This is the "am I missing something obvious?" kind of question.
I would like to use backquotes in some way to make a value appear in a list only if it's not nil. So, for instance, given x, get '(1 2 3) if x is 2 and '(1 3) if x is nil. The following form will do the trick, but it looks convoluted:
`(1 ,@(if x (list x)) 3)
How can I do this another way, e.g., one that looks simpler? Obviously, I'm not interested in a solution using list functions.
xis unbound, you will get an error. Did you want to catch that case or isxalways bound to something? Fundamentally, however, I don't think there is a simpler way to write it (although I'm a pedestrian Lisper, so YMMV). – NickD Jan 15 '21 at 16:01xwill be bound. The code snippet would be in the body of a function,xan argument. – Augusto Jan 15 '21 at 16:11andinstead ofif(as I think it's clearer). And I sometimes use a quoted list instead of invokinglist(e.g. when there's no risk of modifying list structure). I know of nothing clearer, but perhaps someone will post something. To me, this is just an idiom to learn, use, and recognize. IOW, my answer to your question of missing something obvious is no, not that I'm aware of. – Drew Jan 15 '21 at 18:30andin this case iswhenwhich some like better.andis also an idiom to learn, when you remember it evaluates to the last item when everything is true. I also don't know of another more obvious way to do it. – John Kitchin Jan 15 '21 at 21:06