Jump to content

Send an unknown method call: Difference between revisions

→‎{{header|J}}: complete thought
(+J)
(→‎{{header|J}}: complete thought)
Line 158:
=={{header|J}}==
 
'''Solution''': There are multiple ways to evoke code at runtime. The most common is '''<tt>". y</tt>''' (''eval''uate the code in the string y, producing a noun), but there's also <tt>''name''~ </tt> (which will modify J's stack by replacing the two tokens '''<tt>''name''</tt>''' and <tt>~</tt> with the named object) as well as '''<tt>x 128!:2 y</tt>''' (''apply'' the verb described by <tt>x</tt> to the noun <tt>y</tt>). There are other methods as well, e.g.
 
There are other methods as well, e.g., '''<tt>@.</tt>''','''<tt>`:</tt>''', and '''<tt>^:</tt>''', though these are designed to consume gerunds (pre-parsed ASTs) rather than strings (though, of course, a pre-processor can always be provided to convert strings into ASTs before feeding them to these operators).
 
'''Example''':<lang j> sum =: +/
Line 181 ⟶ 183:
nameToDispatch (128!:2) 1 2 3
3</lang>
 
 
 
 
=={{header|Java}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.