From: Pascal J. Bourguignon
Subject: Re: a simple htm creator
Date: 
Message-ID: <7ck5k5o3cj.fsf@pbourguignon.anevia.com>
········@yahoo.es writes:

> (defparameter  *tags* '(html head title body form table tr td a img h1
> h2 h3 h4 h5 h6 h7))
>
> (defun lector(l) (mapc #'lee l) *s*)
>
> (defun lee(x)
> 	(cond ( (listp x) (if (member (car x) *tags*) (f x) (g x)))
> 		(t (with-output-to-string (s *s*)
> 			(format s "~A " x)))))
>
> (defun f(x)
> 	(let ( (u (symbol-name (car x))))
> 	(with-output-to-string (s *s*)
> 		(format s "<~A>" (car x)) (lector (cdr x)) (format s "</~A>" (car
> x)))))
>
> (defun g(x)
> 	(lector (list (eval x))))
>
> (defun to-htm(x)
> 	(setq *s* (make-array '(100) :element-type 'base-char :adjustable
> t :fill-pointer 0))
> 	(lector x))
>
>
> (defun row (&rest l) (cons 'tr (mapcar (lambda(x) (list 'td x)) l)))
>
>
> ;; an example
> (to-htm '((html (head (title Hello) )
>  (body (h1 Hello) <br>
>  My name is Lucas
>  (table (row 1 2 3) (row 4 5 6))))))


Welcome!  ;-)



However, if you want to generate the HTML with the same case, you'd need to write:

(to-htm '((html (head (title "Hello") )
 (body (h1 "Hello") <br>
 "My name is Lucas"
 (table (row 1 2 3) (row 4 5 6))))))


or to set the readtable-case to preserve, and write:

(|SETF| (|READTABLE-CASE| |*READTABLE*|) :|PRESERVE|)
(TO-HTM '((HTML (HEAD (TITLE Hello) )
 (BODY (H1 Hello) <BR>
 My name is Lucas
 (TABLE (ROW 1 2 3) (ROW 4 5 6))))))
(|SETF| (|READTABLE-CASE| |*READTABLE*|) :|UPCASE|) ; go back to standard



There's anothor problem liked to your use of EVAL:

C/USER1[206]> (defun fact (x) (if (< x 1) 1 (* x (fact (1- x)))))
FACT
C/USER1[207]> (pushnew 'p *tags*)
(P HTML HEAD TITLE BODY FORM TABLE TR TD A IMG H1 H2 H3 H4 H5 H6 H7)
C/USER1[208]> (to-htm '((html (head (title Bug))
                              (body (h1 Factorial)
                                    (p 10! = (fact 10))))))
"<HTML><HEAD><TITLE>BUG </TITLE></HEAD><BODY><H1>FACTORIAL </H1><P>10! = 3628800 </P></BODY></HTML>"
C/USER1[209]> (let ((x 10)) 
                (to-htm '((html (head (title Bug))
                                (body (h1 Factorial)
                                      (p x! = (fact x)))))))

*** - EVAL: variable X has no value
The following restarts are available:
USE-VALUE      :R1      You may input a value to be used instead of X.
STORE-VALUE    :R2      You may input a new value for X.
ABORT          :R3      ABORT
C/Break 1 USER1[210]> 

If you solved this (avoiding the use of EVAL), you'd get a better HTML creator.
(and you'd learn some more about Common Lisp).

-- 
__Pascal Bourguignon__