On Sat, May 28, 2022 at 05:25:47PM +0200, Ralf Hemmecke wrote:
> 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",...].

Pairs with non-present key are added at the beginning.  And important           
use case is when pairs are prepended.  After prepending k pairs                 
'rest(x, k)' gives you back original association list.  But                     
one may need to do some processing (say cleanup) for dropped                    
elements.  'first(x, k)' is convenient way to get those elements.               
I tend to write such things using 'first(x)', 'rest(x)' and                     
iteration but other folks may prefer 'first(x, k)'.

-- 
                              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/20220528193943.GB19894%40fricas.math.uni.wroc.pl.

Reply via email to