The link extraction functions. | Lecture 3 - slide 19 : 42 Program 1 |
; Return a list of URLS as located in the a elements of ast. (define (extract-links ast) (if (ast? ast) (let ((name (ast-element-name ast)) (subtrees (ast-subtrees ast)) ) (if (equal? name "a") (let ((href-attr-value (find-href-attribute (ast-attributes ast)))) (if href-attr-value (list href-attr-value) '())) (extract-links-ast-list subtrees))) '())) ; Return a list of URLS as located in the a elements of ; the list of ast's as passed in ast-list. (define (extract-links-ast-list ast-list) (if (null? ast-list) '() (append (extract-links (car ast-list)) (extract-links-ast-list (cdr ast-list)))))