![]() |
VAL incomplete - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Wishlist (https://www.boriel.com/forum/forumdisplay.php?fid=14) +---- Thread: VAL incomplete (/showthread.php?tid=2427) |
VAL incomplete - zarsoft - 06-24-2023 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 - 06-26-2023 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 - 06-26-2023 (06-26-2023, 07: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 VALx RE: VAL incomplete - zarsoft - 06-26-2023 (06-26-2023, 09:25 AM)zarsoft Wrote: Then, I will do it the hard way: I have updated https://www.boriel.com/forum/showthread.php?tid=2428 |