The end to all language wars and the great unity API to come!

Teemu Likonen tlikonen at iki.fi
Wed Jul 6 12:55:53 EDT 2011


* 2011-07-06T06:41:52-07:00 * <rantingrick at gmail.com> wrote:

> I am using a user defined spec as an argument to the cmp function.
> That spec then modifies the body of the compare function and creates a
> user defined control structure. You can argue all day that it is not a
> user defined control structure but no one is going to believe you.

I won't argue all day, I'll just show you an example of a user defined
control structure. This is like the standard (DOTIMES (VAR COUNT) BODY)
macro expect that it executes BODY forms first forwards and then
backwards. The iterator variable VAR goes first up from 0 and then down
to 0.


(defmacro ping-pong-iterator ((var count &optional result)
                              &body body)
  `(progn (loop for ,var from 0 below ,count
                do (progn , at body))
          (loop for ,var from (1- ,count) downto 0
                do (progn ,@(reverse body))
                finally (return ,result))))


CL-USER> (ping-pong-iterator (i 3 "ready")
           (format t "form 1: ~A~%" i)
           (format t "form 2: ~A~%" i)
           (format t "form 3: ~A~%" i)
           (format t "~%"))
form 1: 0
form 2: 0
form 3: 0

form 1: 1
form 2: 1
form 3: 1

form 1: 2
form 2: 2
form 3: 2


form 3: 2
form 2: 2
form 1: 2

form 3: 1
form 2: 1
form 1: 1

form 3: 0
form 2: 0
form 1: 0
=> "ready"



More information about the Python-list mailing list