[Python-ideas] Jump to function as an an alternative to call function
Jonathan Fine
jfine2358 at gmail.com
Thu Aug 16 14:00:13 EDT 2018
Hi Jacob
I really like your previous post. I find it really helps me understand
what you want. You wrote
> I wanted the called, jumped to function to change state in the caller.
> From what I tried to do, passing locals() cannot accomplish this. I have
> made it happen in other languages though.
> In the R language, one can do this
> foo = function(){
> localenv = environment()
> eval(bar, environment = localenv)
> The above code captures the environment of the calling function and
> executes the called function as if the calling function's local environment
> was the global environment.
So in a nutshell, you'd like to be able to write code like this, but in Python?
> bar doesn't have to be a function, it can be any
> valid R expression captured with the expr() function, and everything in R is
> an expression thus allowing for the full usage code blocks.
This Python can already do. Any Python expression can be turned into a
function, simply by prefixing it with 'lambda:'.
> Outside of
> lisp-like languages this feat seems to usually be impossible though.
I'm an Emacs user, so I know Lisp. But R is new to me. But this URL
tells me that R is based on Lisp.
https://www.i-programmer.info/programming/other-languages/1706-a-programmers-guide-to-r.html
And, in my view, this makes your problem immediately much more
important for the Python community. Because both Python and R are
major languages in the area of Data Science.
Thank you so much for your previous post, and to all the others whose
posts have contributed to this clarification.
--
best regards
Jonathan
More information about the Python-ideas
mailing list