Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inside a macro, can I have ,var evaluate to blank/nothing?

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?)

like image 911
nil Avatar asked Feb 02 '26 20:02

nil


1 Answers

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.

like image 148
Xach Avatar answered Feb 04 '26 11:02

Xach