On Sat, May 28, 2022 at 02:55:50PM +0200, Ralf Hemmecke wrote:
>
> We also seem to have a bug (although I question that al(1..1) would be
> anything useful.
>
> (22) -> AL ==> AssociationList(String, List String)
>
> (23) -> al := empty()$AL
>
> (23) table()
> Type: AssociationList(String,List(String))
> (24) -> al."fire" := ["red", "orange", "yellow"]
>
> (24) ["red", "orange", "yellow"]
> Type: List(String)
> (25) -> al."water" := ["blue"]
> (25) ["blue"]
> Type: List(String)
> (32) -> al(1..1) -- doesn't stop
> C-c C-c
> >> System error:
> Interactive interrupt at #x534C5682.
The problem here is really with 'first'. AssociationList uses
implementation of 'first' from LinearAggregate:
first(x, n) == x(minIndex(x)+(0..(n-1)))
that is 'first(x, 2)' calls 'elt(x, 1..2)'. But 'elt'
is implemented in StreamAggregate in terms of 'first',
so that 'elt(x, 1..2)' calls 'first(x, 2)'. So we get
infinite recursion. Due to tail call optimization
this works as infinite loop.
Note that 'first(al, 2)' or 'elt(al, 2)' is sensible.
StreamAggregate has two childrens: ListAggregate and
LazyStreamAggregate. ATM all domains which have
StreamAggregate are also of children categories.
Also there are only two domains having LazyStreamAggregate:
Stream and Sequence. Sequence inherits implementation from
stream. So, it makes sense to remove implementation of 'elt'
from 'StreamAggregate' and add implementations to
ListAggregate and Stream. In ListAggregate we can use list
operations to implement it. In Stream we can give proper
lazy implementation (we need 'delay' for this so we can not
do this in LazyStreamAggregate).
--
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 on the web visit
https://groups.google.com/d/msgid/fricas-devel/20220528154414.GA17236%40fricas.math.uni.wroc.pl.