oldk1331 wrote:
> 
> Even though this is not a bug, it seems that it is impossible to write
> a function that destructively remove its argument's first element,
> the corner case is that a function can't destructively set its argument
> to empty list?

Yes, this is fundamental limitation of using lists.  Essentially
at low level lists are pointers and function gets a copy of
pointer.  Anything that function does can not affect where
original pointer points to.  One could do some nasty tricks,
like copy valiue from second element to first and then
remove second list node.  But ultimentey, if original pointed
to nonempty list then after returm it will still point to
nonempty list.  If original was empty list, then after
return it still will be empty list.

Now, the usel protocol is to use return value: this works
and has negligible extra cost (it may even be cheaper than
"in place" modification, because return value is in a register
while modifed value have to be fetched from cache).  If
for some reason it is more convenient to use "in place"
modification, then there is simple trick: append dummy
first element.  Then you can modify other nodes at will
and at the end just discard the first node.

Let me add that modification to list should be done with
care.  It is possible to share tails of lists and such
sharing can give considerable memory savings.  But once
you share list nodes modification can have quite strange
effects.  So normal style in FriCAS avoids modifying lists.
Basicaly destructive operations are used as speed hacks,
on unshared lists in well understood context (usually
during construction of a list).

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to