I’ve been working through Practical Common Lisp and as an exercise decided to write a macro to determine if a number is a multiple of another number:
(defmacro multp (value factor)
`(= (rem ,value ,factor) 0))
so that : (multp 40 10) evaluates to true whilst (multp 40 13) does not
The question is does this macro leak in some way? Also is this ‘good’ Lisp? Is there already an existing function/macro that I could have used?
Siebel gives an extensive rundown (for simple cases anyway) of possible sources of leaks, and there aren’t any of those here. Both
valueandfactorare evaluated only once and in order, andremdoesn’t have any side effects.This is not good Lisp though, because there’s no reason to use a macro in this case. A function
is identical for all practical purposes. (Note the use of
zerop. I think it makes things clearer in this case, but in cases where you need to highlight, that the value you’re testing might still be meaningful if it’s something other then zero,(= ... 0)might be better)