Re: (rank)
Hi Alex, Ah. That's what I missed the sort direction of the second argument.. Thank you Lindsay On Tue, May 23, 2017 at 10:47 PM, Alexander Burger wrote: > Hi Lindsay, > > > My sample code ("ABRA..) is wrong. Sorry about that. > > Ah, I see. No problem. > > > > : (rank 'c '((a . a) (b . b) (d . d)) T) # ??? > > -> NIL > > : (rank 'd '((a . a) (b . b) (d . d)) T) # ??? > > -> NIL > > > > : (rank 'd '((a . a) (b . b) (d . d))) > > -> (d . d) > > : (rank 'c '((a . a) (b . b) (d . d))) > > -> (b . b) > > > > The latter two work as I would expect. > > I expected the first two to return '(d . d) > > The reason here is that 'rank' expects a *sorted* list. It traverses the > list, > and stops as soon as it can confirm or refute the desired condition. > > With a second argument non-NIL, it tries to "Returns the element from lst > ... > with a minimal CAR greater or equal to any". However, already the first > element > (a . a) is *less* than 'c' or 'd', hence it returns NIL. > > If you reverse the list, it works: > >: (rank 'c '((d . d) (b . b) (a . a)) T) >-> (d . d) > >: (rank 'b '((d . d) (b . b) (a . a)) T) >-> (b . b) > > It is the purpose of the second argument to tell 'rank' in which direction > it > should expect the list to be sorted. > > ♪♫ Alex > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: (rank)
Hi Lindsay, > My sample code ("ABRA..) is wrong. Sorry about that. Ah, I see. No problem. > : (rank 'c '((a . a) (b . b) (d . d)) T) # ??? > -> NIL > : (rank 'd '((a . a) (b . b) (d . d)) T) # ??? > -> NIL > > : (rank 'd '((a . a) (b . b) (d . d))) > -> (d . d) > : (rank 'c '((a . a) (b . b) (d . d))) > -> (b . b) > > The latter two work as I would expect. > I expected the first two to return '(d . d) The reason here is that 'rank' expects a *sorted* list. It traverses the list, and stops as soon as it can confirm or refute the desired condition. With a second argument non-NIL, it tries to "Returns the element from lst ... with a minimal CAR greater or equal to any". However, already the first element (a . a) is *less* than 'c' or 'd', hence it returns NIL. If you reverse the list, it works: : (rank 'c '((d . d) (b . b) (a . a)) T) -> (d . d) : (rank 'b '((d . d) (b . b) (a . a)) T) -> (b . b) It is the purpose of the second argument to tell 'rank' in which direction it should expect the list to be sorted. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: (rank)
Thanks Alex, My sample code ("ABRA..) is wrong. Sorry about that. I simplified too much from some other code I have written that has a lot of unrelated stuff in it. However, what about these examples? Similar to those of the documentation: : (rank 'c '((a . a) (b . b) (d . d)) T) # ??? -> NIL : (rank 'd '((a . a) (b . b) (d . d)) T) # ??? -> NIL : (rank 'd '((a . a) (b . b) (d . d))) -> (d . d) : (rank 'c '((a . a) (b . b) (d . d))) -> (b . b) The latter two work as I would expect. I expected the first two to return '(d . d) /Lindsay On Tue, May 23, 2017 at 12:32 PM, Alexander Burger wrote: > Hi Lindsay, > > > : (nil (setq *BitsSA (sort (make (map link (chop "ABRAABRACADABRA")) > > *BitsSA is a list of lists of characters: > >: (more *BitsSA) >("A") >("A" "A" "B" "R" "A" "C" "A" "D" "A" "B" "R" "A") >("A" "B" "R" "A") >("A" "B" "R" "A" "A" "B" "R" "A" "C" "A" "D" "A" "B" "R" "A") >... > > > : (rank (chop "BR") *BitsSA) > > -> ("R" "A" "C" "A" "D" "A" "B" "R" "A") > > This does not make sense. You search the ranking list with a *list* > argument > (chop "BR"), i.e. ("B" "R") > > Same here: > > > : (rank (chop "BRA") *BitsSA T)# ??? > > -> NIL > > So you compare the CARs of *BitsSA - which are characters (i.e. symbols) - > with > lists. A list, however, is always greater than a symbol. > > >From https://software-lab.de/doc/ref.html#cmp: > >For differing types, the following rule applies: Numbers are less than >symbols, and symbols are less than lists. > > ♪♫ Alex > > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >
Re: (rank)
Hi Lindsay, > : (nil (setq *BitsSA (sort (make (map link (chop "ABRAABRACADABRA")) *BitsSA is a list of lists of characters: : (more *BitsSA) ("A") ("A" "A" "B" "R" "A" "C" "A" "D" "A" "B" "R" "A") ("A" "B" "R" "A") ("A" "B" "R" "A" "A" "B" "R" "A" "C" "A" "D" "A" "B" "R" "A") ... > : (rank (chop "BR") *BitsSA) > -> ("R" "A" "C" "A" "D" "A" "B" "R" "A") This does not make sense. You search the ranking list with a *list* argument (chop "BR"), i.e. ("B" "R") Same here: > : (rank (chop "BRA") *BitsSA T)# ??? > -> NIL So you compare the CARs of *BitsSA - which are characters (i.e. symbols) - with lists. A list, however, is always greater than a symbol. >From https://software-lab.de/doc/ref.html#cmp: For differing types, the following rule applies: Numbers are less than symbols, and symbols are less than lists. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe