; Generalized map. With one parameter, it acts as a curried map function, returning a f mapper. ; With two or more parameter, (gmap f lst1 lst2 ... lstn) is identical to (map f lst1 lst2 ... lstn). (define (gmap . rest) (cond ((= (length rest) 1) (lambda lst (apply map (cons (car rest) lst)))) ((>= (length rest) 2) (apply map (cons (car rest) (cdr rest)))))) ;; Generalize f with ad hoc currying. ;; f is a function which, in its native form, takes two or more parameters. ;; The generalization allows f to act as a curried function. In case (curry-generalized f) ;; only receives a single parameter, it returns a lambda function which waits for the ;; remaining parameters. ;; .example (define gmap (curry-generalized map)) ;; .example (define gfilter (curry-generalized filter)) (define (curry-generalized f) (lambda rest (cond ((= (length rest) 1) (lambda lst (apply f (cons (car rest) lst)))) ((>= (length rest) 2) (apply f (cons (car rest) (cdr rest))))))) (define gfilter (curry-generalized filter)) (define gmap (curry-generalized map)) ; Interesting form. Requires the modified mirror which accepts list constituents. (table 'border 5 (gmap (compose tr (gmap td)) rows)) ; Or in case of map redefinition: (table 'border 5 (map (compose tr (map td)) rows)) ; Define partial attributes and element contents of element and return a new element ; with the attributes and contents partially fixed. ; attributes-and-contents is of the same form as the parameters to a surface elements. ; In fact, attributes-and-contents are just appended to the actual parameters to the modified. (define (modify-element element . attributes-and-contents) (lambda parameters (apply element (append parameters attributes-and-contents)))) (define td1 (modify-element td 'bgcolor red 'width 50)) (define ol-roman (modify-element ol 'css:list-style-type "lower-roman" 'css:background-color "yellow")) (ol-roman (map li (list "a" "b" "c"))) (ol-roman (map (lambda (e n) (li 'value n e)) (list "a" "b" "c" "d" "e") (map *10 (number-interval 1 5)))) (define img1 (modify-element img 'alt "")) (ul (map (compose li as-string) (number-interval 1 50))) (define ol1 (modify-element ol 'type "A")) (ol1 (map (compose li as-string) (number-interval 1 10))) (define ul1 (modify-element ul 'type "square")) (ul1 (map (compose li as-string) (number-interval 1 10))) (define (source-program . parameters) (let* ((contents-attributes (sort-tag-parameters parameters "source-program")) (contents (car contents-attributes)) (attributes (cdr contents-attributes)) ) (*source-program ...)) (source-program 'scr "includes/generate-leq/generate-leq-application.scm" 'select-from "..." 'select-to "..." 'slide-mode "external" 'book-book "inline" 'caption "An application of generate-leq which sorts the manual clauses" (decorations (decoration 'from "(generate-leq" 'to "first)" 'color purple 'face "bold") (decoration 'from "clause-leq?" 'color blue 'face italic) )) (point (main-point "...") (comment-point "...")) (items (item (main-item) (comment-item) (items ...)))