Python's Lisp heritage

Jacek Generowicz jacek.generowicz at cern.ch
Sat Apr 27 12:57:10 EDT 2002


"Brian Quinlan" <brian at sweetapp.com> writes:

> Jacek wrote: 
> > My example was indended to disabuse James of the notion that
> > parentheses are used in lisp "around sub expressions".
> 
> How would you convert the following Python expression to Lisp?
> 
> sin(x/2 + y/2)

#i(sin(x/2 + y/2))

I'm guessing that you want me to answer (sin (/ (+ x y) 2)) so that
you can then triumphantly point out that this is putting parentheses
around sub expressions. But then you would be confusing the appearance
with the purpose. (I already acknowledged in my original followup to
James, that in mathematical expressions function calls and
sub-expressions coincide rather frequently.)

The purpose of the parentheses (in this context) is to call functions
and associate parameters with those function calls. Python has a not
too dissimilar use of parentheses:

  sin(operator.div(operator.add(x,y),2))

Oh look, exactly the same number of parentheses!

What? you object to my obtuse avoidance of Python's nifty infix
synonyms for these operators which cunningly call the functions
without recourse to parentheses?  In that case you surely allow me to
object to obtuse avoidance of such possibilities in Lisp.

In summary, a pair of parentheses is necessary to call functions in
both Python and Lisp, though there are ways of getting around this
requirement in both languages: Python provides a set of infix
operators which call a subset of the mathematical functions; there are
Lisp macros which provide very similar functionality.


Rhetorical question:

  Imagine you use the splark function so often in your expressions
  that you would really like to extend the set of infix operators,
  with say @, to allow you to call splark without having to type those
  infernal parentheses. Is it going to be easier in Python or in Lisp?

  Another one liner, right?



More information about the Python-list mailing list