UserLinux chooses Python as "interpretive language" of choice

Bengt Richter bokr at oz.net
Sun Dec 21 16:41:02 EST 2003


On Sun, 21 Dec 2003 07:41:40 -0500, "John Roth" <newsgroups at jhrothjr.com> wrote:

>
>"Bengt Richter" <bokr at oz.net> wrote in message
>news:bs2j3b$fc5$0 at 216.39.172.122...
>> On Sat, 20 Dec 2003 06:38:20 -0500, "John Roth" <newsgroups at jhrothjr.com>
>wrote:
>>
>>
>> >Sure, you can use a property to not have to put
>> >in the explicit function call, but then you can't put
>> >in the explicit function call *anywhere* you use that
>> >property.
>> >
>> Nor can you supply explicit arguments if you want to, though you could
>> provide an alternate name, so you could access either way.
>
>That's really an inherent feature of the 'property' notion:
>since it's accessed like a variable, the getter can't have any
>parameters. Since the property access return an object,
>I suppose you could have something that looks like an
>indexable or slicable property.
Or even callable, with sneaky dynamic method substitution ;-)
Or any other expression trailer combination of, e.g.,
.attr, (), <any operator, like +-* etc> etc.

>
>> Nor can we do properties without accessing them via the attribute magic
>(i.e.,
>> not via bare global names for example).
>>
>> >Ruby syntax makes it *optional*. That's what is
>> >missing here.
>
>> I've floated various ideas/brain_farts more/less seriously for triggering
>magic
>> via name access alterantive to getattr magic, but there seems to be no
>enthusiasm
>> or else horrification at the thought, so I haven't stirred that pot for
>some time ;-)
>>
>> What would be the syntax you would like to use, with what effect?
>
>Well, the basic idea was simply to make the () optional for functions
>with no parameters. No particular syntax there but it would require some
>major jump through hoops gyrations from the virtual machine, and there
>would have to be some way of getting the function object when you
>wanted it, and I suspect the difference between a function object and
>a more general 'callable' would totally confuse most people. And of
>course, does a function/method with only keywords count as a function
>with no parameters?
>
>Ruby can get away with it because, as far as I know, functions are not
>first class objects. They certainly aren't in Perl which was Ruby's
>inspiration.
Really? Perl was Ruby's inspiration??

>
>It's a non-starter for Python, though.
Seems so. OTTOMH I guess you could have the tokenizer generate two kinds of names,
names_as_now, and bare_names (tagged so with lookahead determining no trailers).
Then you could dynamically check if a bare_name was referring to a callable, and
call it with no params if so, and for all other name usage do as now. Except that as
you point out, you'd need a way to inhibit the effect. But since this thing would be
unusual (and would cause major breakage), maybe it could be enabled only for references
to objects with an __autocall__ alias to their __call__ attribute. And then, since the
auto-call would only happen for bare names, you could pass it as a function by using
name.__call__ instead of name. Or use vars()['name'].

Not that I am proposing this ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list