Subject: multiple assignment stuff in src/mlisp.lisp
From: Stavros Macrakis
Date: Tue, 27 Feb 2007 13:08:22 -0500
On 2/27/07, Robert Dodier <robert.dodier at gmail.com> wrote:
>
> On 26 Feb 2007 23:09:34 +0100, Albert Reiner <areiner at tph.tuwien.ac.at>
> wrote:
>
> > > (%i13) a : [1, 2, 3, 4];
> > > (%o13) [1, 2, 3, 4]
> > > (%i14) (i : 2, [i, a[i]] : [4, 11]);
> > > (%o14) [4, 11]
> > > (%i15) a;
> > > (%o15) [1, 2, 3, 11]
> >
> > This I find a bit surprising; based on the earlier examples I would
> > have expected a => [1, 11, 3, 4], i.e., I thought that the expressions
> > on the left hand side are evaluated "in parallel",
>
> I guess the current behavior results from
>
> (map nil #'mset (cdr tlist)(cdr vlist))
>
> so by the time the 2nd and later assignments are made, they
> see the result of the first assignment ... I don't see a simple way
> to insulate the assignments from each other. A complicated way
> might be substitute gensyms, but that has the potential to leak
> gensyms, aside from probably being too complicated.
> Maybe build a lexical environment and evaluate it? Other ideas?
>
There is no simple way that I can see. We have to build some sort of lvalue
structure so that
(i : 2, [i, a[i]] : [4, 11])
executes as
set i to 2
calculate lvalue(i) => i
calculate lvalue(a[i]) => a[2]
set i to 4
set a[2] to 11
Similarly for
a: [1,2,3]
[ a, rest(a)[2] ] : [a: rest(a), 99]
calculate lvalue(a) => a
calculate lvalue(rest(a)[2]) => [3][1]
set a to [2,3]
set [3][1] to 99
result: a = [2,99]
I'm working on it.
-s