Returning a value from exec or a better solution

Jack Trades jacktradespublic at gmail.com
Tue Aug 30 14:31:26 CEST 2011


On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft <rtw at rtw.me.uk> wrote:


> > That's brilliant and works flawlessly.  Thank you very much!
>
> If an impementation (as you say up thread) can populate globals
> or locals with whatever they want, then how do you know that last
> item added was the function definition the user supplied ?
>
> Rob.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I spoke a bit too soon with the "works flawlessly" post.  In addition to
your issue, there is also the problem that supplying an empty environment
does not allow the user to call necessary functions (like scheme_eval).


Why not just get the name from the user
>

That's probably what I'll end up doing, something similar to:

special_forms = {}

def exec_func_def(symbol, def_string, name=None):
  exec(def_string)
  if name is None:
    special_forms[symbol] = f
  else:
    special_forms[symbol] = eval(name)

It just feels kind of hackish to me, when what I really want to do here is
eval an anonymous function.

-- 
Nick Zarczynski <http://www.rentageekit.com>
Pointless Programming Blog <http://pointlessprogramming.wordpress.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110830/cda0a60f/attachment.html>


More information about the Python-list mailing list