Python execution speed

Marco Antoniotti marcoxa at cs.nyu.edu
Tue Nov 20 22:35:50 CET 2001


"Morten W. Petersen" <morten at thingamy.net> writes:

> On Tue, 20 Nov 2001, Sandy Norton wrote:
> 
> > "Morten W. Petersen" <morten at thingamy.net> wrote in message
> > news:Pine.LNX.4.21.0111201815190.6229-100000 at bcryachts.atsat.com...
> > 
> > > One of Python's advantages is a consistent (simple) design, (not counting
> > > small quirks like 'def function(): return 1' and 'function =
> > > lambda: 1'.  Consistent design says 'less complexity' in my ears, along
> > > the same lines of the simpleness (ease of maintenance, readability,
> > > portability) of a python application if it can always be coded in Python.
> > 
> > Excuse my curiosity but what's quirky about 'def function(): return 1' and
> > 'function =
> > lambda: 1'?
> 
> (I'm posting to the newsgroup as well, didn't notice you posted to
>  both the newsgroup and me.)
> 
> Curiosity is good.  :-)
> 
> In Lisp, functions can be built this way:
> 
>   cl-user(3): (defun multiply (argument) (* argument argument))
>   multiply
>   cl-user(4): (multiply 3)
>   9
>   cl-user(5):
> 
> Where the last evaluated value is returned.
> 
> In Python, there is:
> 
>   def multiply(argument):
>       return argument * argument
> 
> Or (using anonymous functions):
> 
>   multiply = lambda argument: argument * argument
> 
> Where the lambda has the implicit return-of-last-expression (no return
> needed), while functions do not.

In Common Lisp the last expression of an execution thread is the one
returned.  The macro `return' and the special operator `return-from'
are usable for non-local exits.

As per the above example

You can do

cl-prompt> (defun multiply (n1 &rest ns)
              (apply '* n1 ns))
multiply
cl-prompt> (multiply 1 2 3 4)
24

And you can do

cl-prompt> (defvar multiply (lambda (n1 &rest ns)
                                (apply '* n1 ns)))
multiply

Same story (well almost :) ).

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.



More information about the Python-list mailing list