(defmacro for
((param-name start-value end-value &optional (step1 1)) &body body)
(let* ((func-name (gensym))
(comp (gensym))
(comparison (if (< step1 0) '<= '>=))
(start (gensym))
(end (gensym))
(step (gensym))
(k (gensym)))
`(let ((,start ,start-value)
(,comp ,comparison)
(,end ,end-value)
(,step ,step1))
(labels ((,func-name (,param-name ,k)
(if (,comparison ,end ,param-name)
(progn (progn ,@body)
(,func-name (+ ,param-name ,step)
(1+ ,k)) ,k))))
(,func-name ,start 1)))))
Do you know how can I close leak with comparison? When I am trying to bound comp to evaluated operator of comparison I receive error.
(defmacro for
((param-name start-value end-value &optional (step1 1)) &body body)
(let* ((func-name (gensym))
(comp (gensym))
(comparison (if (< step1 0) '<= '>=))
(start (gensym))
(end (gensym))
(step (gensym))
(k (gensym)))
`(let ((,start ,start-value)
(,comp ,comparison)
(,end ,end-value)
(,step ,step1))
(labels ((,func-name (,param-name ,k)
(if (,comp ,end ,param-name)
(progn (progn ,@body)
(,func-name (+ ,param-name ,step)
(1+ ,k)) ) ,k)))
(,func-name ,start 0)))))
Sorry man. I kinda fixed the issue. When I am trying to call macros, it return me error
; compilation unit finished
; Undefined functions:
; #:G1 #:G7
; Undefined variable:
; >=
I don’t know how to deal with bounding <= or >= to generated variable.