From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.bugs Subject: bug#46014: (define (thunk) (lambda (x) x)) should be a compile error? Date: Thu, 21 Jan 2021 19:16:27 +0100 Message-ID: References: <87h7nb3v0g.fsf@dismail.de> <87bldil7fo.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000094d5f705b96d1276" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16896"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46014@debbugs.gnu.org, Joshua Branson To: Ricardo Wurmus Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Thu Jan 21 19:19:28 2021 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2eYK-0004Hu-4f for guile-bugs@m.gmane-mx.org; Thu, 21 Jan 2021 19:19:28 +0100 Original-Received: from localhost ([::1]:54908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2eYJ-0007Ol-6M for guile-bugs@m.gmane-mx.org; Thu, 21 Jan 2021 13:19:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2eVy-0005bJ-Ea for bug-guile@gnu.org; Thu, 21 Jan 2021 13:17:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2eVy-0000hI-5a for bug-guile@gnu.org; Thu, 21 Jan 2021 13:17:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l2eVy-000648-02 for bug-guile@gnu.org; Thu, 21 Jan 2021 13:17:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Israelsson Tampe Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 21 Jan 2021 18:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46014 X-GNU-PR-Package: guile Original-Received: via spool by 46014-submit@debbugs.gnu.org id=B46014.161125300523292 (code B ref 46014); Thu, 21 Jan 2021 18:17:01 +0000 Original-Received: (at 46014) by debbugs.gnu.org; 21 Jan 2021 18:16:45 +0000 Original-Received: from localhost ([127.0.0.1]:59359 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2eVh-00063b-7I for submit@debbugs.gnu.org; Thu, 21 Jan 2021 13:16:45 -0500 Original-Received: from mail-wm1-f45.google.com ([209.85.128.45]:40073) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2eVf-00063O-Rk for 46014@debbugs.gnu.org; Thu, 21 Jan 2021 13:16:44 -0500 Original-Received: by mail-wm1-f45.google.com with SMTP id c127so2329398wmf.5 for <46014@debbugs.gnu.org>; Thu, 21 Jan 2021 10:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7IbWFnjVk0z0tRg8O6YC+SRruCltJZ3BZvMqXBmJ75s=; b=N/mDWCf7XegiuJnk2h76dQO8SkbZQoI+l5cTHrlkrHtIPPmYQCFZfZ06Hmpxoc2tcE Hmufbf7mZIzw5fUJoJrmt1B3DWYhrv+tYp2qhktKsQsuUioZvbgXP0ZzyO3eivT9UT8d AIT4IKxB/modxvEZwqpuTaiumOworqsE41kAoSGx7yp1p9l3RsAyvtM6tR7tKcdGqGny DL4JTBmTdb5wkoIbHzF5V3IMvSTcGlrN1BVpg0apF8SGftc09WKsX+PsCTNKmQMWNvvx dR4RRzB62b6T/LJKg0ZKIugtBR7I7vXWZVJ393a7+hJVqDc3frm2sqgavhQe53j84tSp cUmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7IbWFnjVk0z0tRg8O6YC+SRruCltJZ3BZvMqXBmJ75s=; b=NEdp+vZ2FEdnd1ACTcMsYWT4T4uUCvqYOvUWowrG199jFT3MJoCMaqNCmC8RWnGlSr iCrNn9/Xhx9NUG2l4oDQ2I5M/1dOpwWa810lYKnv1tKYrldze/x4JYpOSnhQD7arWcP7 g446SANodOkNg2jq4FGKne6CgfZCK4dywF+9vFP8N4xaTwYDXTNIWgN37M6594OqzVZd 5KjZyCSqnbxDxzuJRuuzJLroarPj/HnORj3hyiFksJI9+cxCNhfET5pg6MZ6YxoiS9uu 9xOK63sICVfrss8VDJDUAmLQcfAIejkwxY5HYI6q+go2H2S0wpZlCR+Y8hwUsV1DjG7Q RiNQ== X-Gm-Message-State: AOAM530q/rX9zjozdbVJVLghEPYHiIHA1OBDme6uF2zw21BkAjZB9Udj 0TKcy7qNzx/jwtx7IWS5ud6sl3gNSbBw2VtlKPc= X-Google-Smtp-Source: ABdhPJz0Cmd3jQxc1af6Qx1kjho8eGbY0dERWLbgtxAxmp21AMTjAK9/0c+6jrbFsIiy6KluMWsFDcq8dwHGgvCQJiM= X-Received: by 2002:a1c:a549:: with SMTP id o70mr537350wme.71.1611252997869; Thu, 21 Jan 2021 10:16:37 -0800 (PST) In-Reply-To: <87bldil7fo.fsf@elephly.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:9960 Archived-At: --00000000000094d5f705b96d1276 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I will note that paying attention to those warnings is super heolpful in programming in guile. I miss these warnings alot when doing python programming.In a sense with these warnings you get close to static typechecking programming languages and scheme/guile is really a nice mix of dynamic and static typin= g On Thu, Jan 21, 2021 at 2:58 PM Ricardo Wurmus wrote: > > 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 > `thunk' > > 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: > > --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=E2=80=99t that exactly what you=E2=80=99re asking for? > > -- > Ricardo > > > > --00000000000094d5f705b96d1276 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I will note that paying attention=C2=A0to those warnings i= s super heolpful=C2=A0in programming in guile. I miss these warnings
al= ot when doing python programming.In a sense with these warnings you get clo= se to static typechecking=C2=A0programming
languages and scheme/g= uile is really a nice mix of dynamic and static typing

On Thu, Jan 21,= 2021 at 2:58 PM Ricardo Wurmus <r= ekado@elephly.net> wrote:

Hi,

> Consider this bit of simple code:
>
> #+BEGIN_SRC scheme
>
> (define (thunk)
>=C2=A0 =C2=A0 (lambda (x)
>=C2=A0 =C2=A0 =C2=A0 x))
>
> (thunk) ;; works ok, I guess.
> (thunk "hello world!\n")=C2=A0 ;; 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.=C2=A0 Type `,bt' for a backtrace or `,q'= ; to continue.
> #+END_SRC
>
> Guile will compile this program seemingly with no error.=C2=A0 Guile w= ill
> correctly report at runtime that procedure '(thunk "hello wor= ld!\n")'
> takes no arguments, but it's lambda accepts 1 argument.=C2=A0 Woul= d it be
> possible to report this error at compile time?=C2=A0 Would that be
> advantageous?

This is not a bug.=C2=A0 What you call =E2=80=9Cthunk=E2=80=9D here is a pr= ocedure that
returns a procedure.=C2=A0 That=E2=80=99s very common and is often done to = delay
evaluation.

It is in fact an error to call the procedure =E2=80=9Cthunk=E2=80=9D with a= n argument.
It doesn=E2=80=99t matter that it happens to return a procedure that *can* = take
an argument.=C2=A0 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.=C2=A0 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=E2=80=99t that exactly what you=E2=80=99re asking for?

--
Ricardo



--00000000000094d5f705b96d1276--