[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:

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

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

Substituting an 
(if condition
    then-branch
    empty) 
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. 

Thanks,
Jordan






Posted on the users mailing list.