unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panagiotis Vossos <jacbre@internet.gr>
Cc: guile-user@gnu.org
Subject: Re: scoping problem
Date: Sun, 23 Jun 2002 12:59:56 +0300	[thread overview]
Message-ID: <m24rful3hf.fsf@ground.control.net> (raw)
In-Reply-To: <m3hejv9g74.fsf@multivac.cwru.edu>

[Cc'd to guile-user, as it's not a bug]

prj@po.cwru.edu (Paul Jarc) writes:

> I'm new to Scheme, so maybe this isn't a bug, but this script:
> #!/usr/local/bin/guile -s
> !#
> (let ()
>   (define x #t)
>   (define y x)
>   #t)
> 
> gives me this error:
> ERROR: Unbound variable: x

This happens because internal defines are equivalent to 'letrec'
forms.  Using letrec, your code is written as:

(let ()
  (letrec ((x #t)
           (y x))
    #t))

According to the 'Binding Constructs' section in R5RS, in expressions
of the form (letrec ((var1 init1) (var2 init2)) <body>) it must be
possible to evaluate init1 & init2 without referring to the values of
either var1 or var2.  When inits are lambda expressions, this rule is
obeyed automatically.

> But if possible, I'd like to do it all in the (define) form, without
> using (set!).

(let* ((x #t) (y x))
  #t)

Study the R5RS section mentioned above for more details.

regards,
panagiotis


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


           reply	other threads:[~2002-06-23  9:59 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <m3hejv9g74.fsf@multivac.cwru.edu>]

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=m24rful3hf.fsf@ground.control.net \
    --to=jacbre@internet.gr \
    --cc=guile-user@gnu.org \
    /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).