Task

Demonstrate a language's ability for programs to execute code written in the language provided at runtime.

Show what kind of program fragments are permitted (e.g. expressions vs. statements), and how to get values in and out (e.g. environments, arguments, return values), if applicable what lexical/static environment the program is evaluated in, and what facilities for restricting (e.g. sandboxes, resource limits) or customizing (e.g. debugging facilities) the execution.

You may not invoke a separate evaluator program, or invoke a compiler and then its output, unless the interface of that program, and the syntax and means of executing it, are considered part of your language/library/platform.

For a more constrained task giving a specific program fragment to evaluate, see Eval in environment.




 
Module checkit {
      Module dummy {
            i++
            Print Number
      }
      \\ using Stack New { } we open a new stack for values, and old one connected back at the end
      \\ using block For This {} we erase any new definition, so we erase i (which Local make a new one)
      a$={
            Stack New {
                  For this {
                        Local i
                        for i=1 to 10 : print i : next i
                  }
            }
            If valid(k) then print k
      }
      i=500
      k=600
      Push 1000
      inline a$
      Print i=500
      Print Number=1000
      \\ eval an expression
      Print Eval("i+k")
      \\ eval a function
      Print Function("{read x : = x**2}", 2)=4
      Dim k(10)=123
      \\ eval array only
      Print array("k()", 2)=123
      Push 10, 10
      \\ call a module by make it inline first
      inline code dummy, dummy
      Print i=502
}
CheckIt
 