Thanks for the example!
At a certain point, we (our group) have to think
about a sensible abstract data type for lists and
sets in Maxima (yet the operations provided look a
bit random), and then we could use this.
Yet I avoided to go to the Lisp-level.
(The point is that actually for us Maxima is only
a sort of a specification language, where emphasise
is on readability and correctness. But on the other hand,
once you have your functions, then you want to run
them on some not completely trivial examples.
Now typically for our examples, a very simple
program written in C++ needs seconds, while the
"same" Maxima program (basically the same effort
to write (and debug(!)) it) needs days.
This then is somewhat frustrating.
But on the other hand it's healthy, since it reminds
us that for us the Maxima-level is really there
for specification purposes.)
Oliver
>
> If you really want to build modifying operators on Maxima lists, it
> suffices to have one new primitive:
>
> (defun $set_rest (l new)
> (cond ((or (atom l)
> (not (eq (caar l) 'mlist))
> (not (cdr l)))
> (merror "Can only replace rest of non-null lists: ~:M" l))
> ((or (atom new) (not (eq (caar new) 'mlist)))
> (merror "Can only replace rest with a list: ~:M" new))
> (t (rplacd (cdr l) (cdr new))
> l)))
>
> Have fun.
>
> -s
>
> (*) This is not quite true. It is possible to modify the value of a
> particular position in a list, treating it as an array, e.g.
> ll:[a,b,c]$ ll[2]:9$ ll => [a,9,c].