Python and Ruby

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Feb 1 02:22:23 CET 2010


On Sun, 31 Jan 2010 16:50:50 -0800, Chris Rebert wrote:

>>>> How do you call a function of no arguments?
>>>
>>> It's not really a function in that case, it's just a named constant.
>>> (Recall that functions don't/can't have side-effects.)
>>
>>
>>>>> time.time(), random.random()
>> (1264983502.7505889, 0.29974255140479633)
>>>>> time.time(), random.random()
>> (1264983505.9283719, 0.74207867411026329)
>>
>>
>> They don't look terribly constant to me.
> 
> Those aren't functions in the pure functional programming sense; which
> is unsurprising since Python isn't a [pure] functional language. They
> both involve side-effects. time() does I/O to the clock chip to see what
> time it is, and random() uses and changes a global seed value variable
> (which, in a double-whammy, takes its initial value from time()).

Yes, but these tasks -- get the time, get a (pseudo) random number -- are 
not unique to Python. Surely even Lisp and Haskell code will sometimes 
need to know the time. Whether they are "pure functions" (functions in 
the mathematical sense) or impure, they're still functions in some sense. 
How do you deal with such impure functions?



-- 
Steven



More information about the Python-list mailing list