[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiling a recursive macro

From: Douglas Lewan
Subject: Re: Compiling a recursive macro
Date: Thu, 11 Jun 2020 22:10:19 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

I managed to lose the last response to my original question, the one with the case_ macro. Here it is for reference:

(defmacro case_ (val &rest list)
  "(case value
        ((<items>) result1)
        ((<items>) result2)
        [else result3])

   Macro for switch case statement. It test if value is any of the item. If
   item match the value it will return coresponding result expression value.
   If no value match and there is else it will return that result."
  (if (listp list)
      (let* ((item (car list))
             (first (car item))
             (result (cadr item))
             (rest (cdr list))
             (value (gensym)))
        `(let ((,value ,val))
           (if (member ,value ',first)
             ,(if (and (listp rest)
                       (eq (caar rest) 'else))
                (if (not (null rest))
                    `(case_ ,value ,@rest))))))

I did, however, manage to save the macro and, indeed, it compiles without the max-depth-exceeded. There's an insightful difference from what I was attempting: Instead of invoking the macro directly, here the recursive call is inside a back-tick.

Sorry to have lost the mail. My keyboard stutters on occasion and I'm guessing I wound up doing something distructive twice. The point is that I'd like to thank that author.

(908) 720 7908

If this is what winning looks like, I'd hate to see what losing is.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]