bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?

<[email protected]>
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
On Fri, Jan 22, 2021 at 09:47:24AM -0500, jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language wrote:
> Ricardo Wurmus <[email protected]> writes:
> 
> > Hi Joshua,
> >
> >> When I look at
> >>
> >> #+BEGIN_SRC scheme
> >> (define (thunk)
> >>    (lambda (x)
> >>      x))
> >> #+END_SRC
> >
> > […]
> >
> >> My thought is, this is clearly a mistake.  This person needs to change
> >> the above code.
> >
> > How is this clearly a mistake?  The definition of “thunk” above is
> > perfectly fine and also common.
> 
> Thanks again for responding.  I'm still learning scheme, and it's cool
> that this email chain has helped clarify some things.  :)
> 
> Ahh.  I see now that the proper way to call thunk is to do this:
> ((thunk) "the")
> $1 = "the"
> 
> I had assumed that every time one called thunk, it would result in a
> runtime error.  I did not realize that there was a way to properly call
> thunk. Wow. Scheme is truly impressive.
> 
> Interestingly, I had wrongly assumed that
> 
> #+BEGIN_SRC scheme
> (thunk "test\n")  ;; I assumed program execution would stop here
> (display "Hello World\n")
> #+END_SRC
> 
> program execution would stop at (thunk "test\n").  But it actually
> caries on with execution of the program:

What happens is an "exception". It can be handled (then it's up
to the exception handler to end the program or do something else).

> #+BEGIN_SRC scheme
> <stdin>:5:0: warning: possibly wrong number of arguments to `thunk'
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> Wrong number of arguments to #<procedure thunk ()>
> 
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> Hello World
> #+END_SRC

This is the REPL's exception handler talking to you. It's there to help
you debug the problem.

Were it a standalone program, it would have terminated right away.

(note that I'm not the most appropriate person to explain such things,
I can barely wrap my head around them :-)

Cheers

[1] https://www.gnu.org/software/guile/docs/master/guile.html/Exceptions.html

 - tomás
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAmAK/V4ACgkQBcgs9XrR2kbIxACePKWcPtVfmvitEMIdQnhQOmWI
RoQAniSIEmjI/j6/5h+0xP1fHCe+56SW
=JAdy
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.