Name:
Anonymous
2012-12-11 5:03
(define (push-all pushes acc)
(if (null? pushes)
acc
(push-all (cdr pushes) (cons (car pushes) acc))))
(define (pull-in-tail lis is-divider)
(let loop ((lis lis) (acc '()))
(cond ((null? lis) (reverse acc))
((is-divider (car lis)) (push-all acc (list (pull-in-tail (cdr lis) is-divider))))
(else (loop (cdr lis) (cons (car lis) acc))))))
(define (rec-pull-in-tail tree is-divider)
(if (list? tree)
(pull-in-tail (map (lambda (elem) (rec-pull-in-tail elem is-divider))
tree)
is-divider)
tree))
(defmacro (tails divider . code)
`(begin . ,(rec-pull-in-tail code (lambda (x) (eq? x divider)))))
;; example
(if #f
(tails |
(define (factorial n)
| let loop ((n n) | acc 1)
| if (= n 0)
acc
| loop (- n 1) | * n acc)
(factorial 10)
(factorial | + 10 11)
)
)
Name:
Anonymous
2012-12-11 5:20
>>5
It's a macro that lets you write:
(tails | (display | * x y | + z t | / 3 r))
instead of
(display (* x y (+ z t (/ 3 r))))
Name:
Anonymous
2012-12-11 5:29
Ok, I see. They have this in Clojure, more or less.
Name:
Anonymous
2012-12-11 7:38
I prefer to see the nesting.