unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: Joshua Branson <jbranso@dismail.de>
Cc: 46014@debbugs.gnu.org
Subject: bug#46014: (define (thunk) (lambda (x) x)) should be a compile error?
Date: Thu, 21 Jan 2021 14:56:43 +0100	[thread overview]
Message-ID: <87bldil7fo.fsf@elephly.net> (raw)
In-Reply-To: <87h7nb3v0g.fsf@dismail.de>


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	other threads:[~2021-01-21 13:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21  2:04 bug#46014: (define (thunk) (lambda (x) x)) should be a compile error? jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2021-01-21 13:56 ` Ricardo Wurmus [this message]
2021-01-21 18:16   ` Stefan Israelsson Tampe
2021-01-21 20:11     ` jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2021-01-21 20:09   ` jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2021-01-21 22:27     ` Ricardo Wurmus
2021-01-22 14:47       ` jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2021-01-22 16:29         ` tomas
2021-01-23 15:02         ` Ricardo Wurmus
2021-01-23 15:17           ` jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2021-01-23 17:23             ` Ricardo Wurmus
2021-01-23 15:07 ` bug#46014: closing the bug report...hopefully jbranso--- via Bug reports for GUILE, GNU's Ubiquitous Extension Language

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bldil7fo.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=46014@debbugs.gnu.org \
    --cc=jbranso@dismail.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).