Paste number 47425: macro expansion problem

Paste number 47425: macro expansion problem
Pasted by: kiuma
When:1 year, 9 months ago
Share:Tweet this! | http://paste.lisp.org/+10LD
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
(in-package :wo)

(defmacro transform-tag (tagname empty)  
  (let ((tag-symbol 
	 (intern (format nil "~a~a" (string-upcase (eval tagname)) ">")))
	(tag-name (gensym))
	(emptyp (gensym)))
      `(let ((,tag-name ,tagname)
	     (,emptyp ,empty))
	(defun ,tag-symbol (&key attr 
			   ,@(when `(null ,emptyp)
				   `(body)))
	 (make-instance 'tag 
			:tagname ,tag-name
			:empty ,emptyp
			:attr attr
			,@(when `(null ,emptyp)
				`(:body body)))))))

------------------------------------------------

WO> (macroexpand '(transform-tag "pippo" t))
(LET ((#:G2052 "pippo") (#:G2053 T))
  (DEFUN PIPPO> (&KEY ATTR BODY)
    (MAKE-INSTANCE 'TAG :TAGNAME #:G2052 :EMPTY #:G2053 :ATTR ATTR :BODY BODY)))


That it's what I expect! Then I try to put this in a function with a dolist:

(defun generate-tags (empty &rest body)
  ;Each string is concatenated to '>', so for example the exported symbol   
  ;for string "div" will be div>. Then for each of this symbol a function
  ;that creates an instance of etag class is defined
  (dolist (tag body)    
       (transform-tag tag empty)))

but I don't understand compiler error messages. What's wrong now ?
------------------------------------------------------------
; compiling file "/tmp/fileIxP4Ez.lisp" (written 08 SEP 2007 07:57:14 PM):

; file: /tmp/fileIxP4Ez.lisp
; in: DEFUN GENERATE-TAGS
;     (CL-WEBOBJECTS::TRANSFORM-TAG CL-WEBOBJECTS:TAG CL-WEBOBJECTS::EMPTY)
; 
; caught ERROR:
;   (in macroexpansion of (TRANSFORM-TAG TAG EMPTY))
;   (hint: For more precise location, try *BREAK-ON-SIGNALS*.)
;   The variable TAG is unbound.

;     (DEFUN CL-WEBOBJECTS:GENERATE-TAGS
;          (CL-WEBOBJECTS::EMPTY &REST CL-WEBOBJECTS::BODY)
;     (DOLIST (CL-WEBOBJECTS:TAG CL-WEBOBJECTS::BODY)
;       (CL-WEBOBJECTS::TRANSFORM-TAG CL-WEBOBJECTS:TAG CL-WEBOBJECTS::EMPTY)))
; --> PROGN EVAL-WHEN 
; ==>
;   (SB-IMPL::%DEFUN 'CL-WEBOBJECTS:GENERATE-TAGS
;                    (SB-INT:NAMED-LAMBDA CL-WEBOBJECTS:GENERATE-TAGS
;                                         (CL-WEBOBJECTS::EMPTY &REST
;                                          CL-WEBOBJECTS::BODY)
;                                         (BLOCK CL-WEBOBJECTS:GENERATE-TAGS
;                                           (DOLIST
;                                               (CL-WEBOBJECTS:TAG
;                                                CL-WEBOBJECTS::BODY)
;                                             (CL-WEBOBJECTS::TRANSFORM-TAG
;                                              CL-WEBOBJECTS:TAG
;                                              CL-WEBOBJECTS::EMPTY))))
;                    NIL 'NIL (SB-C:SOURCE-LOCATION))
; 
; caught STYLE-WARNING:
;   The variable EMPTY is defined but never used.

;     (DOLIST (CL-WEBOBJECTS:TAG CL-WEBOBJECTS::BODY)
;     (CL-WEBOBJECTS::TRANSFORM-TAG CL-WEBOBJECTS:TAG CL-WEBOBJECTS::EMPTY))
; --> BLOCK LET TAGBODY UNLESS COND IF PROGN 
; ==>
;   (LET ((CL-WEBOBJECTS:TAG (CAR #:N-LIST0)))
;     (SETQ #:N-LIST0 (CDR #:N-LIST0))
;     (TAGBODY
;       (CL-WEBOBJECTS::TRANSFORM-TAG CL-WEBOBJECTS:TAG CL-WEBOBJECTS::EMPTY)))
; 
; caught STYLE-WARNING:
;   The variable TAG is defined but never used.

; /tmp/fileIxP4Ez.fasl written
; compilation finished in 0:00:00
; 
; compilation unit finished
;   caught 1 ERROR condition
;   caught 2 STYLE-WARNING conditions
STYLE-WARNING: redefining GENERATE-TAGS in DEFUN

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.