[racket] View HTML source code in racket
On Jun 23, Greg Hendershott wrote:
>
> (define (find-elements xexpr tag-name)
> ;; Given an x-expression return a list of all the elements starting
> with tag-name.
> (if (empty? xexpr)
> '()
> (let ([x (first xexpr)])
> (if (and (list? x) (not (empty? x)))
> (if (and (symbol? (first x)) (symbol=? (first x) tag-name))
> (append (list x) ; found one!
> (find-elements x tag-name) ; drill down
> (find-elements (rest xexpr) tag-name)) ; iterate across
> (append (find-elements x tag-name) ; drill down
> (find-elements (rest xexpr) tag-name))) ; iterate across
> (find-elements (rest xexpr) tag-name))))) ; iterate across
`match' is more convenient for such things:
(define (find-links xexpr)
(match xexpr
[(list 'a _ ...) (list xexpr)]
[(list xs ...) (append* (map find-links xs))]
[_ '()]))
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!