Can you compile a string to a task in NetLogo?

higher-order-functions, netlogo

Solution

You sure can! Using this one weird only-obvious-in-retrospect trick:

to-report string-to-task [s]
  report runresult (word "task [" s "]")
end

Note that this will return either a reporter task or a command task, depending on the contents of the input string.

Problem

For example, ``` let procedure string-to-task "print ?" (run procedure "hello") ``` There a couple reasons one would want to do this: - Tasks don't need to be recompiled, whereas strings sometimes do (especially when using a lot of them). - You can't pass in arguments when trying to run a string.

Original source