Runtime evaluation: Difference between revisions

eliminate unneeded parenthesis from J "evaluate with argument" example, clean up description
(Added JavaScript example)
(eliminate unneeded parenthesis from J "evaluate with argument" example, clean up description)
Line 228:
<lang j>". 'a =: +/ 1 2 3' NB. execute a string to sum 1, 2 and 3 and assign to noun a</lang>
 
Only J expressions are allowed in strings used as as arguments for <code>".</code> (control words and blocks of expressions are not allowed).
 
OrAlterntively, you can use the conjunction [http://www.jsoftware.com/help/dictionary/d310n.htm <code>:</code>] (''Explicit Definition'') to create various kinds of functions and evaluate them. Arguments have names, such as "y", which are specified by the language definition. For example:
 
<lang j>(monad : '+/y') 1 2 3</lang>
 
Rules of scope for such functions match those described on the [[Scope modifiers]] page. TheseAlso, control words behave (like anyif. otheror wordsfor. inor the languagewhile.) and mayblocks be used in formingof expressions. Expressionsare andallowed statements,in includingstrings control words,which are allowedevaluated in these explicitthis definitionsfashion.
 
Rules of scope for such functions match those described on the [[Scope modifiers]] page. These words behave like any other words in the language and may be used in forming expressions. Expressions and statements, including control words, are allowed in these explicit definitions.
=={{header|Lua}}==
<lang lua>f = loadstring(s) -- load a string as a function. Returns a function.
6,962

edits