bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Ricardo Wurmus
Subject: bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?
Date: Thu, 21 Jan 2021 14:56:43 +0100
User-agent: mu4e 1.4.13; emacs 27.1

Hi,

> Consider this bit of simple code:
>
> #+BEGIN_SRC scheme
>
> (define (thunk)
>    (lambda (x)
>      x))
>
> (thunk) ;; works ok, I guess.
> (thunk "hello world!\n")  ;; runtime error
>
> ;;; <stdin>:1074: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.
> #+END_SRC
>
> Guile will compile this program seemingly with no error.  Guile will
> correctly report at runtime that procedure '(thunk "hello world!\n")'
> takes no arguments, but it's lambda accepts 1 argument.  Would it be
> possible to report this error at compile time?  Would that be
> advantageous?

This is not a bug.  What you call “thunk” here is a procedure that
returns a procedure.  That’s very common and is often done to delay
evaluation.

It is in fact an error to call the procedure “thunk” with an argument.
It doesn’t matter that it happens to return a procedure that *can* take
an argument.  The procedure it returns is just like any other value,
though, and isn’t inspected any further.

That said, it is not true that Guile will compile this without a
complaint.  I dumped your code snippet in a file foo.scm and
compiled it:

--8<---------------cut here---------------start------------->8---
guild compile foo.scm
foo.scm:6:0: warning: wrong number of arguments to `thunk'
wrote 
`/home/rekado/.cache/guile/ccache/3.0-LE-8-4.4/home/rekado/dev/gx/gwl/foo.scm.go'
--8<---------------cut here---------------end--------------->8---

Isn’t that exactly what you’re asking for?

-- 
Ricardo





reply via email to

[Prev in Thread] Current Thread [Next in Thread]