[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: set in Scheme?
David Chin asks, ``Does anyone know how to do the equivalent of a Common Lisp
"set" in Scheme? In particular, I would like to be able to pass different
symbols as arguments to a function and then set! or define them inside the
function. Is this style of programming (global side-effects for function calls)
contrary to the Scheme philosophy?''
I won't stick my neck out by claiming to speak for ``the Scheme philosophy'',
but I will point out some semantic difficulties with this idea. The problem is
that in most Schemes there is no single ``global'' value for a symbol. Rather,
there are a set of environments in which each symbol is bound to a corresponding
set of values. Thus, it is difficult to know what such a ``set''-like operator
would do. Most Schemes with multiple first-class environments, however, do
provide a way to define or set! a symbol in a *particular* environment. For
example, the T dialect has the procedure *LSET for this purpose.
For your application, perhaps you can change things so that, rather than passing
symbols around, you pass procedures of one argument that set a particular
variable to the value of that argument. Thus, rather than passing the symbol
FOO around, you might pass this procedure:
(lambda (v) (set! foo v))
The receiving procedure would then simply apply its argument to the desired
value, as opposed to calling the non-existent ``set'' operation.
Hope this helps,