(import scheme (chicken base) (chicken format) (chicken string) (chicken condition) ) (import libyaml) (let* ( (yaml ((yaml<-))) (~S (lambda (?) (sprintf "~S" ?))) (and* (lambda (L) (foldl (lambda (l r) (and l r)) #t L))) (or* (lambda (L) (foldl (lambda (l r) (or l r)) #f L))) (string+ (lambda (str . ..) (apply string-append (map ->string (cons str ..))) )) (assoc* (lambda (key alist) (cdr (assoc key alist)))) (assoc*y (lambda (key ymap) (let* ((pair (assoc key (car ymap)))) (if pair (cdr pair) (abort (condition `(exn message ,(sprintf "key is not it the yaml mapping:\n~S\n->\n~S" key ymap )))) ) ))) (--> (lambda (ymap . /key) (define (--> y k) (if (null? k) y (--> (assoc*y (car k) y) (cdr k)) )) (--> ymap /key) )) (/ylist (vector->list yaml)) ; col-first (/t/c/r (list (map (lambda (?) (--> ? "des" "yaml")) /ylist) (map (lambda (?) (--> ? "des" "ss")) /ylist) (let ((/e.g. (map vector->list (map (lambda (?) (--> ? "e.g.")) /ylist)))) (map (lambda (e.g.) (list (map (lambda (e) (--> e "yaml")) e.g.) (map (lambda (e) (--> e "ss")) e.g.) )) /e.g. ) ) )) (assoc* (lambda (key alist) (cdr (assoc key alist)))) (assoc*y (lambda (key ymap) (let* ((pair (assoc key (car ymap)))) (if pair (cdr pair) (abort (condition `(exn message ,(sprintf "key is not it the yaml mapping:\n~S\n->\n~S" key ymap )))) ) ))) (--> (lambda (ymap . ) (define (:--> y k) (if (null? k) y (:--> (assoc*y (car k) y) (cdr k)) )) (:--> ymap ) )) (-> (lambda (/l . /i) (define (-> /l /i) (if (null? /i) /l (-> (list-ref* (car /i) /l) (cdr /i)))) (-> /l /i) )) (string->html (lambda (?) (string-translate* ? '(("\n" . "
") ("<" . "<") (">" . ">") ("\"" . """)) ))) ) (let* (( (vector->list yaml))) ;(printf " ; ;") ;; simpler steps here ;; - no formatting, such as bold the title ;; - no converting particular character like < > ;; - no constructing, treat the input as stream, just output when it meet a line/cell ;(printf "") ;(printf " ; ; ; ;") ;(map ; (lambda (l) ; (printf "") ; (printf "" (--> l "des" "yaml")) ; (printf "" (--> l "des" "ss")) ; ; (printf "") ; (printf "") ; ) ; ;) ;(printf "
yaml descriptionscheme description ; ; ;
yaml e.g.
scheme e.g.
~A~A") ; (let* ; ( ; (e.g. (vector->list (--> l "e.g."))) ; ) ; (map ; (lambda (e) ; (printf "") ; (printf "" (--> e "yaml")) ; (printf "" (--> e "ss")) ; (printf "") ; ) ; e.g. ; ) ; ) ; (printf "
")
;					(printf "~A
")
;					(printf "~A
") (printf "") (define (transpose list-of-list) (if (and* (map null? list-of-list)) '() (cons (map car list-of-list) (transpose (map cdr list-of-list))) ) ) (define (/tab<-& &string) ((lambda(@)(@ @))(lambda(@)(lambda(/tab) (if (string? /tab) (&string /tab) (map (@ @) /tab) ) )))) (define (<> tag-as-symbol) (lambda (s) (string-append "<" (symbol->string tag-as-symbol) ">" s "string tag-as-symbol) ">"))) (let* ( (title `( "yaml description" "scheme description" (("yaml e.g.") ("scheme e.g.")) )) (/t/r/c (cons title (transpose /t/c/r))) ; (/t/r/c (cons ((/tab<-& (<> 'b)) (car /t/r/c)) (cdr /t/r/c) )) (/t/c/r (reverse (let ((R (reverse (transpose /t/r/c)))) (cons ((/tab<-& (<> 'pre)) (car R)) (cdr R) ) ))) (/t/c/r (reverse (let ((R (reverse /t/c/r))) (cons (map transpose (car R)) (cdr R) ) ))) (/t/r/c (transpose /t/c/r)) ) (define (/tab->html /tab) (define (/row->html /row) (define (/col->html /col) (if (string? /col) ((<> 'td) /col) ((<> 'td) (/tab->html /col)) )) ((<> 'tr) (string-intersperse (map /col->html /row) "")) ) ((<> 'table) (string-intersperse (map /row->html /tab) "")) ) (display (/tab->html /t/r/c)) ;(display (/tab->html (transpose /t/r/c))) ) ))