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

Re: Vectors as functions

On Freitag, August 15, 2003, at 08:30  Uhr, Michael Vanier wrote:

>> From: Bruce Lewis <brlewis@alum.mit.edu>
>> Date: 15 Aug 2003 14:10:11 -0400
>> Michael Vanier <mvanier@cs.caltech.edu> writes:
>>> I'm thinking of situations where you might have a list of symbols
>>> representing names (or first-class names) and you might want to set 
>>> their
>>> values to a given value, like mapping set! over the list of names.  
>>> Not
>>> having names as first-class entities makes that unduly hard.
>> If you're sure you want to do it this way, and not use a hash table to
>> deal with names at run time, then you probably want Common Lisp.
> How would you use a hash table to deal with names at run time?

A quoted name, i.e. a symbol, has object identity. You could use a hash 
table that relies on hash values for those object identities. (In 
Common Lisp, this would be a so-called eq hashtable).

> [To Mike Sperber] Does "set" in common lisp destroy lexical scoping?  
> I'm
> not sure exactly what you were getting at, although I dimly understand 
> that
> there could be a problem.

In Common Lisp, set sets the so-called symbol-value of a symbol, i.e. 
(set 'sym val) is equivalent to (setf (symbol-value 'sym) val).  This 
circumvents lexical bindings (intentionally so!) because symbol values 
are always global (modulo dynamic scoping).

This shouldn't be too shocking. If you use hashtables for dealing with 
names you also circumvent lexical bindings.

> I guess the bottom line is: how much freedom to mess around with the 
> local
> environment is consistent with lexical scoping?

I know about global, dynamic and lexical environments. Are there more 

BTW, you could do worse than read "The Art of the Interpreter" by Guy 
Steele and Gerald Sussman to learn more about these issues. See