From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 21 17:27:44 2021 Received: (at 46014) by debbugs.gnu.org; 21 Jan 2021 22:27:44 +0000 Received: from localhost ([127.0.0.1]:59613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2iQa-0003vO-Ee for submit@debbugs.gnu.org; Thu, 21 Jan 2021 17:27:44 -0500 Received: from sender4-of-o51.zoho.com ([136.143.188.51]:21155) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2iQW-0003v0-FL for 46014@debbugs.gnu.org; Thu, 21 Jan 2021 17:27:40 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1611268048; cv=none; d=zohomail.com; s=zohoarc; b=fHKXP1OhkvonRG51e/+9dYI/G+zqqRoa8AWliQb5948vliOh+Y0h2eVLEoEB9KFDx6+E0RmdGkoiL6txGdwLCfX58gXs5azK2sAy8bJ7y+1qhy+P0dFuOo4cQYI9SnVoCGZUjXHXzHehqm08S+nxC5Mlx/+y/0rjT/tN7CN3Iw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611268048; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=2N5QHrEV0EVMPEgosi0ptgucn27TdjMiM4112dNvJdg=; b=a/1V4u1UrHse3Hs5wOm/9rKttNxVrgkeDpbca2rxej3DhrWXiqiWU85qEJ/Fjus6z+XpA6Ih/rJxk3uywEAaogtwtDzIWqSihE7cdHDyL5J4rxMfjsnnJniqDf8anKDYzXlpkFWxAFoMBoeKqiGOVH4KNoZti90+s0KrTvxgT7g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1611268048; s=zoho; d=elephly.net; i=rekado@elephly.net; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=2N5QHrEV0EVMPEgosi0ptgucn27TdjMiM4112dNvJdg=; b=WYTgme2L1VX3A425P8vnA2GtiF/2j6qUcQJ4ZDT1Sz7kV+PDguWh4ah+h/8HY8DE 1EA4KMXGRYi09VpBn+kDBd8wud/f7pbm4M8vww8QzVluwtPJwWWJ8n8B0PKY2nG8ZxQ Kp29GBqZs/P+ZrvmCC0/onyyxrQpO4QcUSQuIx0Y= Received: from localhost (p54ad4e28.dip0.t-ipconnect.de [84.173.78.40]) by mx.zohomail.com with SMTPS id 1611268047063346.3233320606232; Thu, 21 Jan 2021 14:27:27 -0800 (PST) References: <87h7nb3v0g.fsf@dismail.de> <87bldil7fo.fsf@elephly.net> <87eeie2gs1.fsf@dismail.de> User-agent: mu4e 1.4.13; emacs 27.1 From: Ricardo Wurmus To: Joshua Branson Subject: Re: bug#46014: (define (thunk) (lambda (x) x)) should be a compile error? In-reply-to: <87eeie2gs1.fsf@dismail.de> X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC Date: Thu, 21 Jan 2021 23:27:23 +0100 Message-ID: <878s8mkjsk.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External X-Spam-Score: 0.0 (/) 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: -1.0 (-) Hi Joshua, > When I look at > > #+BEGIN_SRC scheme > (define (thunk) > (lambda (x) > x)) > #+END_SRC [=E2=80=A6] > 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 =E2=80=9Cthunk=E2=80=9D a= bove is perfectly fine and also common. The above is equivalent to (define thunk (lambda () (lambda (x) x))) And that=E2=80=99s really okay and can be desired. The problem is not with this definition. If someone calls this wrongly, well, that=E2=80=99s a pro= blem with the caller. And Guile=E2=80=99s compiler does tell you that you are probably wrong in calling =E2=80=9Cthunk=E2=80=9D with an argument. Do I understand you correctly that you would like this warning to be an error instead? > 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. Let me address this separately. In Scheme you *can* define a procedure that takes a different number of arguments. Here=E2=80=99s one example fro= m the manual: (define (make-accum n) (case-lambda (() n) ((m) (set! n (+ n m)) n))) (define a (make-accum 20)) (a) =E2=87=92 20 (a 10) =E2=87=92 30 (a) =E2=87=92 30 =E2=80=9Ccase-lambda=E2=80=9D specifies a procedure that can take arguments= in as many different shapes as there are clauses. Here there are two clauses: one for the case where no arguments are provided and another where one argument (bound to =E2=80=9Cm=E2=80=9D) is provided. Furthermore, you can see here that this is a higher order procedure, as =E2=80=9Cmake-accum=E2=80=9D takes an argument and returns a procedure (the case-lambda). Another example, also from the manual, is this: (lambda* (start #:optional (end (+ 10 start))) (do ((i start (1+ i))) ((> i end)) (display i))) This procedure takes one or two arguments. --=20 Ricardo