Ruby and Python

Quinn Dunkan quinn at mark.ugcs.caltech.edu
Mon Nov 20 15:29:28 EST 2000


On 20 Nov 2000 14:52:19 +0100, Hrvoje Niksic <hniksic at arsdigita.com> wrote:
>"Alex Martelli" <aleaxit at yahoo.com> writes:
>
>> """
>> In Scheme, as in most dialects of Lisp, functions are first-class. This
>> means that they are values, just like any other data type--they may be
>> passed as arguments to functions  and returned as values of functions.
>> """
>
>The last part is what distinsguishes "first-class" from
>"second-class".  In C, for instance, functions might be called
>second-class objects because you can pass them to functions, but you
>cannot meaningfully return new ones from functions.
>
>The whole story about the enclosing environment is a red herring
>anyway, because it relies on side-effects.  When using proper
>*functions* in Python, they are always first-class objects, *and* you
>need no namespace games for them to work.

I'm not quite sure I understand:

def curried_add(x):
    def f(y, x=x): # <- namespace game here
        return x+y
    return f

Surely you'll agree that's a "real" function :)

My own personal definition of 'first class functions' wants functions to live
in the same namespace as other values, but that would probably disqualify
lisp, so obviously my defn is out of sync with the rest of the world's :)
I'd rather write in scheme anyway :)

I think python's scoping is not a bug or a feature, it's a design tradeoff.
Whether it's a worthwhile tradeoff is a matter of debate, but it is consistent
with the rest of the language, which tends to trade the ease of certain idioms
for explicit behaviour.  Indentation sacrifices the 'everything on one line'
and 'invent your own indentation style' idioms for explicit and consistent
block notation.  Putting most functionality in modules and encouraging
qualified imports sacrifices concise typing for explicit naming.  I think most
people would agree that the first two sacrifices are worth their tradeoffs.
When we get to sacrificing a number of functional idioms for explicit
namespaces, people start to disagree because functional idioms are useful.

Not that that little bit of content-less summary had anything to do with the
point, but hey, it's usenet.  And now the people from the grammar thread,
attracted by my use of 'that that' will probably come over and prolong this
thread further (farther?) :)



More information about the Python-list mailing list