, takes an expression and puts it in directly<div><br></div><div>`(something ,(list 1 2 3) else) ===> '(something (1 2 3) else)</div><div><br></div><div>,@ takes an expression that evaluates to a list and "splices" it in place</div>
<div><br></div><div>`(something ,@(list 1 2 3) else) ===> '(something 1 2 3 else)</div><div><br></div><div>I typically do something like</div><div><br></div><div>`(something ,@(if condition (list answer) empty) else)</div>
<div><br></div><div>and even may make a macro out of it</div><div><br></div><div>(define-syntax-rule (when-xexpr cond expr)</div><div> (if cond (list expr) empty))</div><div><br></div><div>Jay<br><br><div class="gmail_quote">
On Fri, Dec 9, 2011 at 11:12 PM, Jordan Schatz <span dir="ltr"><<a href="mailto:jordan@noionlabs.com">jordan@noionlabs.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I think thats there must be a "lisp" way of doing this, but I'm still too<br>
new to see how. Anyone care to enlighten me?<br>
<br>
I'm trying to create a function that produces an xexpr:<br>
<br>
(define (custom-input name<br>
#:class [class "xlarge"]<br>
#:id [id #f]<br>
#:size [size 30]<br>
#:type [type "text"]<br>
#:placeholder [placeholder #f]<br>
#:autofocus [autofocus #f]<br>
#:label [label #f])<br>
`(div ((class "clearfix"))<br>
,(if label<br>
`(label ((for ,name)) ,name)<br>
'())<br>
(div ((class "input"))<br>
(input ((name ,name) (class ,class)<br>
(size ,(number->string size)) (type ,type)<br>
,(if id<br>
`(id ,id)<br>
`(id ,name))<br>
,(when placeholder<br>
`(placeholder ,placeholder))<br>
,(when autofocus<br>
'(autofocus "autofocus")))))))<br>
<br>
But using "when" produces #<void> like so:<br>
<br>
(validate-xexpr<br>
(custom-input "Company"<br>
#:label #t<br>
#:placeholder "Your company name (optional)"))<br>
<br>
> Expected a symbol as the element name, given (name "Company")<br>
<br>
Substituting an<br>
(if condition<br>
then-branch<br>
empty)<br>
for the "when" also produces an invalid xexpr, though I'd rather not use<br>
if and have an else branch unless I really wanted it to be there.<br>
<br>
Thanks,<br>
Jordan<br>
<br>
<br>
<br>
<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://lists.racket-lang.org/listinfo/users" target="_blank">http://lists.racket-lang.org/listinfo/users</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Jay McCarthy <<a href="mailto:jay@cs.byu.edu" target="_blank">jay@cs.byu.edu</a>><br>Assistant Professor / Brigham Young University<br><a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>"The glory of God is Intelligence" - D&C 93<br>
</div>