[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)

On 2/11/2014 11:19 AM, Travis Griggs wrote:
> On Feb 11, 2014, at 7:52 AM, Chris Angelico <rosuav at gmail.com> wrote:
>> So in that situation, the no-args call does make sense. Of course,
>> this is a call to a function that does take args, but it's accepting
>> all the defaults and providing no additional content. It's quite
>> different to actually define a function that mandates exactly zero
>> arguments, and isn't making use of some form of implicit state (eg a
>> closure, or maybe a module-level function that manipulates
>> module-level state - random.random() would be an example of the
>> latter). Syntactically, Python can't tell the difference between
>> "print()" and "foo()" where foo can never take args.
> So at this point, what I?m reading is that actually making a ?no arg function? is difficult, if we widen the semantics.

It is quite easy.

def f(): return 3  # or any other constant.

Chris said that useful functions in Python are (mostly) not really 
niladic, which is equivalent to saying that niladic functions in Python 
are (mostly) not really useful. They are a mainly a device in pure 
function theory to have constants (True, False, 0, 1, ...) while also 
having everything be a function (the 'pure' part).  Pure set theory uses 
its own tricks to make the same constants (and functions) be sets ;-).

Terry Jan Reedy