Re: [Ql-Users] Select on
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 Ql-Users : 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. Maybe useful? That would then be the PICK$ function. It's on DIY disk 1, sub E, found on Dilwyn's site, where else? To me it looks like PICK$ is the OPPOSITE of string SELect. PICK$ goes like this: 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$ = "???" END SELect 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 END SELect 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 = $0123 TO $0300: Go_to_North = $3001, $1234: Go_to_East = etc though of what practical use they would be I know not.. But out of interest, does such a function exist? Per ___ QL-Users Mailing List
Re: [Ql-Users] Select on
If we are talking about Selecting on single-character strings, such as when coding actions depending on some keypress, I would like to tell you about how I get around this problem. At the very beginning, I would declare some constants of the codes of all the alphabetical characters, all 52 of them. Underscores are used in the names to highlight these vars are constants and their initial values should not change. I will give what the code would look like under Minerva, and then how this would look in SMSQ/E. Note that when Selecting on strings, both cases, capitals and lower case letters are considered equivalent. This has to be taken into account. 100 : 110 : 120 REMark In Minerva SuperBASIC 130 case$ = "" : REMark "a" == "A" - both cases 140 SELect ON case$ 150 = "a" : PRINT 'Choice is "A"' 160 = "b" : PRINT 'Choice is "B"' 170 = "c" : PRINT 'Choice is "C"' 180 = "d" : PRINT 'Choice is "D"' 190 = "e" : PRINT 'Choice is "E"' 200 = "f" : PRINT 'Choice is "F"' 210 = CHR$(27) : PRINT 'Esc pressed' 220 END SELect 230 : 2000 REMark In SMSQ/E S*BASIC 2010 REMark Note: MANIFEST is optional TURBO command for extra constant checking 2020 : 2030 MANIFEST : _a = 97 : A_ = 65 2040 MANIFEST : _b = 98 : B_ = 66 2050 MANIFEST : _c = 99 : C_ = 67 2060 MANIFEST : _d = 100 : D_ = 68 2070 MANIFEST : _e = 101 : E_ = 69 2080 MANIFEST : _f = 102 : F_ = 70 2090 MANIFEST : ENTER = 10 : Esc = 27 2100 CLS 2110 REPeat loop 2120 PRINT 'Choose case: Press a letter between "a" and "F" '; 2130 case = CODE(INKEY$(#1,-1)) : IF case <> ENTER : PRINT CHR$(case); " "; 2140 SELect ON case 2150 = _a,A_ : PRINT 'Choice is "A"' 2160 = _b,B_ : PRINT 'Choice is "B"' 2170 = _c,C_ : PRINT 'Choice is "C"' 2180 = _d,D_ : PRINT 'Choice is "D"' 2190 = _e,E_ : PRINT 'Choice is "E"' 2200 = _f,F_ : PRINT 'Choice is "F"' 2210 = Esc : PRINT 'Esc pressed' : EXIT loop 2220 = REMAINDER : PRINT 'Try again' 2230 END SELect 2240 END REPeat loop 2250 PRINT 'Test complete' 2260 PRINT #0,'Test complete' Michael ___ QL-Users Mailing List
Re: [Ql-Users] Select on
If we are talking about Selecting on single-character strings, such as when coding actions depending on some keypress, I would like to tell you about how I get around this problem. At the very beginning, I would declare some constants of the codes of all the alphabetical characters, all 52 of them. Underscores are used in the names to highlight these vars are constants and their initial values should not change. I will give what the code would look like under Minerva, and then how this would look in SMSQ/E. Note that when Selecting on strings, both cases, capitals and lower case letters are considered equivalent. This has to be taken into account. 100 : 110 :120 REMark In Minerva SuperBASIC130 case$ = "" : REMark "a" == "A" - both cases140 SELect ON case$150 = "a" : PRINT 'Choice is "A"'160 = "b" : PRINT 'Choice is "B"'170 = "c" : PRINT 'Choice is "C"'180 = "d" : PRINT 'Choice is "D"'190 = "e" : PRINT 'Choice is "E"'200 = "f" : PRINT 'Choice is "F"'210 = CHR$(27) : PRINT 'Esc pressed'220 END SELect230 :2000 REMark In SMSQ/E S*BASIC2010 REMark Note: MANIFEST is optional TURBO command for extra constant checking2020 :2030 MANIFEST : _a = 97 : A_ = 652040 MANIFEST : _b = 98 : B_ = 662050 MANIFEST : _c = 99 : C_ = 672060 MANIFEST : _d = 100 : D_ = 682070 MANIFEST : _e = 101 : E_ = 692080 MANIFEST : _f = 102 : F_ = 702090 MANIFEST : ENTER = 10 : Esc = 272100 CLS2110 REPeat loop2120 PRINT 'Choose case: Press a letter between "a" and "F" ';2130 case = CODE(INKEY$(#1,-1)) : IF case <> ENTER : PRINT CHR$(case); " ";2140 SELect ON case2150 = _a,A_ : PRINT 'Choice is "A"'2160 = _b,B_ : PRINT 'Choice is "B"'2170 = _c,C_ : PRINT 'Choice is "C"'2180 = _d,D_ : PRINT 'Choice is "D"'2190 = _e,E_ : PRINT 'Choice is "E"'2200 = _f,F_ : PRINT 'Choice is "F"'2210 = Esc : PRINT 'Esc pressed' : EXIT loop2220 = REMAINDER : PRINT 'Try again'2230 END SELect2240 END REPeat loop2250 PRINT 'Test complete'2260 PRINT #0,'Test complete' Michael ___ QL-Users Mailing List
Re: [Ql-Users] Select on
That's probably the best solution for the problem - String$ SELECT has always been a half-baked solution in SuperBASIC. Tobias > Am 21.06.2020 um 13:38 schrieb Bob Spelten via Ql-Users > : > > Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via Ql-Users > : > >> 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. >> >> Maybe useful? >> > That would then be the PICK$ function. > It's on DIY disk 1, sub E, found on Dilwyn's site, where else? > > Bob > > -- > The BSJR QL software site at: "http://home.hccnet.nl/b.spelten/ql/; > > -- > Deze e-mail is gecontroleerd op virussen door AVG. > http://www.avg.com > > ___ > QL-Users Mailing List ___ QL-Users Mailing List
Re: [Ql-Users] Select on
Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via Ql-Users : 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. Maybe useful? That would then be the PICK$ function. It's on DIY disk 1, sub E, found on Dilwyn's site, where else? Bob -- The BSJR QL software site at: "http://home.hccnet.nl/b.spelten/ql/; -- Deze e-mail is gecontroleerd op virussen door AVG. http://www.avg.com ___ QL-Users Mailing List
Re: [Ql-Users] Select on
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. Maybe useful? Cheers, Norm. -- Sent from my Android device with K-9 Mail. Please excuse my brevity. ___ QL-Users Mailing List
Re: [Ql-Users] Select on
I have already tried roughly all the various solutions and obviously we know very well that they are solutions they don't really know satisfaction. I also speak from the readability point of view, when you have to get your hands by modifying the code written years before or written by other nested cycles of functions are difficult to understand. My question is straightforward: would anyone with assembler knowledge want to try their hand at creating a new extension capable of solving the problem? I can offer him a drink! (good Italian wine!) :-D Il giorno sab 20 giu 2020 alle ore 23:24 pjwitte via Ql-Users < ql-users@lists.q-v-d.com> ha scritto: > On 20/06/2020 17:00, Jan Bredenbeek via Ql-Users wrote: > > Op za 20 jun. 2020 14:01 schreef Dave Park via Ql-Users < > > ql-users@lists.q-v-d.com>: > > > >> ooGyebd = Goodbye > >> goodbye <> Goodbye > >> > > Use a hash algorithm like CRC-16 or CRC-32? ;-) > > Thats probably the fastest solution so far :o) Maybe overkill for just > a few items. INSTR is pretty fast - and its built in. > > Per > > > ___ > QL-Users Mailing List > ___ QL-Users Mailing List
Re: [Ql-Users] Select on
On 20/06/2020 17:00, Jan Bredenbeek via Ql-Users wrote: Op za 20 jun. 2020 14:01 schreef Dave Park via Ql-Users < ql-users@lists.q-v-d.com>: ooGyebd = Goodbye goodbye <> Goodbye Use a hash algorithm like CRC-16 or CRC-32? ;-) Thats probably the fastest solution so far :o) Maybe overkill for just a few items. INSTR is pretty fast - and its built in. Per ___ QL-Users Mailing List
Re: [Ql-Users] Select on
Op za 20 jun. 2020 14:01 schreef Dave Park via Ql-Users < ql-users@lists.q-v-d.com>: > > > > ooGyebd = Goodbye > goodbye <> Goodbye > > Use a hash algorithm like CRC-16 or CRC-32? ;-) Jan ___ QL-Users Mailing List
Re: [Ql-Users] Select on
On Sat, Jun 20, 2020 at 3:03 AM Derek Stewart via Ql-Users < ql-users@lists.q-v-d.com> wrote: > Hi, > > Here is my un-subtle attempt, how about summing the ASCII codes for the > character string to be selected and use SELect ON to select the option > based on the sum total, for example: > > 10 a$="Goodbye" > 15 asum=0 > 20 FOR a=1 TO LEN(a$): asum=asum+CODE(a) > 40 SELect ON asum > 50 = 255: REMark ASCII Code sum for "Hello" > 51 PRINT "Hello World" > 60 = 364: REMark ASCII sum for "Goodbye" > 61 PRINT "Goodbye World" > 70 END SELect > ooGyebd = Goodbye goodbye <> Goodbye -- Dave Park d...@sinclairql.com ___ QL-Users Mailing List
Re: [Ql-Users] Select on
Hi, Here is my un-subtle attempt, how about summing the ASCII codes for the character string to be selected and use SELect ON to select the option based on the sum total, for example: 10 a$="Goodbye" 15 asum=0 20 FOR a=1 TO LEN(a$): asum=asum+CODE(a) 40 SELect ON asum 50 = 255: REMark ASCII Code sum for "Hello" 51 PRINT "Hello World" 60 = 364: REMark ASCII sum for "Goodbye" 61 PRINT "Goodbye World" 70 END SELect On 19/06/2020 20:35, pjwitte via Ql-Users wrote: On 19/06/2020 20:02, Daniel Baum via Ql-Users wrote: What about doing something like this. In languages like c# the equivalent of the "select on: command is hardly ever used and if .. else if ... else is much more common: 100 INPUT a$ 110 IF a$="a" THEN 115 PRINT "hello a" 120 ELSE 130 IF a$="b" 135 PRINT "hello b" 150 ELSE 155 IF a$="c" 157 PRINT "hello c " 160 ELSE 170 PRINT "hello d" 180 END IF 190 END IF 200 END IF Actually, I had need of a similar construct recently. This is what I came up with: 100 FOR i% = 1 TO 6 110 case$ = 'case' & i% 120 c% = case$ INSTR "case1 case2 case3 case4 case5 case6" 130 : 140 SELect ON c% 150 = 1: PRINT 'case 1' 160 = 7: PRINT 'case 2' 170 = 13: PRINT 'case 3' 180 = 19: PRINT 'case 4' 190 = 25: PRINT 'case 5' 200 = 31: PRINT 'case 6' 210 = REMAINDER : PRINT 'ERROR' 220 END SELect 230 : 240 END FOR i% This is obviously just a demo to illustrate the idea. It seems reasonably fast. In my case I was able to keep all the terms to more or less the same size. If there is a chance of ambiguity, one could wrap the terms in delimiters: c% = '#' & case$ & '#' INSTR '#case1#test this2#or this#etc#..#' Per ___ QL-Users Mailing List ___ QL-Users Mailing List
Re: [Ql-Users] Select on
On 19/06/2020 20:02, Daniel Baum via Ql-Users wrote: What about doing something like this. In languages like c# the equivalent of the "select on: command is hardly ever used and if .. else if ... else is much more common: 100 INPUT a$ 110 IF a$="a" THEN 115 PRINT "hello a" 120 ELSE 130 IF a$="b" 135 PRINT "hello b" 150 ELSE 155 IF a$="c" 157 PRINT "hello c " 160 ELSE 170 PRINT "hello d" 180 END IF 190 END IF 200 END IF Actually, I had need of a similar construct recently. This is what I came up with: 100 FOR i% = 1 TO 6 110 case$ = 'case' & i% 120 c% = case$ INSTR "case1 case2 case3 case4 case5 case6" 130 : 140 SELect ON c% 150 = 1: PRINT 'case 1' 160 = 7: PRINT 'case 2' 170 = 13: PRINT 'case 3' 180 = 19: PRINT 'case 4' 190 = 25: PRINT 'case 5' 200 = 31: PRINT 'case 6' 210 = REMAINDER : PRINT 'ERROR' 220 END SELect 230 : 240 END FOR i% This is obviously just a demo to illustrate the idea. It seems reasonably fast. In my case I was able to keep all the terms to more or less the same size. If there is a chance of ambiguity, one could wrap the terms in delimiters: c% = '#' & case$ & '#' INSTR '#case1#test this2#or this#etc#..#' Per ___ QL-Users Mailing List
Re: [Ql-Users] Select on
What about doing something like this. In languages like c# the equivalent of the "select on: command is hardly ever used and if .. else if ... else is much more common: 100 INPUT a$ 110 IF a$="a" THEN 115 PRINT "hello a" 120 ELSE 130 IF a$="b" 135 PRINT "hello b" 150 ELSE 155 IF a$="c" 157 PRINT "hello c " 160 ELSE 170 PRINT "hello d" 180 END IF 190 END IF 200 END IF On Fri, Jun 19, 2020 at 5:28 PM Giorgio Garabello via Ql-Users < ql-users@lists.q-v-d.com> wrote: > For that I think it is easier to implement a new instruction (even an > external extension) instead of modifying the current instruction. > > Il giorno ven 19 giu 2020 alle ore 12:19 pjwitte via Ql-Users < > ql-users@lists.q-v-d.com> ha scritto: > > > On 19/06/2020 10:52, Giorgio Garabello via Ql-Users wrote: > > > "SELect ON" instruction > > > I find it has a major flaw that will not allow you to manage > alphanumeric > > > variables, > > > I unfortunately don't know the assemly > > > Would someone be available to create an extension similar to SELECT > (e.g. > > > SELECT $) capable of handling strings? > > > I understand that it is not simple .. :-( > > > > > > Giorgio > > > > Sadly, this is one of many improvements in Minerva BASIC that did not > > make it into SBASIC. At least SBASIC no longer crashes on FOR i$ = 'a' > > TO 'z'! or REPeat a$ .. It just errors. (As of V3.35, I think) > > > > Per > > > > ___ > > QL-Users Mailing List > > > ___ > QL-Users Mailing List > ___ QL-Users Mailing List
Re: [Ql-Users] Select on
For that I think it is easier to implement a new instruction (even an external extension) instead of modifying the current instruction. Il giorno ven 19 giu 2020 alle ore 12:19 pjwitte via Ql-Users < ql-users@lists.q-v-d.com> ha scritto: > On 19/06/2020 10:52, Giorgio Garabello via Ql-Users wrote: > > "SELect ON" instruction > > I find it has a major flaw that will not allow you to manage alphanumeric > > variables, > > I unfortunately don't know the assemly > > Would someone be available to create an extension similar to SELECT (e.g. > > SELECT $) capable of handling strings? > > I understand that it is not simple .. :-( > > > > Giorgio > > Sadly, this is one of many improvements in Minerva BASIC that did not > make it into SBASIC. At least SBASIC no longer crashes on FOR i$ = 'a' > TO 'z'! or REPeat a$ .. It just errors. (As of V3.35, I think) > > Per > > ___ > QL-Users Mailing List > ___ QL-Users Mailing List
Re: [Ql-Users] Select on
On 19/06/2020 10:52, Giorgio Garabello via Ql-Users wrote: "SELect ON" instruction I find it has a major flaw that will not allow you to manage alphanumeric variables, I unfortunately don't know the assemly Would someone be available to create an extension similar to SELECT (e.g. SELECT $) capable of handling strings? I understand that it is not simple .. :-( Giorgio Sadly, this is one of many improvements in Minerva BASIC that did not make it into SBASIC. At least SBASIC no longer crashes on FOR i$ = 'a' TO 'z'! or REPeat a$ .. It just errors. (As of V3.35, I think) Per ___ QL-Users Mailing List
[Ql-Users] Select on
"SELect ON" instruction I find it has a major flaw that will not allow you to manage alphanumeric variables, I unfortunately don't know the assemly Would someone be available to create an extension similar to SELECT (e.g. SELECT $) capable of handling strings? I understand that it is not simple .. :-( Giorgio ___ QL-Users Mailing List