• 1 Post
  • 8 Comments
Joined 1 year ago
cake
Cake day: November 24th, 2023

help-circle
  • Revolutionary_Utena@alien.topOPBtoLispConstructing a macro 'for'
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

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


  • Revolutionary_Utena@alien.topOPBtoLispConstructing a macro 'for'
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

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




  • Revolutionary_Utena@alien.topOPBtoLispConstructing a macro 'for'
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago
    (defmacro for ((param start-value end-value &amp;optional (step1 1)) &amp;body body)
      (let* ((func-name (gensym))
             (start (gensym))
             (param-name (gensym))
             (comparison (if (&lt; step1 0) '&lt; '>))
             (end (gensym))
             (step (gensym))
             (k (gensym)))
        `(let ((,end ,end-value)
               (,step ,step1)
               (,start ,start-value))
          (labels ((,func-name (,param-name ,k)
                       (let ((new-exprs (progn ,@body))
                             (newK (+ 1 ,k)))
                         (if (,comparison ,end ,param-name)
                             (,func-name (+ ,param-name ,step) newK)
                             newK))))
             (,func-name ,param 0)))))
    
    (let ((s 0))
    (for (i 2 5)
    (incf s (sin i)))
    s)
    

    I made some changes but when I try to call macros with parameter (i 2 5) compiler give me error about unbound variable i.