Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Common Lisp, how to define a macro expanding to nothing (rather than `nil`)?

I want to define a macro which can comment a s-expression, for example:

I hope that

(list 1 2 (comment-macro (something))) -> (1 2)

But if I define the macro like this

(defmacro comment-macro (x))

the result of the above form is actually

(1 2 nil)
like image 637
SaltyEgg Avatar asked Sep 10 '13 14:09

SaltyEgg


2 Answers

You cannot accomplish what you want with a regular macro because its primary value (or nil if no values are returned) will always be used.

However, there are two common options:

  1. comment: #| ... |# - for general text

  2. feature expressions: #+(or) ... or #-(and) ... - for (temporarily?) disabling code

You can also define your own read macros using set-macro-character and set-dispatch-macro-character.

like image 64
sds Avatar answered Sep 18 '22 04:09

sds


In Common Lisp, there is no way to define a macro which expands to nothing. The primary value returned from the macro (i.e. the macro function) is always inserted in place of the macro call.

like image 42
Lars Brinkhoff Avatar answered Sep 21 '22 04:09

Lars Brinkhoff