[<<][staapl][>>][..]
Tue Apr 28 10:31:33 CEST 2009

cleanup

salvaged from rpn/cps.ss :

(define-syntax (cps stx)
  (let ((cps-fns (cdr (syntax->list stx))))
    #`(lambda (k)
        #,(foldr (lambda (fn k)
                   #`(lambda (p) (#,fn p #,k)))
                 #'k
                 cps-fns))))


(define-syntax (cps-let stx)
  (let ((cps-fns (cdr (syntax->list stx))))
    #`(lambda (p)
        #,(foldr (lambda (fn sub)
                   #`(let ((p (#,fn p))) #,sub))
                 #'p
                 cps-fns))))

(define-syntax-rule (macro form)
  (syntax->datum (expand-once #'form)))


(check
 (macro (cps a b c))
 => '(lambda (k)
       (lambda (p)
         (a p (lambda (p)
         (b p (lambda (p)
         (c p k))))))))

(check
 (macro (cps-let a b c))
 => '(lambda (p)
       (let ((p (a p)))
       (let ((p (b p)))
       (let ((p (c p)))
         p)))))



[Reply][About]
[<<][staapl][>>][..]