Advertisement
Guest User

Untitled

a guest
Apr 29th, 2020
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.00 KB | None | 0 0
  1. (use-modules (srfi srfi-1) (ice-9 match) (sxml simple))
  2.  
  3. (define top-id "top-id")
  4.  
  5. (define (print-enum id nicks)
  6.   (display
  7.     (string-append
  8.       "  <enum id=\"" top-id "." id "-enum\">\n"))
  9.   (fold
  10.     (lambda (nick idx)
  11.       (format #t
  12.         "    <value nick=\"~a\" value=\"~d\"/>\n"
  13.         nick idx)
  14.       (1+ idx))
  15.     0
  16.     nicks)
  17.   (display "  </enum>\n"))
  18.  
  19. (define (print-enum1 id nicks)
  20.   (let* ((top-id (string-append top-id "." id "-enum"))
  21.          (nicks (let lp ((nicks nicks) (idx 0) (res '()))
  22.                   (match nicks
  23.                    (() (reverse res))
  24.                    ((nick . rest) (lp rest (1+ idx)
  25.                                       (cons `(value (@ (nick ,nick)
  26.                                                        (value ,idx)))
  27.                                             res))))))
  28.          (sxml `(enum (@ (id ,top-id)) ,nicks)))
  29.     (display (sxml->xml sxml))))
  30.  
  31. (newline)
  32. (print-enum "a" '("a" "b" "c"))
  33. (print-enum1 "a" '("a" "b" "c"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement