1

I am messing around with web development and would like to do something like the following:

(defun col1 (&rest content) `((:DIV :CLASS "col1") 
                              (:COMMENT " Column 1 start ")
                              ,content goes here
                              (:COMMENT " Column 1 end ")))

where content is two or more lists returned by a function:

(defun two-list () ....)

that would return

'(:H2 "header")
'(:P "paragraph")

so that

(col1 (two-list))

would return

((:DIV :CLASS "col1") 
 (:COMMENT " Column 1 start ")
 (:H2 "header")
 (:P "paragraph")
 (:COMMENT " Column 1 end "))    

I've tried using the values function, but it only seems to embed one list into the content area. Is it possible to do something like this? Thanks for the help lispers, I'm having a great time learning how to Lisp!

2
  • While this isn't an answer to your particular programming question, and questions asking for tools are off topic for StackOverflow, if you're going to be doing HTML generation based on s-expressions, you might be interested in taking a look at CL-WHO, or some of the other Lisp markup language out there. Commented Sep 11, 2013 at 12:36
  • Yeah, I've been using some cl-who, but mostly lml2 and cl-html-parse. Commented Sep 12, 2013 at 3:05

1 Answer 1

4

How about two-list returns a list of elements you want to embed, like ((:H2 "header")(:P "paragraph")), then col1 could be defined as:

(defun col1 (content) `((:DIV :CLASS "col1") 
                              (:COMMENT " Column 1 start ")
                              ,@content ; goes here
                              (:COMMENT " Column 1 end ")))

(defun two-list () '((:H2 "header")(:P "paragraph")))

Notice that I removed the &rest from col1. If you want to still have that you need to do (apply #'col1 (two-list)) instead of (col1 (two-list))

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that did it. Your second solution works perfectly for me since I'd like to be able to add a bunch of stuff to the content area. Now off to read more about the @ symbol...
@gaauto If Sylwester's answer works for you (and your comment indicates that it did), you should accept the answer to let others know that it worked for you.
If you look for documentation on an @ symbol you might have trouble finding it; the @ character has this particular meaning only in the context of the backquote and comma. lispworks.com/documentation/HyperSpec/Body/02_df.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.