Re: [Ql-Users] RET_STK and debugging SBASIC code

2014-07-09 Thread Wolfgang Lenerz

Hi Michael,


PICK$ will select the nth item from the list that follows the n.

Consider  PICK$(n, aaa, bbb, ccc, ddd, etc)

If n is 1 then PICK$ will return aaa because it is the 1st item in the list.  If n is 5 
then etc would be returned because it is the 5th item.  The parameters of PICK$ can be of 
any type: they will be coerced into strings.  Expressions can be supplied, for example, dev$  
file$.



Ah OK, thanks.


There is a particular problem that PICK$ may help us to solve.  Occasionally, 
we may want to iterate through a list of items.  If these items are strings, 
then we may well reach for a FOR loop and do something like . . .

(...)

Which version do you prefer?


I'd probably use an array.



Thanks though, this looks like an interesting keyword!

Wolfgang

___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm


[Ql-Users] RET_STK and debugging SBASIC code

2014-07-08 Thread Michael Bulford
Hi Wolfgang,

PICK$ will select the nth item from the list that follows the n.

Consider  PICK$(n, aaa, bbb, ccc, ddd, etc)

If n is 1 then PICK$ will return aaa because it is the 1st item in the list.  
If n is 5 then etc would be returned because it is the 5th item.  The 
parameters of PICK$ can be of any type: they will be coerced into strings.  
Expressions can be supplied, for example, dev$  file$.
 
There is a particular problem that PICK$ may help us to solve.  Occasionally, 
we may want to iterate through a list of items.  If these items are strings, 
then we may well reach for a FOR loop and do something like . . .

FOR x$ = aaa, bbb, ccc, ddd, etc 

Unfortunately, this is not allowed.  The identifier for a FOR loop has to be 
numeric, either floating point or integer.  This leaves us with a problem: how 
to do the above? 
There is a way to do this.  A normal numeric FOR loop could be used, and then 
assign values to x$ depending on the FOR loop index, like this . . .

FOR n = 1 TO 5 
  SELect ON n = 1 : x$ = aaa : = 2 : x$ = bbb : = 3 : x$ = ccc : = 4 : x$ 
= ddd : = 5 : x$ = etc

This can also be done using PICK$ . . .

FOR n = 1 TO 5 
  X$ = PICK$(n, aaa, bbb, ccc, ddd, etc)

Which version do you prefer?

The version using PICK$ may be more readable, but please bear in mind the 
following.  PICK$ will evaluate all of its parameters before deciding  which 
value to return, so, in terms of efficiency, this would not be the best choice. 
 If outright execution speed is top priority, then the Select version should be 
chosen.

What I like about PICK$ is the readability factor.  I use PICK$ in my own 
programs and can recommend it.

Michael
___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm


[Ql-Users] RET_STK and debugging SBASIC code

2014-07-05 Thread Michael Bulford
Hi all,

I believe I have discovered a very good way of using the RET_STK function

DEFine FuNction bug(p1$, p2$, p3$, p4$, p5$)
LOCal n, x$
   PRINT #0,PAUSEd at line ! RET_STK !
   FOR n = 1 TO 5
  x$ = PICK$(n, p1$, p2$, p3$, p4$, p5$)
  IF PARNAM$(n) OR x$: PRINT #0,!! PARNAM$(n)   =   x$ ! 
   END FOR n 
   CURSEN #0 : PAUSE : CURDIS #0 
   PRINT #0, : RETurn 0 
END DEFine bug 

Note that PICK$ is from DIY Toolkit VolE_CONTROL_code.  A function is used 
rather than a procedure so that RET_STK will always produce the correct line 
number. 

Suppose I wanted to stop my program under some condition at line 2885 and print 
out the values of the variables row, col and count.   The following line could 
be inserted 

2885 IF some_condition : ERT bug(row,col,count) 

Then what could appear in #0 is 

PAUSEd at line 2885   row = 19   col = 20   count = 156 

All the parameters are optional.   You can even supply expressions, although 
only their values would get printed. 

I have found this to be so useful.  There is no need to type in any line 
numbers – RET_STK is doing all the work.  Since using this, my debugging has 
become so much easier and less time-consuming. 

Michael 
___
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm