From: Maxime Devos <maximedevos@telenet.be>
To: Damien Mattei <damien.mattei@gmail.com>
Cc: guile-user <guile-user@gnu.org>, Matt Wette <matt.wette@gmail.com>
Subject: Re: Fwd: new function
Date: Wed, 22 Sep 2021 20:03:51 +0200 [thread overview]
Message-ID: <c6c325e0e2d3c91dd464abbee8050c845fc04fbf.camel@telenet.be> (raw)
In-Reply-To: <CADEOadcn0=_JMS6NSCWqQjxkmmDXubSX-2msa_bOsrOuV-Qtfw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]
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
> ,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 local 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 == "english":
message = "Hello world!"
if language == "dutch":
message = "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!")))
(display message)
(newline))
(hello "english") ; "Hello world!"
(hello "dutch") ; "Hallo wereld!"
Greetings,
Maxime.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
next prev parent reply other threads:[~2021-09-22 18:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CADEOadfF+rR=fW0fS-PkQkDN8EHFB1sJnkeePMJyc23m9shLgA@mail.gmail.com>
2021-09-19 9:18 ` Fwd: new function Damien Mattei
2021-09-19 10:38 ` Maxime Devos
2021-09-19 14:45 ` Matt Wette
2021-09-19 14:56 ` Maxime Devos
2021-09-21 13:04 ` Damien Mattei
2021-09-21 19:03 ` Maxime Devos
2021-09-22 7:52 ` Damien Mattei
2021-09-22 18:03 ` Maxime Devos [this message]
2021-09-22 19:12 ` Taylan Kammer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c6c325e0e2d3c91dd464abbee8050c845fc04fbf.camel@telenet.be \
--to=maximedevos@telenet.be \
--cc=damien.mattei@gmail.com \
--cc=guile-user@gnu.org \
--cc=matt.wette@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).