[Top][All Lists]

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

Re: scoping problem

From: Panagiotis Vossos
Subject: Re: scoping problem
Date: Sun, 23 Jun 2002 12:59:56 +0300
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

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

address@hidden (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))

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

Study the R5RS section mentioned above for more details.


reply via email to

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