Python and Ruby

Chris Rebert clp2 at rebertia.com
Tue Feb 2 03:17:04 CET 2010


On Mon, Feb 1, 2010 at 6:14 PM, MRAB <python at mrabarnett.plus.com> wrote:
> Nobody wrote:
>> On Sun, 31 Jan 2010 22:36:32 +0000, Steven D'Aprano wrote:
>>>> for example, in if you have a function 'f' which takes two parameters to
>>>> call the function and get the result you use:
>>>>
>>>>  f 2 3
>>>>
>>>> If you want the function itself you use:
>>>>
>>>>   f
>>>
>>> How do you call a function of no arguments?
>>
>> There's no such thing. All functions take one argument and return a value.
>>
>> As functions don't have side-effects, there is seldom much point in having
>> a function with no arguments or which doesn't return a value. In cases
>> where it is useful (i.e. a value must have function type), you can use the
>> unit type "()" (essentially a zero-element tuple), e.g.:
>>
>>        f () = 1
>> or:
>>        f x = ()
>>
> A function with no arguments could be used as a lazy constant, generated
> only on demand.

The usefulness of that depends on a language's evaluation strategy.
Haskell, for instance, uses lazy evaluation by default, so your use
case doesn't apply in that instance.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list