[racket] Can you avoid voids in quasiquote?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Jan 28 14:26:24 EST 2014

I tend to use ,@ (splice) like this: 

`(p "foo" "bar" ,@(@when test-condition (do-something)))

where 

(define-syntax-rule (@when tst body) (if tst (list body) '()))


On Jan 28, 2014, at 2:20 PM, Matthew Butterick <mb at mbtype.com> wrote:

> I frequently write quasiquoted xexprs that contain this kind of pattern:
> 
> `(p "foo" "bar" ,(when test-condition (do-something)))
> 
> When test-condition is #f, I get:
> 
> '(p "foo" "bar" #<void>)
> 
> Which is wrong. What I wanted was:
> 
> '(p "foo" "bar")
> 
> I can fix it by doing this:
> 
> (filter-not void? `(p "foo" "bar" ,(when test-condition (do-something))))
> 
> Is this the best way? Or is there a cleverer way to make the nested expression completely disappear?
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.