Python and Ruby

Ed Keith e_d_k at yahoo.com
Sun Jan 31 20:31:05 EST 2010


--- On Sun, 1/31/10, Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> wrote:

> From: Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au>
> Subject: Re: Python and Ruby
> To: python-list at python.org
> Date: Sunday, January 31, 2010, 8:22 PM
> 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?
> 
> 
> 

You pass it a monad (http://en.wikipedia.org/wiki/Monad_(functional_programming)).

    -EdK

Ed Keith
e_d_k at yahoo.com

Blog: edkeith.blogspot.com



      



More information about the Python-list mailing list