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

Terry Reedy reedy37 at home.com
Tue May 15 12:08:53 EDT 2001


"Nonexistence" <huaiyuan at rac3.wam.umd.edu> wrote in message
news:c6x1yprz2u4.fsf at rac3.wam.umd.edu...

...
>  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)

What I know about Lisp macros is what I have gleaned from this thread,
which isn't too much yet.  How is the above different from writing and
calling a function.  IE

def new_state(tag):
  if tracing: store_tracing_info()
  goto(tag)

new_state(tag)

TJ Reedy






More information about the Python-list mailing list