[Python-ideas] Inline Functions - idea

yoav glazner yoavglazner at gmail.com
Wed Feb 5 19:38:35 CET 2014


On Feb 5, 2014 8:18 PM, "David Mertz" <mertz at gnosis.cx> wrote:
>
> It's hard for me to see the use case for this "inline function" idea.
 The example given is just some code that is repeated within branches of an
'if'; but the obvious thing is to move that repetition outside the if/elif
clauses.
>
> I understand that the example is simplified to present it, but it's hard
for me easily to imagine a case where either using a closure or passing in
'locals()' directly fails to cover everything you are asking for.  I mean,
you did say that passing locals() is "clunky", but it's hard to see how any
function that dealt with the availability of different variables on an ad
hoc basis could really be non-clunky (and that what every inline function
would have to do)

How about:

Def somefun():
  a = 5
  b = 7
  return fmt('{a} is not {b}')

inline def fmt(fmtstr):
  return fmtstr.format_map(locals())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140205/e6dbf5f5/attachment-0001.html>


More information about the Python-ideas mailing list