Some programming languages have uniform 'value' semantics. Many others
have 'reference' or 'object' semantics. In object semantics, atomic/scalar
objects are immutable, and assigned by value, and composite objects are
mutable, and assigned by reference. Maxima, like Lisp and Java, has
reference semantics.
I agree that it would be good to document this. Not clear that most users
would bother to check the documentation for ':', though, so *where* would
you document this? In a tutorial, perhaps when the idea of assigning to
list/vector elements is introduced? The issue is complicated by Maxima's
idiosyncratic treatment of arrays....
There is no reason, though, to complicate your code with local variables,
assignments, and 'appends'. Much more straightforward simply to
*construct* the
result list you want directly:
increment_each(list) :=
makelist( makelist( if i=j then list[i]+1 else list[i], i, 1,
length(list)), j, 1, length(list))
-s
On Sun, Dec 23, 2012 at 9:28 AM, Jochen Ziegenbalg <
ziegenbalg at ph-karlsruhe.de> wrote:
> Dear Roland,
>
> thank you so much, it works great!
> But: How can the non-specialized user of Maxima know about this?
> If you do the analog thing with "normal" variables like in
> x : 3;
> x2 : x;
> x2 : 5;
> the variable x retains its value (3) - in contrast to the example with
> the lists.
>
> Is this subject matter written up somewhere in some manual or tutorial?
>
> Thank you, again,
> Jochen
>
>
> > Dear Jochen,
> >
> > L2 : L doesn't copy the List,
> >
> > its only a new name for the same! object/list
> >
> > instead try copylist:
> >
> > DistributePlus1(L) :=
> > block (
> > L1 : [], L2 : [] ,
> >
> > for i : 1 thru length(L) do
> > (L2 : copylist (L),
> >
> > L2[i] : L2[i]+1,
> > L1 : append(L1, [L2]) ),
> > L1 );
> >
> >
> > Roland Stewen
> >
> >
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>