guile-user
[Top][All Lists]
Advanced

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

Re: Fwd: new function


From: Taylan Kammer
Subject: Re: Fwd: new function
Date: Wed, 22 Sep 2021 21:12:42 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 21.09.2021 21:03, Maxime Devos wrote:
> 
> (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=")
>         (display x)
>         (newline))
>       'never)
>   (display x)
>   (newline))
> 

I didn't know (define x) without a value was possible in Guile.  I guess
it's just a shorthand for (define x *unspecified*), judging by your result.

If I'm not mistaken, the only way in Scheme to get a "defined but not yet
bound" kind of situation is to use 'letrec'.  If you use the 'letrec*'
variant, it guarantees a straight order of evaluation, so the following is
supposed to definitely NOT work, due to y and z being defined-not-bound:

  (letrec* ((x (+ y z))
            (y (random 10))
            (z (random 10)))
    (display x)
    (newline))

However, in Guile, it seems to bind all the variables to #<unspecified>
anyway, resulting in a "wrong type argument" error (since we end up
passing #<unspecified> to '+') instead of saying that y and z are not
yet bound.

Long story short, there doesn't seem to be *any* way in Guile to have a
lexical variable that's defined but not bound.

-- 
Taylan



reply via email to

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