i'm trying to build a tree of objects to represent html markup. I think of a method that will build a string in this way:
1. write the open tag to a string in (self 2) defined directly in fuction
2. run this method for each object in the list of objects in the field (self 1)
3. append (self 2) of element in the list to the (self 2) of the object the method is operating on at the moment
4. write the close tag
i get 'list expected' error for both following samples ( second one written to simplify the problem)
Code: Select all
(new Class 'Tag)
(context 'Tag)
(constant 'markup 1)
(constant 'opentag 0)
(constant 'closetag 1)
(constant 'inner 2)
(constant 'v 3)
(define (gen)
(set 's1 "")
(extend s1 (self markup opentag))
(dolist (el (self inner))
(:gen el)
(extend s1 "\n\n" (el Tag:v)))
(extend s1 (self markup closetag))
(setf (self v) s1))
(context MAIN)
(set 't3 (Tag '("<div>" "</div>") '() ""))
(set 't2 (Tag '("<div style=\"position: absolute\">" "</div>") '(t3) ""))
(set 't1 (Tag '("<div style=\"position: relative\">" "</div>") '(t2) ""))
;(push (t2 Tag:inner) t3)
;(push (t1 Tag:inner) t2)
(:gen t1)
(println (t1 Tag:v))
(println t1)
(exit)
Code: Select all
(new Class 'Tag)
(context Tag)
(define (run)
;(set 'l1 (self 1))
;(println (list? (self 1)) " " (self 3) " " l1)
(dolist (el (self 1))
(:run el)
(println (self 2))))
(context MAIN)
(set 't1 (Tag '((Tag '() 1 "a") (Tag '() 2 "b") (Tag '() 3 "c")) 4 "d"))
(:run t1)
(exit)