Comparisons and sorting of a numeric class....

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 8 09:57:23 EST 2015


On Wed, Jan 7, 2015 at 11:21 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
>
>> Marko Rauhamaa wrote:
>>> I prefer the Scheme way:
>>>    #f is a falsey object
>>>    everything else is a truthy object
>>
>> The Scheme way has no underlying model of what truthiness represents, just
>> an arbitrary choice to make a single value have one truthiness, and
>> everything else the other. It's just as meaningless and just as arbitrary
>> as the opposite would be:
>>
>>     #t is True
>>     everything else is falsey
>> [...]
>> I'd rather the Pascal way:
>>
>>     #t is True
>>     #f is False
>>     everything else is an error
>
> An advantage of the Scheme way is the chaining of "and" and "or". For
> example, this breaks in Python:
>
>    def dir_contents(path):
>        if os.path.isdir(path):
>            return os.listdir(path)
>        return None
>
>    def get_choices():
>        return dir_contents(PRIMARY) or \
>            dir_contents(SECONDARY) or \
>            [ BUILTIN_PATH ]

That depends on what the function is intended to do in the first
place. Why would you want to return the contents of an empty directory
rather than the default?

Anyway, to make that work as you want it in Scheme, dir_contents would
have to return #f, not None. Does it really make sense for a
non-predicate function to be returning the value "false"?



More information about the Python-list mailing list