![]() |
J.2 Strings as Code |
a = 45 b = 10 c$ = 'a*b + pi' declare dynamic d d = eval(c$) print dThe content of c$ is compiled into Sheerpower byte code at runtime and then evaluated. The result is stored into D. Because the eval() function can return any data type, depending on the string that was passed into it, D must be declared as a dynamic variable.
suffix$ = '_temp' code$ = 'for i'+suffix$ + '= 1 to 10\' + 'print i'+suffix$ + '\next i'+suffix$ execute code$ execute 'print i_temp'Note: The use of execute can make your code harder to maintain because the actual code does not exist until runtime. It should only be used in special cases where it is the best solution.
Hide Description
|
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |