2010-04-13 5 views
3

&rest 매개 변수를 받아들이고 다른 함수에 위임하는 함수를 정의하고 싶습니다.일반적인 lisp의 & rest-parameters 다루기

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

나는 이것보다 더 좋은 방법은 찾지 못했습니다 :

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

을하지만 라인 4는 & 나머지 매개 변수 "값"을 합치보다는 더 이상하지 않습니다 때문에이 나에게 다소 glumbsy 보인다. (concatenate 'string "<html>" (values-list values) "</html>") 시도했지만이 작동하지 않는 것 (SBCL). 누군가 내게 조언을 줄 수 있습니까?

종류는 format을 사용하지 않는

원칙적으로

답변

3
(defun html (&rest values) 
    (apply #'concatenate 'string values)) 
+0

P 또한 표시해야합니다. 리스 노트는이 대답을 한 후에 변경되었습니다. –

3

, 그것은 훨씬 더받지 않습니다 간주,하지만 당신은 당신이 리스프에서 HTML 쓰기 할 수있는 CL-WHO 라이브러리를 사용할 수 있습니다

 
(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"))))) 

편집 :

+1

CL-WHO를 가리키는 유머러스하고리스 피한 방식의 +1 :-) –