From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: expression and definition context in Scheme Date: Tue, 30 Aug 2022 12:47:06 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22169"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.7.0-alpha0-841-g7899e99a45-fm-20220811.002-g7899e99a To: "Damien Mattei" , guile-user , guile-devel Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Aug 30 12:48:25 2022 Return-path: Envelope-to: guile-user@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 1oSyn9-0005YB-Sr for guile-user@m.gmane-mx.org; Tue, 30 Aug 2022 12:48:25 +0200 Original-Received: from localhost ([::1]:33422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSyn8-0005z8-TZ for guile-user@m.gmane-mx.org; Tue, 30 Aug 2022 06:48:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSymM-0005qW-Uf; Tue, 30 Aug 2022 06:47:37 -0400 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:38817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSymK-00088K-NW; Tue, 30 Aug 2022 06:47:34 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 5736B32009A1; Tue, 30 Aug 2022 06:47:29 -0400 (EDT) Original-Received: from imap51 ([10.202.2.101]) by compute4.internal (MEProxy); Tue, 30 Aug 2022 06:47:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veryfast.biz; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1661856448; x= 1661942848; bh=9jTfM4MBftIBVnuaHPWQ8c+cAYwhmAT+Rhs8MaQCJEU=; b=k NLtvA3VBjmN23Ih8JS0t76eaaQGfdtzquuscsNbIrJfKnCjiJMDEynOO9DSEC6q2 zUFc8TVYOPVnC5tKCV/fF1N4CPJh0U6aOToMPGqfGNODv01oz0dyFKHhTQvoMWqy OpVd3mtLru/beLp7em3fnTHJRvyUXKMS6dvOFrWfxHQijEGUQ+PX8KhE3hqbeqOa k9uMsl+3VsqAy8YkWlXo2meQDo4hcaJVYMx5PwIBq52KT6fyEaQlLOrWT7HYrYyd SOu2bmeJTmw0+iom/nek18tIlPM43zZcPytuNLrkPOthUJG36jWhfdNaDI2rIa8S NM+CSYk8yO6o/vXpglroA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1661856448; x=1661942848; bh=9 jTfM4MBftIBVnuaHPWQ8c+cAYwhmAT+Rhs8MaQCJEU=; b=vZaZR+AwP44FsTUSg qU9cXrCaRXw7gVhQ3uQnZ2h9Z1seL4ThEhcE9QZ82MkD2JApsY4YIbaC+qjmc8HC gxd3WmmbmxrE8m1pNF6wQkghqLJcwFx0aIWqb5TwqLW1GycrydQwfSfz9NNFR23x t4CTIOTVK022wVtCQbKlc/5BcNxQd250OJ758WYEsYIqt8EwuUXYRewf6LlQJGl2 M7AyrcxmdCeC2ICTG9gxbkfZD4dTHoXV1lmAsAJNfHV/mmV6gXlq0e+OezfRkjjd M2Eemb7rVwukYesmtADGZF+7XGNr3UkCtN/loQU5zS4ZhQM2678YgWRUdJdBpQWN 7Kjkw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekfedgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpefnihhn uhhspgeujhpnrhhnshhtrghmuceolhhinhhushdrsghjohhrnhhsthgrmhesvhgvrhihfh grshhtrdgsihiiqeenucggtffrrghtthgvrhhnpeetvdeuteehueektefhuddvjeelteff uedvvdeuudeiuedvtedtueehhedvjeeiffenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehlihhnuhhsrdgsjhhorhhnshhtrghmsehvvghrhihf rghsthdrsghiii X-ME-Proxy: Feedback-ID: i51694465:Fastmail Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id A4D42B60083; Tue, 30 Aug 2022 06:47:28 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: pass client-ip=64.147.123.25; envelope-from=linus.bjornstam@veryfast.biz; helo=wout2-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18552 gmane.lisp.guile.devel:21337 Archived-At: I am working on a patch to guile to add definitions to just about every = body except for (begin ...) outside definition context. The patch is trivial, but I have to document it and a patch to r6rs that= makes the r6rs cons work according to spec. I had a kid recently so it might take some time before I have any comput= er time, so if anyone has some time this is a really simple thing. You c= an find the first patch somewhere in this mailing list, it only changes = the (begin ...)s in the derived forms in (ice-9 boot-9) to (let () ...).= Then i was going to copy the cond and case from the r6rs appendix and a= dd some error reporting. The most difficult part is documenting it :) Andy have the idea hos blessing, and will mean guile gets define in expr= ession context in when, unless, cond, case, while, and do as well as in = derived forms. --=20 Linus Bj=C3=B6rnstam On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote: > Hello, > > i'm facing sometimes recursively the problem to have definitions in=20 > expression context, which i manage every time by adding an upper empty=20 > (let () my definitions goes here ) > the last case i was facing this probleme is defining a 'for macro: > > ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (displa= y=20 > i) (newline)) > ;; 0 > ;; 1 > ;; 2 > ;; 3 > ;; 4 > > > (define-syntax for > =20 > (syntax-rules () > =20 > ((_ (init test incrmt) b1 ...) > > (let () > init > (let loop () > (when test > b1 ... > incrmt > (loop))))))) > > this one fails in my Scheme+ code below: > (define (compute-carries n) > > (for ( {k <+ 0} {k <=3D n} {k <- {k + 1}} ) > > { Ckp1 <+ (compute-Ck-plus1 k) } > (display-nl Ckp1))) > > because { Ckp1 <+ (compute-Ck-plus1 k) } expands in : > (define Ckp1 (compute-Ck-plus1 k)) > and i get a compilation error: > ;;; Syntax error: > ;;; logic-syracuse+.scm:15:7: definition in expression context, where=20 > definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k)) > > so i replace my 'for macro definition with: > > (define-syntax for > =20 > (syntax-rules () > =20 > ((_ (init test incrmt) b1 ...) > > (let () > init > (let loop () > (when test > (let () > b1 ... > incrmt > (loop)))))))) > > and it works, but you will notice an abusive use of empty (let () ...)=20 > in the code to avoid the restrictions of definitions not allowed in=20 > expression context.=20 > > My ideas is as it is so easy to cheat the compiler from seeing the=20 > expressio context why does the compiler restrict this? expression and=20 > defintion context, i'm not sure they are in scheme standarts, are they=20 > really usefull? > why not remove this from Scheme at all? > > Regards, > > Damien