[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: new function

From: Maxime Devos
Subject: Re: Fwd: new function
Date: Wed, 22 Sep 2021 20:03:51 +0200
User-agent: Evolution 3.34.2

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 
a function (procedure) in Scheme without defining new syntax, by using set! 
of define, and adding a define in the beginning of the procedure for every 


def hello(language):
  if language == "english":
     message = "Hello world!"
  if language == "dutch":
     message = "Hallo wereld!"

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)

(hello "english") ; "Hello world!"
(hello "dutch") ; "Hallo wereld!"


Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

[Prev in Thread] Current Thread [Next in Thread]