On Mon, Dec 08, 2025 at 02:00:29AM +0100, 'Ralf Hemmecke' via FriCAS - computer 
algebra system wrote:
> I wonder why we need a copy of the data structure for "terms" but not for
> "listOfTerms". The specification unfortunately says nothing about
> what the expected behaviour shoulld be. A copy is certainly safer, but do we
> really need/want it?

AFAICS copy is due to possibility of incorrect use.  'terms' is widely
used so I think copy was inserted either due to buggy uses or for
consistency with other places that do a copy.

In principle functions like 'terms' should be non-copying, and instead
all use places should be modified to avoid mutation.  But we do not
have automation to enforce immutability where we need it, so copy
is a progamtic choice.

> Anyway, the docstring for "terms" claims "This is the internal
> representation.". But it actually is a copy of it.
> 
> I also do not see why the implementation of "listOfTerms" appears under the
> "if M has Comparable then ..." condition. Is it just because its doctrics
> says something about "construct(listOfTerms x)=x" and "construct" involves
> "smaller?" ?

That is mostly historic.  'listOfTerms' was introduced partly as a
speedup, partly to allow sharing of low sevel code by several
domain.  This is limited use interface, so there is much less
chance for bugs.

-- 
                              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 view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/aUgNF0lAFKAUALed%40fricas.org.

Reply via email to