[Top][All Lists]

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

Re: Emacs Lisp and Guile

From: Marius Vollmer
Subject: Re: Emacs Lisp and Guile
Date: 30 Jul 2002 14:20:30 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

Richard Stallman <address@hidden> writes:

>     When that is the case, we need to treat Elisp variable references
>     differently from Scheme variable references.  In Scheme, we only look
>     up the storage location of a variable once and then each reference is
>     only a simple memory access.
> I guess so.  But one question is, what would a reference to a "Lisp"
> variable look like in Scheme?  Would you have to call a special
> function to get or set the value?

Yes, probably, as far as I can see.  I don't think this is a problem,
tho.  A call to that special function can be very fast when needed.
For example, when we should get serious about compilation to machine
code, we will want to inline certain operations, like arithmetic on
fixnums, and the call to the special Elisp-variable-accessor-function
can be one of these operations.  For a bytecode interpreter (or
similar), we will likewise want to have special opcodes for these kind
of things.

> Scheme variables are normally lexical.  What do people normally do in
> Scheme when you want a dynamically scoped value?

In plain Scheme, you use 'dynamic-wind' to establish a dynamic
context.  Entering and leaving that context will run specified
procedures that can swap values in and out of variables that should
have dynamically scoped values.

We also have '@bind' which does just this but more efficiently.

In Guile, we also have 'fluids'.  A fluid is a normal object like a
cons pair that holds one object per thread.  That is, fluids are our
mechanism for thread local variables.  There is also support for
efficiently creating dynamic contexts that will swap the value of a
fluid with a backing store when entered/left.

    > (define var (make-fluid))
    > (define (peek-var)
        (peek (fluid-ref var)))
    > (fluid-set! var 12)
    > var
    => #<fluid 5>
    > (peek-var)
    ;;; 12
    > (with-fluids ((var 23))
    ;;; 23
    > (peek-var)
    ;;; 12

The "5" in #<fluid 5> is just an index, not the value of the fluid.

reply via email to

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