![]() |
|
VAL incomplete - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: Wishlist (https://forum.boriel.com/forumdisplay.php?fid=14) +---- Thread: VAL incomplete (/showthread.php?tid=2427) |
VAL incomplete - zarsoft - 2023-06-24 In ZX SPECTRUM: LET x = 2 PRINT VAL "2*x" Prints 4 But on the compiler gives 0 How about adding variables from "a" to "z" in VAL? RE: VAL incomplete - boriel - 2023-06-26 This cannot be done in compiled BASIC. VAL "2*x" will need the ROM VAL, which calls the BASIC interpreter. This will need to store the variables in Sinclair BASIC Format which takes more space and is slow so the ROM interpreter will find the variable "x" in the BASIC Variables region. Currently, a compiled variable like that of the example takes 1 byte (just the space needed to store the number). For Sinclair BASIC it will always be a Float (5 bytes, and slow) + the variable name "x" encoded in another region, etc. So VAL here will behave as most BASICs, convert a STRING to a number or return 0 if it cannot decode it (indeed Sinclair BASIC VAL is very powerful). There is a library function to call the BASIC interpreter, BTW, but it won't work in this case because it still needs the "x" variable. RE: VAL incomplete - zarsoft - 2023-06-26 (2023-06-26, 08:32 AM)boriel Wrote: VAL "2*x" will need the ROM VAL. Then, I will do it the hard way: LET X = 5 LET F$ = "2*X" LET G$ = VALx$( F$) ( G$ = "2*5" ) PRINT VAL G$ (result = 10) Code: ' PROGRAM VALxRE: VAL incomplete - zarsoft - 2023-06-26 (2023-06-26, 10:25 AM)zarsoft Wrote: Then, I will do it the hard way: I have updated https://forum.boriel.com/showthread.php?tid=2428 |