TonyTebby wrote:
This "macro substitution" in Foxpro is not really anything to do with
macros - it is a run-time expression evaluator that parses and evaluates a
string.

Foxpro can do it because it is based on early purely interpreted Bill Gates
BASIC which always parses all statements every time they are executed.
JavaScript also has an eval() function because javascript is (nearly) purely
interpreted. SuperBASIC, SBASIC, VisualBASIC and JAVA cannot because they
program is compiled to execute a fixed sequence of pseudo instructions
written for a "virtual machine" (Java bytecodes), an "engine" (Pascal
p-codes)  or a "run-time interpreter" (S*BASIC, VisualBasic).

In principle, an Eval could be added to SuperBASIC.

Compilation
1) Detect that a statement includes an eval and do not parse / compile it
but extract the "eval" functions replacing them by special variables (e.g.
&01$, &02$ etc)
2) For each eval in the statement, generate an assignment &xx$ = [eval
parameter] and store it in the program
3) Store the modified statement uncompiled after these assignments.

Runtime, when the uncompiled statement is encountered
1) spawn a new set of SBASIC system variables and tables (in principle this
could be done once only)
2) substitute the values of the eval variables into the statement
3) parse and compile the statement
4) now the tricky bit - return to the main set of  SBASIC tables and execute
the statement

This would work (1000s of times slower than normal execution)  for simple
cases such as A="Upper": Print Eval( A & "('Hello'))
I can't verify that as the source code is compiled before execution. But even if it is 1000s of time slower, it will still be a lot faster than modifying manually a field in , let's say, a database of a few 100s of records and I would need a calculator to do it.

But imagine the chaos if someone did

If xxx: A="": B="End For" Else A="End For": B=""
For Index = 1 to 100
  ...
  Exit Index
...
Eval (A)
...
Eval (B)

The end of the loop depends on the value of xxx and can change during
execution, but SBASIC compiles the end of the loop before execution.
This trick does work in Javascript because it is purely and slowly
interpreted.
Yes, I can imagine it. But then the content of the string could be controlled by an array, I think.
That array would hold only the operators and/or functions tolerated in the string.
Example:
dim str_allowed$(2,15)
str_allowed$(0)='upper$':str_allowed$(1)='lower$':str_allowed$(2)='proper_name$'
dim num_allowed$(5,5)
num_allowed$(0)='instr':num_allowed$(1)=�<�:num_allowed$(2)=�*� etc
Of course this would limit the power of such a 'VAL' function, but better something than nothing at all.
The above explanation of mine could of course be completely irrelevant and/or stupid. If it is, sorry for wasting your time.

Any suggestions?
If Sbasic can't cope with such a 'VAL' function, I know now I've been wasting several month of programming in Sbasic and designing windows with Easymenu/Easysptr.

If we (well, some clever programmers, I mean) would/could enhance the features/possibilities of 'DO'-files.
If we could force a 'DO'-file to return to the calling job instead of returning to Job 0/command line, a big step ('Quantum Leap?) would be made, because a 'macro-substitution' is already possible with a 'DO'-file.

100 rem macro_bas
110 REMark example of substitution /VAL
120 res1$="res1$=" :res2$="res2$=" :REMark res1$ string res2$ num
130 L1$='(' :R1$=")": f1$='upper$': string1$="'qdos'"
140 num1$="20":num2$="5":f2$="*"
150 OPEN_OVER#3,ram1_mac_do
160 PRINT#3,res1$&f1$&l1$&string1$&r1$
170 PRINT#3,res2$&num1$&f2$&num2$
180 CLOSE#3
190 DO 'ram1_mac_do'
200 PRINT res1$,res2$
210 rem lines 200 ... are not executed
220 rem because ram1_mac_do doesn't return to mac_bas but to job
225 rem 0/command line
230 rem type 'print res1$,res2$ on the command line
235 rem and 'QDOS', '200' will be displayed

Thank you for reading this .
Kind regards
Fran�ois Van Emelen

Tony Tebby

----- Original Message -----
From: "Fran�ois Van Emelen" <[EMAIL PROTECTED]>
To: "QL users list" <[EMAIL PROTECTED]>; "Fran�ois Van Emelen"
<[EMAIL PROTECTED]>
Sent: mardi 18 f�vrier 2003 17:34
Subject: [ql-users] Sbasic and macro substitutions



Hi all,

I've been using Foxpro v2 (programmable database system) for several
years now and 'macro substitution' is one of those powerful functions I
use a lot in my programmes. I wonder whether such a function is
available (possible?) in Sbasic.
Here's an example of a 'macro substitution':

l='('
r=')'
f='UPPER'
v='"ql-smsq"'
c=F+L+V+R
? c (?=print) displays as expected UPPER('ql-smsq')
cc=&c (&=macro substitution sign)
?cc  displays QL-SMSQ

Is there a way to achieve this in Sbasic (Qliberated Sbasic) ?
How ? Why not?

Fran�ois Van Emelen




Reply via email to