unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: scoping problem
       [not found] <m3hejv9g74.fsf@multivac.cwru.edu>
@ 2002-06-23  9:59 ` Panagiotis Vossos
  0 siblings, 0 replies; only message in thread
From: Panagiotis Vossos @ 2002-06-23  9:59 UTC (permalink / raw)
  Cc: guile-user

[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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-06-23  9:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <m3hejv9g74.fsf@multivac.cwru.edu>
2002-06-23  9:59 ` scoping problem Panagiotis Vossos

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).