Guest User

Racket-recursive-list

a guest
Aug 20th, 2026
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.75 KB | None | 0 0
  1. #lang racket
  2.  
  3. (require sxml)
  4.  
  5. (define url "https://example.com")
  6. (define anchor-text "demo")
  7.  
  8. (define new-item `(li (a (@ (href ,url) (target "_blank")) ,anchor-text)))
  9.  
  10. (define (list-template url anchor-text) `(li (a (@ (href ,url) (target "_blank")) ,anchor-text)))
  11.  
  12. (define (nested-map-handler f L)
  13.   (if (list? L)
  14.       (map (lambda (x) (nested-map-handler f x))
  15.            L)
  16.       (f L)))
  17.  
  18. (define (node-logic node)
  19.   (if (and (list? node) (eq? (car node) 'li))
  20.       (list node new-item)
  21.       node
  22.       ))
  23.  
  24. (define template-appended-li (list new-item (list-template "https://fandom.org" "fans universe"))) ; this one is contract error free
  25.  
  26. (display (srl:sxml->html (nested-map-handler node-logic new-item))) ; this one is not error free
Advertisement
Add Comment
Please, Sign In to add comment