You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can we think of a good way to pass in arguments, à la LevelSpace maybe, so people don't have to write a line of code for each argument they want to pass in?
Maybe drawing on our anonymous function syntax (and maybe functionality?)
I think that looks good, but I wonder if it is limited to lambdas and functions relying only on positional arguments then but not keyword arguments. I've tried to play around with it, but I haven't gotten it to work yet. Maybe I am missing something obvious, though.
An alternative is for these primitives to take an anonymous function that does the variable assignment, maybe? Like
py:run [ x -> "a_function(varname=x)"]
How does that look to you?
One question: why the different primitive? Could this not just build top of py:run and py:runresult?
Alternatively, we could do the syntax you suggested, but include the ability to pass in a list with name and value for keyword arguments?
(py:call "afunction" arg1 arg2 ["keyword" value])
Ideally we could find a way to write code that looks more like python, though. I can see how this works, but it would be nicer to just be able to inject them into a string of actual python code... somehow. Or maybe I am putting too much weight on that, and this is totally fine?
An alternative is for these primitives to take an anonymous function that does the variable assignment, maybe?
Unfortunately, that doesn't work as the Python and NetLogo valid variable names are pretty different (in particular, can't uses dashes in Python).
Also, this would do pretty much exactly the same thing as using Python lambdas, but using Python lambdas doesn't require any magic. Do you see an advantage of something like this over Python lambdas? Seems like just one lambda for another. With your example, Python lambdas would be:
(py:call "lambda x : a_function(varname = x)" 5)
(of course, you'd only do this is varname is keyword only or whatever)
One question: why the different primitive? Could this not just build top of py:run and py:runresult?
Unfortunately, I don't see a way to do that, since those already use variadic arguments to concatenate strings into multiple lines.
(py:call "afunction" arg1 arg2 ["keyword" value])
I'd be down for this, but you'd need to use the list reporter rather than the literal syntax most of the time, since you can't include arbitrary reporters in the literal syntax.
Unfortunately, that doesn't work as the Python and NetLogo valid variable names are pretty different (in particular, can't uses dashes in Python).
Yeah... I started realizing it wasn't a good idea after I posted it. That's another good reason it isn't.
Also, this would do pretty much exactly the same thing as using Python lambdas, but using Python lambdas doesn't require any magic. Do you see an advantage of something like this over Python lambdas? Seems like just one lambda for another.
Totally - I guess I was trying to move more of the coding style to the NetLogo end, and that's all that would accomplish. I'm not sure that's actually desirable in this extension. So definitely something I think is important, or something that would buy us anything special.
Unfortunately, I don't see a way to do that, since those already use variadic arguments to concatenate strings into multiple lines.
Ah, gotcha.
(py:call "afunction" arg1 arg2 ["keyword" value])
I'd be down for this, but you'd need to use the list reporter rather than the literal syntax most of the time, since you can't include arbitrary reporters in the literal syntax.
I like where py:call is going! I think this feature would be nice, especially given how many python libraries include functions that have keyword arguments. Without it, people would have to write their own positional versions of those existing functions just to then call the library functions correctly.
Good point about list! Sigh... nothing we can do about it though.
I think this feature would be nice, especially given how many python libraries include functions that have keyword arguments. Without it, people would have to write their own positional versions of those existing functions just to then call the library functions correctly.
Still not sure... It's actually more verbose than the lambda version since you have to write out list. Also, not sure how the extension would distinguish keyword pairs a list argument.
Activity
qiemem commentedon Feb 7, 2020
What about
py:callwith following syntax?Probably need different ones for reporter vs command...
py:callvspy:callreport?lambdamakes this pretty flexible, but unfortunately, Python'slambdaalso has some pretty severe limitations. What do you think?arthurhjorth commentedon Feb 8, 2020
I think that looks good, but I wonder if it is limited to lambdas and functions relying only on positional arguments then but not keyword arguments. I've tried to play around with it, but I haven't gotten it to work yet. Maybe I am missing something obvious, though.
An alternative is for these primitives to take an anonymous function that does the variable assignment, maybe? Like
How does that look to you?
One question: why the different primitive? Could this not just build top of
py:runandpy:runresult?arthurhjorth commentedon Feb 9, 2020
Alternatively, we could do the syntax you suggested, but include the ability to pass in a list with name and value for keyword arguments?
Ideally we could find a way to write code that looks more like python, though. I can see how this works, but it would be nicer to just be able to inject them into a string of actual python code... somehow. Or maybe I am putting too much weight on that, and this is totally fine?
qiemem commentedon Feb 11, 2020
Unfortunately, that doesn't work as the Python and NetLogo valid variable names are pretty different (in particular, can't uses dashes in Python).
Also, this would do pretty much exactly the same thing as using Python lambdas, but using Python lambdas doesn't require any magic. Do you see an advantage of something like this over Python lambdas? Seems like just one lambda for another. With your example, Python lambdas would be:
(py:call "lambda x : a_function(varname = x)" 5)(of course, you'd only do this is
varnameis keyword only or whatever)Unfortunately, I don't see a way to do that, since those already use variadic arguments to concatenate strings into multiple lines.
I'd be down for this, but you'd need to use the
listreporter rather than the literal syntax most of the time, since you can't include arbitrary reporters in the literal syntax.arthurhjorth commentedon Feb 12, 2020
Yeah... I started realizing it wasn't a good idea after I posted it. That's another good reason it isn't.
Totally - I guess I was trying to move more of the coding style to the NetLogo end, and that's all that would accomplish. I'm not sure that's actually desirable in this extension. So definitely something I think is important, or something that would buy us anything special.
Ah, gotcha.
I like where
py:callis going! I think this feature would be nice, especially given how many python libraries include functions that have keyword arguments. Without it, people would have to write their own positional versions of those existing functions just to then call the library functions correctly.Good point about
list! Sigh... nothing we can do about it though.qiemem commentedon Feb 19, 2020
Still not sure... It's actually more verbose than the lambda version since you have to write out
list. Also, not sure how the extension would distinguish keyword pairs a list argument.