My first Lisp macro; is it leaking?

I worked through Practical General Lisp , and as an exercise, it was decided to write a macro to determine if a number is several other numbers:

(defmacro multp (value factor)
`(= (rem ,value ,factor) 0))

so that: (multp 40 10) evaluates to true while (multp 40 13) not

The question is, how is this macro leak ? Also this "good" Lisp? Is there an existing function / macro that I could use?

+5
source share
4 answers

Siebel ( ) , . value, factor , rem .

Lisp, .

(defun multp (value factor)
  (zerop (rem value factor)))

. ( zerop. , , , , - , - , , (= ... 0) )

+11

. , , - gensyms. "" Lisp, , , , . , , .

+2

, , :

(flet ((= (&rest args) nil))
  (multp 40 10))

NIL... , ANSI CL , CL: =, .

, , ( , ), ( ).

+1

, , , " " .

, , . , , , , , :

(defmacro ana-and (&rest forms)
  (loop for form in (reverse forms)
        for completion = form then `(let ((it ,form))
                                      (when it
                                       ,completion))
        finally (return completion)))

" " , , , ( , NIL). , , cobbled-together-, , .

0
source

All Articles