Hi,

but then there should be one consequence: one should remove all
destructive operations from lists, as they do not work. Then, this is
the bug, to lead to believe that one performs a destructive change. Or
at least: exclude the argument 1 for delete! and give an error.


Am 02.11.15 um 03:47 schrieb Waldek Hebisch:
> 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).
>

-- 
Mit freundlichen Grüßen

Johannes Grabmeier

Fraktionsvorsitzender 
FREIE WÄHLER, Stadtrat Deggendorf

Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Fax: +49-(0)-3224-192688

-- 
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