[Top][All Lists]

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

translators and scoping rules (was: Re: language translator help)

From: John W. Eaton
Subject: translators and scoping rules (was: Re: language translator help)
Date: Sat, 27 Apr 2002 19:54:27 -0500

On 27-Apr-2002, Neil Jerram <address@hidden> wrote:

| What are the Octave scoping rules?  For dynamic scoping (a la Elisp),
| Guile has the address@hidden' macro for setting and restoring such variables'
| values.  In the Elisp case, this allows Elisp variables to be Guile
| variables directly.  (Except that it doesn't cope with buffer-local,
| etc.)

The scoping rules are fairly simple.  Variables are local to functions
unless declared global.  Global variables all share the same common
global namespace.

The eval() function can introduce new local variables.  How would you
do that with Guile?

Something like this

  (define foo
    (lambda ()
      (let ((x 21))
        (eval-string "(define a (* 2 21))")
        (display a)

works to define a new variable "a", but once foo has been evaluated,
the variable "a" is visible outside the scope of the function:

  guile> a
  ERROR: In expression a:
  ERROR: Unbound variable: a
  ABORT: (unbound-variable)

  Type "(backtrace)" to get more information or "(debug)" to enter the debugger.
  guile> (define foo
  ...      (lambda ()
  ...        (let ((x 21))
  ...          (eval-string "(define a (* 2 21))")
  ...          (display a)
  ...          (newline))))
  guile> (foo)
  guile> a

How would you use eval to introduce a new local variable?


reply via email to

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