Sharing & rest-parameters lisp

I want to define a function that takes parameters &restand delegates them to another function.

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

I have not found a better way than this:

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

But it looks a little dazzling to me, since line 4 does nothing more than concatenating the "values" of the parameter "amp; rest". I tried (concatenate 'string "<html>" (values-list values) "</html>"), but it does not work (SBCL). Can anyone give me some advice?

Yours faithfully

+3
source share
2 answers
(defun html (&rest values) 
  (apply #'concatenate 'string values))
+3
source

Basically, this will not improve if you are not using it format, but you can use CL-WHO , which allows you to 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")))))

: , format:

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

Source: https://habr.com/ru/post/1741005/


All Articles