3
votes

Thanks to previous answers on common lisp: how can a macro define other methods/macros with programmatically generated names? I have a macro that defines helper functions (actually I have a macrolet, my new favorite lisp-newbie-hammer). But inside this macro, there is something that decides whether the helper functions need to take in a particular argument. So I have an if-statement with nearly identical branches -- down one branch, I place ,var in the lambda list of the generated functions. Down the other branch, I omit ,var. (I'm writing a DSL for non-programmers so I don't want them to see things like &optional)

Is there a way to avoid having basically duplicated code here? If I set var to "", then "" appears in the lambda list of my generated defuns. If I set var to nil, then NIL appears instead.

Is there a value that I can use such that ,var evaluates to absolutely nothing at all, winking out of existence? (And of philosophical interest, shouldn't there be one?)

1

1 Answers

6
votes

One option is to use ,@var and have your value be a list if it should be used, nil if it shouldn't. For example:

(let ((used `((frob 1 2 3)))
      (unused nil))
  `(progn ,@unused ,@used))
=> (PROGN (FROB 1 2 3))

The unused value has disappeared.