eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
SORRY! This is bullshit, this i no eval (VAL/VAL$) function (as. e.g. on Spectrum or eval() in Python)! See the following answers in this thread.
Oops, suddenly it also works here (sQLux 1.1.1.) also in a Minerva MultiBASIC job:-)
Last edited by ql_freak on Thu Jun 26, 2025 10:38 pm, edited 1 time in total.
http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX

- janbredenbeek
- Super Gold Card
- Posts: 683
- Joined: Wed Jan 21, 2015 4:54 pm
- Location: Hilversum, The Netherlands
- Contact:
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
It works in your first example since you give it a numeric argument (SIN(PI/6)), which is evaluated and coerced into a string before the function is called.
But when you give it a string argument, it simply returns the string itself.
I guess you want it to evaluate the string as a numerical expression, much like the VAL function on the Spectrum.
There is no easy way to do that. Perhaps one way would be to create a file with a BASIC command like 'result=<expression>' (where <expression> is substituted from the argument given to eval$) and running it with a DO command?
(sorry, currently have no time to test this
)
But when you give it a string argument, it simply returns the string itself.
I guess you want it to evaluate the string as a numerical expression, much like the VAL function on the Spectrum.
There is no easy way to do that. Perhaps one way would be to create a file with a BASIC command like 'result=<expression>' (where <expression> is substituted from the argument given to eval$) and running it with a DO command?
(sorry, currently have no time to test this

Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
I think that i have an Eval toolkit, somewhere in my collection. Or two... I'll look for them when i get home.
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
VAL and TRANSLATE toolkit (with source)
- Attachments
-
- val.zip
- (42.13 KiB) Downloaded 9 times
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
That looks similar to a small toolkit on my site, but with slightly different keyword names etc.
I guess one is probably a more recent version of the other. The asm on the one on my site says:
(Sorry, Windows mangled the surname of one of the authors, it should have been S. Sjöberg)
I guess one is probably a more recent version of the other. The asm on the one on my site says:
https://dilwyn.theqlforum.com/tk/eval.zip* EVAL_asm: extracted and adapted by Thierry Godefroy from "A mathematical and
* graphical toolkit" by R.D. Harding, M. Lindroos and S. Sj„berg (of
* Chalmers university of technology - Gothenburg - Sweden).
(Sorry, Windows mangled the surname of one of the authors, it should have been S. Sjöberg)
--
All things QL - https://dilwyn.theqlforum.com
All things QL - https://dilwyn.theqlforum.com
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
The version I posted above is by Manuel Bendala Garcia, Sevilla, Spain
So probably is a different version.
So probably is a different version.
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
You're of course right, don't know what I have thought when writing this. It's not an eval function because you cannot pass it a string, which a user has input. It can only evaluate an expression which is coded in the program. Sorry.janbredenbeek wrote: Wed Jun 25, 2025 12:05 pm It works in your first example since you give it a numeric argument (SIN(PI/6))...,
http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX

Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
Thank you Andrew. Nice piece of software, but it's not an VAL/VAL$/EVAL function which is my intention.
This is a function to evaluate mathematical expressions, similar as my self written (1) function (expression parser) I'm using in my Coca (COmboboxCAlculator) calculator (see in Downloads section of my homepage). From what I have read in the docs, this VAL-function does nothing know about variables and/or already defined SuperBASIC functions (which should be usable in a full VAL/EVAL-function, like the eval()-function in Python). BTW: The EJC compiler (unfortunately nearly no one has it, and it cannot be made free, because it uses the Lattice C compiler [ported and licenced to QL by Metacomco] - the rest, the library, start-code, ... is downloadable from my homepage. DUNNO if Erling has patched the Lattice Compiler itself) has a similar val() function which can evaluate mathematical expressions (like "sin(3.14.../6)*2") - I have written an example for this function in this forum a long time ago).
What I want is an EVAL(string) [or better EVAL$(string$)?] function, which can evaluate any SuperBASIC expression. E.g. (code not tested!):
Code: Select all
var = 1.7
var2 = 3
CONSTANT = 1
100 DEFine FuNction even(num)
110 RETurn int(num/2) = num/2
120 END DEFine
130 :
140 result = EVAL("var*2 + CONSTANT*even(var2)")
[url=viewtopic.php?t=1879]
Unfortunately my example does not run correctly :-(
--
(1) Not really self written. It's just an extended version of the expression parser from the example in Stroustrups "The C++ Programming Language", extended with the power operator and support for all (most?) mathematical functions available in the standard library of C++. BTW: albeit Coca compiles only with a C++ compiler, the expression parser itself (also C++) does not use special C++ features, it should be easy to convert it to C (even EJC should be capable to compile it then [reentrant, ROMable code :-)]).
http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX

- janbredenbeek
- Super Gold Card
- Posts: 683
- Joined: Wed Jan 21, 2015 4:54 pm
- Location: Hilversum, The Netherlands
- Contact:
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
It's an interesting problem.
You cannot simply write a SB expression to a file and evaluate this using e.g. DO or MERGE, since that stops the program altogether (especially in a function).
Under Minerva and SMSQ/E however, it's possible for an SB program to start another SB program as an EXECutable (Minerva MultiBASIC using EW pipep). So you could write your expression to a file or pipe and run this as another SB program.
Now the real challenge is how to pass parameters to the second program, since it won't know about the calling program's variables. Also, the result has to be stored somewhere and picked up by the calling program (I guess using temporary files or maybe pipes).
I'll probably come back at this later...
You cannot simply write a SB expression to a file and evaluate this using e.g. DO or MERGE, since that stops the program altogether (especially in a function).
Under Minerva and SMSQ/E however, it's possible for an SB program to start another SB program as an EXECutable (Minerva MultiBASIC using EW pipep). So you could write your expression to a file or pipe and run this as another SB program.
Now the real challenge is how to pass parameters to the second program, since it won't know about the calling program's variables. Also, the result has to be stored somewhere and picked up by the calling program (I guess using temporary files or maybe pipes).
I'll probably come back at this later...
Re: eval Function (eval$) for SuperBASIC (Job 0,0 only?) (does <EDIT>or does not(?)</EDIT> work in Minervas MultiBASICs)
Well the original version from EmmBee in the thread posted above is working. Cosmetic problem: For any expression in channel#0 there will be printed:
result = ...
CONTINUE
As I have now some understanding, how SuperBASIC is working internally (thanks to my reflection toolkit and your hint, where to find the tokenized form of a SuperBASIC program in Jan Jones SuperBASIC reference manual) I assume (IMHO!):
There is no code (not even unvectored) in QDOS, which can evaluate a string as an expression. I assume if you have a line like:
PROCname expression (or FuNcname(expression))
e.g.:
myProc sin(pi/6)*2
SuperBASIC tokenizes the expression (sin(pi/6)*2) and then there seems to be a (none vectored) routine, which can evaluate this tokenized expression.
There (IMHO) must be such a code in QDOS else the above code (myProc ...) shouldn't be possible.
result = ...
CONTINUE
As I have now some understanding, how SuperBASIC is working internally (thanks to my reflection toolkit and your hint, where to find the tokenized form of a SuperBASIC program in Jan Jones SuperBASIC reference manual) I assume (IMHO!):
There is no code (not even unvectored) in QDOS, which can evaluate a string as an expression. I assume if you have a line like:
PROCname expression (or FuNcname(expression))
e.g.:
myProc sin(pi/6)*2
SuperBASIC tokenizes the expression (sin(pi/6)*2) and then there seems to be a (none vectored) routine, which can evaluate this tokenized expression.
There (IMHO) must be such a code in QDOS else the above code (myProc ...) shouldn't be possible.
http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX
