On 28.05.22 17:44, Waldek Hebisch wrote:
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.

Well, I do not think so. What would be the specification? Get the second
element of the internal representation of al? Who can predict whether
this will be ["fire",...] or ["water",...]. It becomes only sensible
IMHO if I do

KV==>Record(key: String, entry: List String)
(entries(al)@List(KV)).2,

but then we are talking about List anyway.

The other thing is that I do something like

[foo(al.n) for n in 1..#al]

which should/could be done via

[foo x for x in entries(al)@List(KV)

Well, existence of that elt does not hurt, but I would somehow question
"sensible" unless someone gives me a good use case that I obviously now
overlook.

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.

OK, that's what I wanted to hear.

In Stream we can give proper lazy implementation (we need 'delay'
for this so we can not do this in LazyStreamAggregate).

Yes, that was exactly the problem that I faced when I tried to implement it generically.

I try to prepare a pull-request.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/92c7c727-5b51-d0f3-3f1d-b3f5a05b806a%40hemmecke.org.

Reply via email to