Comparisons and sorting of a numeric class....

Marko Rauhamaa marko at pacujo.net
Thu Jan 8 01:21:36 EST 2015


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 ]


Marko



More information about the Python-list mailing list