Hi,

PicoLisp makes it very easy to build and work with suffix arrays.
Yesterday I realized there is a built-in '*rank* function which I thought
would neatly replace some custom code I had written to do the same thing.

However,  passing non-nil in the third-param does not return the expected
result if the 'any argument is not a number. It always returns NIL. It does
return the expected maximal CAR for 'any with 'flg NIL, just not the
expected minimal CAR with 'flg non-NIL.

I am wondering if this is a bug in picolisp or perhaps I am missing
something regarding how the function is supposed to work.

/Lindsay

Sample code:

# Create minimal suffix array
: (nil (setq *BitsSA (sort (make (map link (chop "ABRAABRACADABRA"))))))
: (nil (for L *BitsSA (println (pack L))))
"A"
"AABRACADABRA"
"ABRA"
"ABRAABRACADABRA"
"ABRACADABRA"
"ACADABRA"
"ADABRA"
"BRA"
"BRAABRACADABRA"
"BRACADABRA"
"CADABRA"
"DABRA"
"RA"
"RAABRACADABRA"
"RACADABRA"

# Use (rank ... https://software-lab.de/doc/refR.html#rank
: (rank (chop "BR") *BitsSA)
-> ("R" "A" "C" "A" "D" "A" "B" "R" "A")
: (rank (chop "BR") *BitsSA T)
-> NIL

# Further examples of using (rank
: (rank 50 '((1000 . a) (100 . b) (1 . c)) T)
-> (100 . b)
: (rank (chop "BRA") *BitsSA T)            # ???
-> NIL
: (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)

Reply via email to