TURBO parameter names

Anything QL Software or Programming Related.
stevepoole
Super Gold Card
Posts: 717
Joined: Mon Nov 24, 2014 2:03 pm

Re: TURBO parameter names

Post by stevepoole »

Hi Emmbee,
You can even stipulate WHEN ERRor = errnum to cater only for a particular condition.
Steve.


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: TURBO parameter names

Post by EmmBee »

Hi Steve,
Yes you can, but it can't be done on QPC2, at least I don't think so.
And it has to be in the form ... WHEN variable = something ...
Michael


Ralf R.

Re: TURBO parameter names

Post by Ralf R. »

EmmBee wrote:Hi Steve,
Yes you can, but it can't be done on QPC2, at least I don't think so.
And it has to be in the form ... WHEN variable = something ...
Michael
No, it is the other way in QPC2: WHEN ERRor does work, but WHEN var does not.


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: TURBO parameter names

Post by EmmBee »

Per,

That’s an interesting program you have, recursively slicing an array, then when the final level is reached, the elements are passed across to the other array. This is certainly intriguing. I have compiled this with Q_Liberator, but it runs into trouble with the DIMN functions in EQS. So there’s probably a bug in Q_Liberator with DIMN, can you confirm this? I’ve managed to find a work-around, and this has made the code slightly shorter. Since EQN is doing the same work as EQS, and now EQS cannot be used because of the bug, the EQU function now does it all, with a modified DIMN check.

Code: Select all

1000 DEFine FuNction EQU(a,b)
1010 LOCal er, i%
1020 IF PARTYP(a)<>PARTYP(b):RETurn -15
1030 IF PARUSE(a)<>PARUSE(b):RETurn -17
1040 er=0
2020 IF DIMN(a)<>DIMN(b):RETurn -4
2030 IF DIMN(a,2+(PARTYP(a)=1))=0 THEN
2040  FOR i%=0 TO DIMN(a):a(i%)=b(i%)
2050 ELSE
2060  FOR i%=0 TO DIMN(a)
2070   er=EQU(a(i%),b(i%)):IF er<0:EXIT i%
2080  END FOR i%
2090 END IF
2100 RETurn er
2110 END DEFine
Michael


User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: TURBO parameter names

Post by pjw »

Michael,

Yes, I agree there is a problem. I havent investigated any further to see
whats going on. Cant think I never compiled it before - or perhaps something,
somewhere, has changed since 1998? Your version works perfectly (SMSQ/E 3.22,
QLib 3.35).

I wrote separate sub-functions for strings and numbers to speed up the routine,
as there are differences in handling the last dimension. This means any
questions regarding type will only need to be answered once for each call
rather than for every iteration. Not much in it I guess, except in special
circumstances.


Per
dont be happy. worry
- ?
User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: TURBO parameter names

Post by pjw »

Actually, there is a significant speed difference between the two versions: The original split version took 36 seconds on my machine (QPC2 on some Windoze box, where I have little control over what else the machine gets up to) for 10,000 runs, and 60 seconds for the compact version. This was only a quick test using the bulk of the harness I provided with my version, cutting out the display and pauses:

Code: Select all

1 DIM a$(2,2,2,2,6),b$(2,2,2,2,8)
2 DIM a(2,2,2,2),b(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:a(i%,j%,k%,l%)=count%:count%=count%+1
6 :
10 CLS: t = date
11 for it = 1 to 10000
12  ert EQU(b$,a$)
13  ert EQU(b TO a)
14 endfor it
15 print date - t
16 BEEP 2000,20
17 :
...


Per
dont be happy. worry
- ?
stevepoole
Super Gold Card
Posts: 717
Joined: Mon Nov 24, 2014 2:03 pm

Re: TURBO parameter names

Post by stevepoole »

Hi Emmbee,
Sorrry I was not too explicit : WHEN ERRor= errnum
Was shorthand to remind you to look up the list of error numbers in the beginners guide, to adapt to any errnum reported in #0.
You can do some wonderful things this way under QDOS: (not on QPC2).
10 When error=17: list#2, erlin-10 to erlin+10: continue: end when
100 nul=0
110 MIStake : REMark OK
120 nul=1E-615
130 stop
This works because MIStake is a normal Keyword which you can insert at the beginning of a line.
I used it to implement a debugger.
Steve.


stevepoole
Super Gold Card
Posts: 717
Joined: Mon Nov 24, 2014 2:03 pm

Re: TURBO parameter names

Post by stevepoole »

Hi pjw,
Try this :
place lines 1 to 5, at 20 onwards. insert line 17 stop
type goto 20, then RUN.
Your program will run faster, because the interpreter does not have to search through the program to find what line it is on. The longer the program, the faster a piece of code to be timed will be run, as long as it lies at the beginning of a program. This is a clue as to how to restructure your code when you finalise it. Call inner loops from the beginning of the listing.
Steve.


stevepoole
Super Gold Card
Posts: 717
Joined: Mon Nov 24, 2014 2:03 pm

Re: TURBO parameter names

Post by stevepoole »

I just erased this posting, as it got submitted twice...
steve.


User avatar
pjw
QL Wafer Drive
Posts: 1316
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: TURBO parameter names

Post by pjw »

Hi Steve,

I tested your suggestion, but found no noticeable difference in speed. . Maybe I misunderstood something?

SBasic is significantly different from SuperBASIC in so many ways. It is much more efficient in all(?) areas (thanks in part also to improvements in SMSQ/E vs QDOS). Many of the old tweaks I learnt over the years using SuperBASIC no longer apply. Perhaps this is one of them? Of course, if the code is likely to be run under all versions of the interpreter the old tricks still matter. But if they are only to be run under SBasic or be compiled, other rules may apply.

When developing a routine I try to focus on algorithmic efficiency first, then use that as a template and tweak the working code according to the vagaries of the target platform: Platforms vary, algorithms dont.

As a matter of possible interest, I also wrote an assembler version of the EQU routine. It does the same job in 0.3 seconds, ie 100 times faster, so for speed, thats the obvious way to go.

Per


Per
dont be happy. worry
- ?
Post Reply