My first Lisp macro; is it leaky? -


i've been working through practical common lisp , exercise decided write macro determine if number multiple of number:

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

so : (multp 40 10) evaluates true whilst (multp 40 13) not

the question macro leak in way? "good" lisp? there existing function/macro have used?

siebel gives extensive rundown (for simple cases anyway) of possible sources of leaks, , there aren't of here. both value , factor evaluated once , in order, , rem doesn't have side effects.

this not lisp though, because there's no reason use macro in case. function

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

is identical practical purposes. (note use of zerop. think makes things clearer in case, in cases need highlight, value you're testing might still meaningful if it's other zero, (= ... 0) might better)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -