Ian Kelly <ian.g.ke...@gmail.com>: >> 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?
To demonstrate the principle. Such short-circuited expressions have spread to numerous high-level programming languages. Python has them, too, but you have to be extra careful not to be hit by the surprising false interpretations. > 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"? By custom, #f acts as the de-facto None of Scheme for that very reason. In classic Lisp, nil takes the roles of None, False and [], leading to the confusion I mentioned. Of course, Scheme now has to deal with distinguishing None (#f) and False (#f as well). Luckily, that confusion rarely comes to play. Marko -- https://mail.python.org/mailman/listinfo/python-list