On 21/06/2020 13:38, Bob Spelten via Ql-Users wrote:
Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via
To me it looks like PICK$ is the OPPOSITE of string SELect. PICK$ goes
I have a vague recollection that Simon N Goodwin did something
similar, maybe, in the DIY Toolkit.
I think it was passed a variable and a list of strings, and
returned the position of the variable in the list. Something like
That would then be the PICK$ function.
It's on DIY disk 1, sub E, found on Dilwyn's site, where else?
direction$ = PICK$(direction%,"North","East","South","West")
Which is nothing other than what we've already got, ie:
SELect on direction%
= 1: direction$ = "North"
= 2: direction$ = "East"
= 3: direction$ = "South"
= 4: direction$ = "West"
= REMAINDER: direction$ = "???"
although it is theoretically faster than SELect as it calculates the
location of the desired value rather than doing a bunch of comparisons.
But what a string select is supposed to do is:
direction% = PICK%(direction$,"North","East","South","West")
ie it returns some processable answer to a string query, viz
SELect on direction$
= 'North': Go_to_North
= 'East': Go_to_East
= 'South': Go_to_South
= 'West: Go_to_West
= REMAINDER: Go_to_Hell
Just for fun, after reading Giorgio's mail, I went and wrote a
function like PICK% (not PICK$). Although it is very simple, it is
significantly slower than the INSTR suggestion I made earlier. It
would probably more or less match a real string select in speed.
A hash function could be faster/more efficient for lists critical
enough to justify the presence of such a function.
Ideally, it would be some function that would map lexicographical
values well onto numbers, eg
f('ABC') < f('abc') or f('abcd') > f('abc'), etc, in a word or
longword. Then things like ranges might be possible:
term = Magic(term$)
SELect on term
= $00000123 TO $00000300: Go_to_North
= $00003001, $00001234: Go_to_East
though of what practical use they would be I know not..
But out of interest, does such a function exist?
QL-Users Mailing List