From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 21 15:10:04 2021 Received: (at 46014) by debbugs.gnu.org; 21 Jan 2021 20:10:04 +0000 Received: from localhost ([127.0.0.1]:59443 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2gHM-0000N6-DF for submit@debbugs.gnu.org; Thu, 21 Jan 2021 15:10:04 -0500 Received: from mx1.dismail.de ([78.46.223.134]:46376) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2gHJ-0000MX-NL for 46014@debbugs.gnu.org; Thu, 21 Jan 2021 15:10:03 -0500 Received: from mx1.dismail.de (localhost [127.0.0.1]) by mx1.dismail.de (OpenSMTPD) with ESMTP id b0779ac4; Thu, 21 Jan 2021 21:09:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=dismail.de; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=20190914; bh=ZHN+KBou uuUmw9QgfCgbRBL5sUtPJhOomjBJqYaAsZE=; b=WIM9cWsknARajBJBlN4xHrRl dymZUyyfMfTxQvL+eOiKWXkqQEs+25MWo+/wt79ceE2GK6rywemDPhM6YhYPD5jv G/TRfeSLNLHzokCAqV0x+gK0V9SNMeq1u3/FtCk4xNRykN0MqnUoRRthol/eaU6q ApDAAANRBgqIWBrZdFDR6RUtaYAfN4agIR0aW57lwHumThslhLgH+C7Xp5APGJxC wBJmkWEacCopeZn3zC7yLXp+cRHzaeriss2nTHEoz0qUvO7lfAUIjg+Kc6CuI21k oJH6VUwbueb8VNlYtWoAwytjtpJpIE69UppLApvBMrcDZfDld20Rxj3Re2J96A== Received: from smtp2.dismail.de ( [10.240.26.12]) by mx1.dismail.de (OpenSMTPD) with ESMTP id 6cba0f76; Thu, 21 Jan 2021 21:09:54 +0100 (CET) Received: from smtp2.dismail.de (localhost [127.0.0.1]) by smtp2.dismail.de (OpenSMTPD) with ESMTP id 87fb92db; Thu, 21 Jan 2021 21:09:53 +0100 (CET) Received: by dismail.de (OpenSMTPD) with ESMTPSA id d812253a (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 21 Jan 2021 21:09:52 +0100 (CET) From: Joshua Branson To: Ricardo Wurmus Subject: Re: bug#46014: (define (thunk) (lambda (x) x)) should be a compile error? References: <87h7nb3v0g.fsf@dismail.de> <87bldil7fo.fsf@elephly.net> Date: Thu, 21 Jan 2021 15:09:50 -0500 In-Reply-To: <87bldil7fo.fsf@elephly.net> (Ricardo Wurmus's message of "Thu, 21 Jan 2021 14:56:43 +0100") Message-ID: <87eeie2gs1.fsf@dismail.de> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 46014 Cc: bug-guile@gnu.org, 46014@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Ricardo Wurmus writes: > 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 >> >> ;;; :1074:0: warning: possibly wrong number of arguments to `thun= k' >> ice-9/boot-9.scm:1669:16: In procedure raise-exception: >> Wrong number of arguments to # >> >> 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 =E2=80=9Cthunk=E2=80=9D here is a proce= dure that > returns a procedure. That=E2=80=99s very common and is often done to del= ay > evaluation. > > It is in fact an error to call the procedure =E2=80=9Cthunk=E2=80=9D with= an argument. > It doesn=E2=80=99t 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=E2=80=99t 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: > > 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/g= wl/foo.scm.go' > > Isn=E2=80=99t that exactly what you=E2=80=99re asking for? Gotcha. Thanks for explaining! I suppose what I meant to say is, should guile refuse to compile the above? In other languages, like C I suppose, writing a function simultaneous with one and two arguments would refuse to compile. The compiler would make you fix the code. Should guile do this as well? When I look at #+BEGIN_SRC scheme (define (thunk) (lambda (x) x)) #+END_SRC or #+BEGIN_SRC scheme (use-modules (srfi srfi-9)) (define-record-type (make-lunch food duration location) lunch? (food lunch-food) (duration lunch-duration) (location lunch-location)) (define dine-out (make-lunch "pizza" "30 min" "downtown")) ;; maybe this should refuse to compile? (define (list-lunch) (match-lambda (($ food duration location ) (list food duration location)))) #+END_SRC My thought is, this is clearly a mistake. This person needs to change the above code. Thanks, Joshua P.S. I'm not a scheme expert. I'm only reporting this, because I recently read a blog post about free software users rarely report perceived issues. I'm just trying to be helpful. :) Thanks for the speedy response time. -- Joshua Branson (joshuaBPMan in #guix) Sent from Emacs and Gnus https://gnucode.me https://video.hardlimit.com/accounts/joshua_branson/video-channels https://propernaming.org "You can have whatever you want, as long as you help enough other people get what they want." - Zig Ziglar