3

I want to define a function that accepts &rest parameters and delegates them to another function.

(html "blah" "foo" baz) => "<html>blahfoobaz</html>"

I did not find a better way than this one:

(defun html (&rest values)
  (concatenate 'string 
               "<html>" 
               (reduce #'(lambda (a b)
                           (concatenate 'string a b))
                       values :initial-value "") 
               "</html>"))

But this looks somewhat glumbsy to me, since line 4 does no more than concatenating the &rest parameter "values". I tried (concatenate 'string "<html>" (values-list values) "</html>") but this does not seem to work (SBCL). Could someone give me an advice?

Kind regards

2 Answers 2

3
(defun html (&rest values) 
  (apply #'concatenate 'string values))
Sign up to request clarification or add additional context in comments.

1 Comment

Please note the question was changed after I gave this answer.
3

In principle, it will not get much better, unless you use format, but you can use the CL-WHO library, which lets you write HTML in Lisp:

(defun hello-page ()
  (with-html-output-to-string (string)
    (:html (:head (:title "Hello, world!"))
           (:body (:h3 "Hello, World!")
                  (:a :href "http://weitz.de/cl-who/"
                      "The CL-WHO library")))))

Edit: The format way should perhaps also be shown:

(defun html (&rest values)
  (format nil "<html>~{~a~}</html>" values))

Comments

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.