Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run a task with a list of arguments #539

Closed
qiemem opened this issue Feb 4, 2014 · 4 comments
Closed

Add ability to run a task with a list of arguments #539

qiemem opened this issue Feb 4, 2014 · 4 comments

Comments

@qiemem
Copy link
Member

qiemem commented Feb 4, 2014

Basically, add lisps apply to NetLogo.
Example:
apply task foo [ "one" "two" "three"]

One potential criticism of this is that it doesn't allow as much compile-time checking as normal run, but I'm not sure that even counts as a criticism.

Inspired by: http://stackoverflow.com/questions/21541133/run-a-task-with-a-variable-number-of-arguments-in-netlogo

@qiemem
Copy link
Member Author

qiemem commented Mar 11, 2015

I came across this problem again, and actually figured out a workaround!

to-report listify-task [ tsk num-args ]
  let args (reduce word n-values num-args [ (word " (item " ? " ?)") ])
  report runresult (word "task [ (runresult tsk " args ") ]")
end

This converts a reporter task from something that takes a number of arguments to one that takes a list. You use it like so:

observer> show (runresult (listify-task task [?1 + ?2] 2) [4 5])
observer: 9

apply could be implemented on top of this like:

to-report apply [ tsk args ]
  report (runresult (listify-task tsk length args) args)
end

though it would be somewhat inefficient. Better to store the result of listify-task and the run that whenever you need to.

It essentially creates a task of the following form: task [ (runresult tsk item 0 ? item 1 ? ...)].

@SethTisue
Copy link
Collaborator

nice. very clever

@SethTisue
Copy link
Collaborator

@SethTisue
Copy link
Collaborator

qiemem added a commit that referenced this issue Aug 29, 2016
Fixes #539
These are being left as __ for now and may be promoted later (possibly
with a different name).
@qiemem qiemem closed this as completed in 38ea195 Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants