TCAT, Thanks for the info. The article compares Qlib with SuperCharge. which, with its Lenslock technology was a real PITA. Turbo, its successor, is considerably better. However, I see that it still wont accept arrays as parameters for SB procs/fns, only m/c ones. That frequently doesnt work for me. Id like to use Turbo, for the reasons I gave, but with some of its counter-intuitive quirks, I dont really consider it SB-compatible*. Id have to hobble my style to comply. And with the speed of modern QL systems, including emulators on fast PCs, the difference in speed between Turbo and QLib isnt normally an issue.
* Eg: In QLib-compatible SBasic all parameters are handled in a consistent, logical way. They are always passed by reference unless you want them not to. In your latest example changing the line 110 to:
110 val (a$): ref b$
ie, feeding the s$ paramters with an expression, will achieve the same: 'abc done'. (In SuperBASIC you may have to use something like val a$ & ''). There are no array operators in SB (the only operation supported is slicing) so arrays are always passed by reference.
Could the following program (or something that achieves the same) be done in a Turbo-compatible way? (Lines < 100 are just a harness to fill two complex arrays, one string and one numeric, and then clone (EQUate) those arrays into other, corresponding, arrays. LRUN in the standard S*Basic 3-window interpreter.)
Code: Select all
1 DIM a$(2,2,2,2,6),b$(2,2,2,2,8)
2 DIM x(2,2,2,2),y(2,2,2,2)
3 FOR i%=0 TO 2:FOR j%=0 TO 2:FOR k%=0 TO 2:FOR l%=0 TO 2:a$(i%,j%,k%,l%)='L'&i%&j%&k%&l%
4 count%=0
5 FOR i%=0 TO 2:FOR j%=0 TO 2:FOR k%=0 TO 2:FOR l%=0 TO 2:x(i%,j%,k%,l%)=count%:count%=count%+1
6 :
10 CLS:PRINT a$,\
12 er=EQU(b$,a$)
14 CLS#0:CLS#2:PRINT#2;b$,\:PRINT#0;er
16 BEEP 2000,20:PAUSE
18 CLS:PRINT !x!\
20 er=EQU(y TO x)
22 CLS#2:PRINT#2!y!\:PRINT#0;er\
24 BEEP 2000,20
26 :
100 REMark EQU SBASIC function to
101 REMark EQUate two arrays of the
102 REMark same dimensions and type
103 REMark Requires tk2 or equivalent
104 :
105 REMark ©PWitte, August 1998
106 REMark For "educational" purposes only
107 REMark Use at own risk. No warranties!
108 :
1000 DEFine FuNction EQU(a,b)
1010 LOCal er
1020 IF PARTYP(a)<>PARTYP(b):RETurn -15
1030 IF PARUSE(a)<>PARUSE(b):RETurn -17
1040 er=0
1050 IF PARTYP(a)=1 THEN
1060 RETurn EQS(a,b)
1070 ELSE
1080 RETurn EQN(a,b)
1090 END IF
1100 END DEFine
1110 :
2000 DEFine FuNction EQN(a,b)
2010 LOCal i%
2020 IF DIMN(a)<>DIMN(b):RETurn -4
2030 IF DIMN(a(0))=0 THEN
2040 FOR i%=0 TO DIMN(a):a(i%)=b(i%)
2050 ELSE
2060 FOR i%=0 TO DIMN(a)
2070 er=EQN(a(i%),b(i%)):IF er<0:EXIT i%
2080 END FOR i%
2090 END IF
2100 RETurn er
2110 END DEFine
2120 :
3000 DEFine FuNction EQS(a,b)
3010 LOCal i%
3020 IF DIMN(a)<>DIMN(b):RETurn -4
3030 IF DIMN(a(0,0))=0 THEN
3040 FOR i%=0 TO DIMN(a):a(i%)=b(i%)
3050 ELSE
3060 FOR i%=0 TO DIMN(a)
3070 er=EQS(a(i%),b(i%)):IF er<0:EXIT i%
3080 END FOR i%
3090 END IF
3100 RETurn er
3110 END DEFine
3120 :
Interestingly you will see,that the parameter variable names and types are irrelevant - its the type of the passed parameter that counts, and although the variable names a and b have been used to represent an array in the parameter list and function body, they arent 'tainted' in the token list and can be reused as a scalar variable in the same program.