[racket] #<void> in xexpr

From: Jordan Schatz (jordan at noionlabs.com)
Date: Sat Dec 10 01:12:10 EST 2011

I think thats there must be a "lisp" way of doing this, but I'm still too
new to see how. Anyone care to enlighten me?

I'm trying to create a function that produces an xexpr:

(define (custom-input name
                      #:class [class "xlarge"]
                      #:id [id #f]
                      #:size [size 30]
                      #:type [type "text"]
                      #:placeholder [placeholder #f]
                      #:autofocus [autofocus #f]
                      #:label [label #f])
  `(div ((class "clearfix"))
        ,(if label
           `(label ((for ,name)) ,name)
        (div ((class "input"))
             (input ((name ,name) (class ,class)  
                     (size ,(number->string size)) (type ,type)
                     ,(if id
                          `(id ,id)
                          `(id ,name))
                     ,(when placeholder
                        `(placeholder ,placeholder))
                     ,(when autofocus
                          '(autofocus "autofocus")))))))

But using "when" produces #<void> like so:

 (custom-input "Company"
               #:label #t
               #:placeholder "Your company name (optional)"))

 > Expected a symbol as the element name, given (name "Company")

Substituting an 
(if condition
for the "when" also produces an invalid xexpr, though I'd rather not use
if and have an else branch unless I really wanted it to be there. 


Posted on the users mailing list.