Would Anonymous Functions Help in Learning Programming/Python?

Donn Cave donn at u.washington.edu
Fri Sep 21 19:18:15 EDT 2007


In article <1190410638.211343.241690 at y42g2000hsy.googlegroups.com>,
 Cristian <super.sgt.pepper at gmail.com> wrote:
...

> To someone who's learning to program wouldn't a syntax like the
> further give them all they need and also reinforces the idea that
> functions are data just like everything else?
> 
> my_function = function(foo, bar): pass
> an_instance_method = function(self, foo): pass
> a_method_declaration = method(self, foo): pass

I think one followup has already alluded to the division
between Python `statements' and `expressions'.  The `def'
statement may create and bind a value, but since it's a
statement and not an expression, it doesn't have any value.
Python is not a functional programming language.  It probably
could be reinvented to eliminate statements, but ... there
are already plenty of languages to choose from.

If we're going there, though, I think it's obvious that
once you have defined

  an_instance_method = function(self, foo): ...

it should be invoked

  an_instance_method(an_instance, foo)

which would be much less messy in nested expressions where
the current standard OOP notation flips from right to left
too much ...

  string.join(x.split('-'), '').lower()

  --> lower(string.join('', split(x, '-')))

It might make for some interesting problems, but that's what
it's about, changing things so it stays fun for everyone.
At the same time, partial function parameter binding should
be implemented, so you could say

   dotted = string.join('.')
   ...
   v = dotted(['comp', 'lang', 'python'])

As you probably well know, that isn't my idea, it's a common
functional programming language idiom.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list