What can you do in LISP that you can't do in Python

Nonexistence huaiyuan at rac3.wam.umd.edu
Mon May 14 23:52:03 EDT 2001


"Richard P. Muller" <rpm at wag.caltech.edu> writes:

> I read Paul Graham's excellent article
> (http://www.paulgraham.com/paulgraham/avg.html) on using LISP to write
> what became the Yahoo!Stores website. One of the central points is that
> there are some things (macros) that you can do in LISP that you can't do
> in other languages. 

Be careful here.  The author made no such (strong) claim.  

> This motivated me to learn a bit about LISP. I chose
> the Scheme dialect, because it seemed to have the best documentation
> available for free. 

Try http://www.lisp.org.

I found these documents helpful (in increasing level of formality):

  http://psg.com/~dlamkins/sl/cover.html
  http://ringer.cs.utsa.edu/research/AI/cltl/cltl2.html
  http://www.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/FrontMatter/index.html

> However, thus far I can't see anything that I could do in Scheme that I
> couldn't do in Python. From the thread on LISP I've seen a lot of
> comments that have suggested that I should have started with Common Lisp
> instead of Scheme -- so maybe that's the problem. But can someone give
> me a short example of something that I can do in LISP that I couldn't do
> in Python?
> 
> Don't get me wrong: I like Scheme -- it's a very elegant language. But
> thus far I haven't seen the big "Aha!".

You may want to checkout "Accelerating Hindsight: Lisp as a Vehicle for
Rapid Prototyping" (http://world.std.com/~pitman/PS/Hindsight.html) by Kent
Pitman.  In particular, regarding macro: 

  Macros can be a real boon to rapid prototyping.  Few things in code are as
  tedious as the needless repetition of a clumsy idiom throughout a large
  body of code.  It is as painful to type in originally as it is distracting
  to later read.  It is also error-prone.  Consider the following code
  fragment, which might be part of a state machine that optionally keeps a
  history of its prior states for debugging purposes:
  
  (IF TRACING
      (PUSH (CONS STATE (COPY-LIST REGISTERS))
            STATE-HISTORY))
  (GO STATE-17)
  
  Writing such code over and over bloats the source text needlessly, and
  replicates dependence on the representation of the state and the
  registers making it hard to experiment with alternatives.  A better
  approach would be to write a macro definition such as:
  
  (DEFMACRO NEW-STATE (TAG)
      `(PROGN (IF TRACING 
                  (PUSH (CONS STATE (COPY-LIST REGISTERS))
                        STATE-HISTORY))
              (GO ,TAG)))
  
  Given this, one could do a state transition to STATE-17 by merely
  writing:
  
  (NEW-STATE STATE-17)
  
  Also, because Lisp macros use structured objects and not textual
  substitution, macros like this are more reliable than macros in most
  other languages.  This permits more complex uses of macros without
  diminished robustness that heavily cascaded textual macros might produce.




More information about the Python-list mailing list