unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Taylan Kammer <taylan.kammer@gmail.com>
To: Maxime Devos <maximedevos@telenet.be>,
	Damien Mattei <damien.mattei@gmail.com>,
	Matt Wette <matt.wette@gmail.com>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: Fwd: new function
Date: Wed, 22 Sep 2021 21:12:42 +0200	[thread overview]
Message-ID: <4f267793-3076-72d3-214b-077dbcf3910c@gmail.com> (raw)
In-Reply-To: <52130eefb713942a36aa5717ef4c916173567ce3.camel@telenet.be>

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



      parent reply	other threads:[~2021-09-22 19:12 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
2021-09-22 19:12           ` Taylan Kammer [this message]

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=4f267793-3076-72d3-214b-077dbcf3910c@gmail.com \
    --to=taylan.kammer@gmail.com \
    --cc=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=matt.wette@gmail.com \
    --cc=maximedevos@telenet.be \
    /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).