On 11/02/2015 05:54 PM, Prof. Dr. Johannes Grabmeier FW wrote:
> I see, so I had a different (and not valid) meaning of destructive
> operations in mind!
> Am 02.11.15 um 17:46 schrieb Waldek Hebisch:
>> Docstring for 'delete!':
>>
>> delete!(u, i) destructively deletes the \spad{i}th element of u.
>>
>> "Working" means that operation is doing what is promised.
>> AFAICS 'delete!' is keeping its promise: returned value
>> is OK.
Yes.
>> I do not know what more could we do to make
>> clear that 'delete!' is a version of 'delete' that may
>> be used when you do not care what happens to the
>> argument (for examples because you will forget the
>> argument and only use returned value).
The point is that unless the docstring explicitly says so, it is always
unsafe to use the variable that was given in the arguments. So even when
a in an array and i an integer,
a.i:=x
is equivalent to
setelt!(a, i, x)
in other words, one shouldn't trust a anymore.
The docstring for setelt! in PrimitiveArray comes from here.
https://github.com/fricas/fricas/blob/master/src/algebra/aggcat.spad#L835
and says this
setelt! : (%, Dom, Im) -> Im
++ setelt!(u, x, y) sets the image of x to be y under u,
++ assuming x is in the domain of u.
++ Error: if x is not in the domain of u.
So, yes, the setelt! is certainly a special case, but is that docstring
really so telling that is says that u is *not* garbage after application
of setelt! ?
Furthermore, as Waldek mentioned, "destructive" operation means
"potentially destructive", i.e., it might not destructively modify it's
argument(s) at all. Well, no programmer would probably implement setelt!
in a functional way (no side effects), but according what Waldek cited
from ug01:
This actually means that it is {\it allowed} to update its
arguments but it is not {\it required} to do so.
such an implementation would not contradict this general principle and
not the docstring of setelt!. Yes, I call this a bug.
And as for improving the 'delete!' docstring. I believe that programmers
who don't know all the library conventions by heart certainly
appreciate, if there were a sentence that explicitly states which of the
argument is destructively modified and maybe even in which way (as would
be necessary for setelt!).
delete! : (%, Integer) -> %
++ delete!(u, i) destructively deletes the \spad{i}th element of u.
Better perhaps
++ delete!(u, i) returns a structure v that is u without the
++ \spad{i}th element.
++ It is unsafe to use the first argument after the call.
Ralf
--
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.