Runtime evaluation: Difference between revisions

Content added Content deleted
(added note re Lua 5.3+ loadstring -> load)
(Added Wren)
Line 1,728: Line 1,728:
eval "out \"hello world\" endl console" console
eval "out \"hello world\" endl console" console
</lang>
</lang>

=={{header|Wren}}==
Firstly, Wren has a REPL which is started from the command line by running Wren-cli without any parameters.

Any valid Wren code can then be entered and immediately evaluated.

To quit the REPL just type Ctrl-C or Ctrl-D.

The examples in the Kotlin entry would look like this in the Wren REPL:
<pre>
$ wren-cli
\\/"-
\_/ wren v0.3.0
> 20 + 22
42
> 5 * 81.sqrt
45
> var triple = Fn.new { |x| x * 3 }
> triple.call(16)
48
>
</pre>

Secondly, Wren has the ''Meta.eval'' method which can be used from within a script to execute any valid Wren code (presented to it in string form) at runtime. The string could be constructed within the script, obtained from a file or input by the user. Here's a very simple example:
<lang ecmascript>import "meta" for Meta

var s = "for (i in 0..4) System.print(i)"
Meta.eval(s)</lang>

{{out}}
<pre>
0
1
2
3
4
</pre>


=={{header|zkl}}==
=={{header|zkl}}==