Sheerpower Logo

Code Manifestation -- Strings as Code


Code Manifestation — Strings as Code

Sheerpower allows strings to contain code. This makes it easy to design and implement your own business-specific scripting languages. The following example uses the eval() function:

a = 45 b = 10 c$ = 'a*b + pi' declare dynamic d d = eval(c$) print d

The contents of c$ are compiled into Sheerpower bytecode at runtime and then evaluated. The result is stored in 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.

In special cases where greater runtime flexibility is required, Sheerpower supports code manifestation, allowing entire blocks of code to be compiled and executed dynamically at runtime using the execute statement:

suffix$ = '_temp' code$ = 'for i' + suffix$ + ' = 1 to 10' + chr$(13) + _ 'print i' + suffix$ + chr$(13) + _ 'next i' + suffix$ execute code$ execute 'print i_temp'
Note: Use of execute can make your code harder to maintain because the actual code does not exist until runtime. It should be used only in special situations where dynamic code generation is the best or cleanest solution.

Why It Matters

This runtime compilation capability means Sheerpower can act as both a host language and a code generator. Developers can build domain-specific scripting engines, dynamic rule processors, or business logic layers that evolve without redeployment. It combines the performance of compiled code with the adaptability of scripting — a powerful advantage for systems that need to respond to changing business logic or external data sources in real time.

(Show/Hide Sheerpower Code Manifestation Takeaways)
Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.