From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.user Subject: Re: Fwd: new function Date: Tue, 21 Sep 2021 21:03:27 +0200 Message-ID: <52130eefb713942a36aa5717ef4c916173567ce3.camel@telenet.be> References: <1f773384-058a-f2e3-69cf-b0e23033ec2d@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-tRyikm70fdh7T9UCU2fd" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15580"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.34.2 Cc: guile-user To: Damien Mattei , Matt Wette Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Sep 21 21:04:32 2021 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 1mSl4B-0003nl-2L for guile-user@m.gmane-mx.org; Tue, 21 Sep 2021 21:04:31 +0200 Original-Received: from localhost ([::1]:44630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSl48-00056G-Vn for guile-user@m.gmane-mx.org; Tue, 21 Sep 2021 15:04:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSl3L-00055I-0b for guile-user@gnu.org; Tue, 21 Sep 2021 15:03:43 -0400 Original-Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]:48782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSl3I-0003A8-P3 for guile-user@gnu.org; Tue, 21 Sep 2021 15:03:38 -0400 Original-Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by xavier.telenet-ops.be with bizsmtp id wj3Y2500E0mfAB401j3YPZ; Tue, 21 Sep 2021 21:03:32 +0200 In-Reply-To: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1632251012; bh=6KXBGnzk3wcjNDVbsUpCji6uyzpKT7MxphMQ52uoG9o=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Bl2zHYGM7E2PuPwUEQdReDPEJ5ohdtbYXtc7rPhFplyWuCF+iRBnOVq+qbUyOiQZM kwrga3bCN86Wn1b8Ps1i+9OtcWSapoHy8H5FhKzAntu3ZHAxJ1ql5Pr1837DN04xoP Me33s3BZnUjL5Sd5u+CZ/yXAOIGSfRspwJmbyYI1JvRtGCyh9zuVkles3Xm+JdO7QQ PmkKm2/oq6W/lCzxjatz9Rw3JCbR0Xhiq9UtOC3uC+KIn+zD4foBIrhZb6MkTjJoIl ukCtQcgwj/Fp1nMBGMNmfv1fdhNU30JV4n1g44u6ci1iU4CBNPN//kCbQX/elkIn7O QhanM7p0UmzdA== Received-SPF: pass client-ip=2a02:1800:120:4::f00:14; envelope-from=maximedevos@telenet.be; helo=xavier.telenet-ops.be 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_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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:17774 Archived-At: --=-tRyikm70fdh7T9UCU2fd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Damien Mattei schreef op di 21-09-2021 om 15:04 [+0200]: > i have tested define-once > http://www.gnu.org/software/guile/docs/master/guile.html/Top-Level.html > (the defvar of Lisp)and idea are: > -unfortunately it is considered by scheme as a define,so there is some > context where it is not allowed in my code > -seems to work fine at toplevel (as mentioned in doc) but strange behavio= r > in a function, i did not understand really what happened but i got some > #unspecified value. >=20 > here are my test code: > cheme@(guile-user)> (define (foo2) > (define-once x 1) > (if #t > (let () > (define-once x 2) > ;;(set! x 2) > (display "x=3D") > (display x) > (newline)) > 'never) > (display x) > (newline)) Possibly you want (added a set? argument for demonstration): (define (foo2 set?) (define x) ; define an (undefined or unbound, not sure about terminology)= variable (if set? (let () (set! x 2) ; change the value of x (display "x=3D") (display x) (newline)) 'never) (display x) (newline)) That should be portable and avoids global state. scheme@(guile-user)> x ;;; :20:0: warning: possibly unbound variable `x' ice-9/boot-9.scm:1685:16: In procedure raise-exception: Unbound variable: x scheme@(guile-user) [1]> ,q scheme@(guile-user) [1]> (foo2 #f) # ; I expected an error as would result from ... ;; ... this ... scheme@(guile-user)> (variable-ref (make-undefined-variable)) ice-9/boot-9.scm:1685:16: In procedure raise-exception: In procedure variable-ref: Unbound variable: #> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [2]>=20 ;; instead of # but whatever ... scheme@(guile-user) [1]> (foo2 #t) x=3D2 2 scheme@(guile-user) [1]> (foo2 #t) x=3D2 2 scheme@(guile-user) [1]> (define x 3) scheme@(guile-user) [1]> (foo2 #t) x=3D2 ; foo2 doesn't use the global variable 'x' 2 scheme@(guile-user) [1]> x $1 =3D 3 Does this seem reasonable to you? --=-tRyikm70fdh7T9UCU2fd Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYUosfxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7irUAP4lllfdC3QwJMo08v/Viyns7sA2 RsVONUiZ82C8G3DlfwEAzwVDCtGYMUWvpLOKhY8R2n6/l31dwg2NWr+QnTtD3Qg= =jskK -----END PGP SIGNATURE----- --=-tRyikm70fdh7T9UCU2fd--