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: Wed, 22 Sep 2021 20:03:51 +0200 Message-ID: References: <1f773384-058a-f2e3-69cf-b0e23033ec2d@gmail.com> <52130eefb713942a36aa5717ef4c916173567ce3.camel@telenet.be> Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-riNeFwWjq0LP63sJrYC6" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15358"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.34.2 Cc: guile-user , Matt Wette To: Damien Mattei Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Sep 22 20:51:58 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 1mT7La-0003km-57 for guile-user@m.gmane-mx.org; Wed, 22 Sep 2021 20:51:58 +0200 Original-Received: from localhost ([::1]:46582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT7LX-0003Xk-0x for guile-user@m.gmane-mx.org; Wed, 22 Sep 2021 14:51:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT6bJ-0007jd-9P for guile-user@gnu.org; Wed, 22 Sep 2021 14:04:10 -0400 Original-Received: from albert.telenet-ops.be ([2a02:1800:110:4::f00:1a]:34992) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mT6bD-0002Aj-EO for guile-user@gnu.org; Wed, 22 Sep 2021 14:04:09 -0400 Original-Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by albert.telenet-ops.be with bizsmtp id x63x250050mfAB40663xv8; Wed, 22 Sep 2021 20:03:57 +0200 In-Reply-To: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1632333837; bh=4+DXG0DafdMaJu3gzWjh1JVI305u3eaJ145xB4OBKNI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Re00DIO/5EV+XCsubDvKq7TNkAyjSkBBxhPA18g7A4aokZrOFDtPwfdBOtU/K0PEB O4tr7AV7ahxDrtQ7CCyR2UgVLv+360zqbtThCDSO3TtO/MEsxX62F8C1dWPg+p+sAO v/d4Z2qvFYXxNOrF73moAjzTzOAv8jGmf9EE0Wm46cDzUV88gU4Ty7GAZkyOl/WWkb aafGbC6P6ITUlhBdEowgeIS8ahYoU/DcCkUml7Zbw2aSRTVFi7n0fnA7bSlN0uIJTK r8TdM95U2VHkDYAh0izY2QKitSgR8ep/MZZqiIDi3G6ANagtbgJLqksp9LZIPXwQHs d/b+p9zY5+yGA== Received-SPF: pass client-ip=2a02:1800:110:4::f00:1a; envelope-from=maximedevos@telenet.be; helo=albert.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:17776 Archived-At: --=-riNeFwWjq0LP63sJrYC6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Damien Mattei schreef op wo 22-09-2021 om 09:52 [+0200]: > i do not understand well what you want to mean with those example. > For me define-once does not seems to be a solution, it act as define too= much=20 > ,does not set! variable if already exist and can not use to set it again = because, > as define it is forbidden twice in the same block for the same variable: > [...] I was not suggesting using define-once. Rather, I was demonstrating how to get Python-style scoping of variables lo= cal to a function (procedure) in Scheme without defining new syntax, by using set!= instead of define, and adding a define in the beginning of the procedure for every = variable. Python: def hello(language): if language =3D=3D "english": message =3D "Hello world!" if language =3D=3D "dutch": message =3D "Hallo wereld!" print(message) hello("english") # output: Hello world! hello("dutch") # output: Hallo wereld! Equivalent (non-idomatic but portable) Scheme: (define (hello language) (define message) (cond ((equal? language "english") (set! message "Hello world!")) ((equal? language "dutch") (set! message "Hallo wereld!"))) =20 (display message) (newline)) (hello "english") ; "Hello world!" (hello "dutch") ; "Hallo wereld!" Greetings, Maxime. --=-riNeFwWjq0LP63sJrYC6 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+4iGRcl7gUCYUtwCBccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7sr8AP4hdO2wxcAABgD/ZmnUMN5rtJ1a xCeu1fj7c1SBksYWPgEAqPvRanAkqPTu8hPPQuvdkf1LwkX0jUt5IxZ1UIyzcAg= =4uF7 -----END PGP SIGNATURE----- --=-riNeFwWjq0LP63sJrYC6--