Approximate overview
Token Events
Other good things
Why do we map the procedure over the tree, rather than using remove-spaces
directly on the list?
(define remove-spaces
(lambda (val)
(cond
[(string? val)
(string-replace val " " "")]
[else
val])))
Could you change the colors?
Yes, but I will do so later.
Reminder: It’s new, there will be issues.
How many things will go wrong?
A lot!
(define no-comment
(lambda (xml)
(cond
[(string? xml)
xml]
[(pair? xml)
(cond
[(eq? (car xml) '@)
xml]
[(eq? (car xml) 'q)
; Special case if we see an attribute after the 'q
; The thing after the q (cadr) uses an @
; (q (@ ...) ....) -> (q (@ ...) "No comment.")
(if (and (pair? (cadr xml))
(equal? (caadr xml) '@))
(list 'q (cadr xml) "No comment.")
'(q "No comment."))]
[else
(map no-comment xml)])]
[else
xml])))
(define off-with-their-heads
(lambda (xml)
(cond
[(string? xml)
xml]
[(pair? xml)
(cond
[(eq? (car xml) '@)
xml]
[(eq? (car xml) 'q)
; Special case if we see an attribute after the 'q
; The thing after the q (cadr) uses an @
; (q (@ ...) ....) -> (q (@ ...) "No comment.")
(if (and (pair? (cadr xml))
(equal? (caadr xml) '@)
(class-is-red-queen? (cdadr xml)))
(list 'q (cadr xml) "Off with their heads!")
xml)]
[else
(map off-with-their-heads xml)])]
[else
xml])))
; Given an attribute list, determine whether any of the attributes
; is a class attribute with a value that includes "redqueen".
; Attributes likely has the form
; `((attribute value) (attribute value) (attribute value) ...)`.
(define class-is-red-queen?
(lambda (attributes)
(cond
[(null? attributes)
#f]
[(and (pair? (car attributes))
(equal? (caar attributes) 'class)
(index-of (string-split (cadar attributes)) "redqueen" ))
#t]
[else
(class-is-red-queen? (cdr attributes))])))