switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
; -*- scheme -*-
|
|
|
|
(define (begin->cps forms k)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((atom? forms) `(,k ,forms))
|
|
|
|
((null? (cdr forms)) (cps- (car forms) k))
|
|
|
|
(#t (let ((_ (gensym))) ; var to bind ignored value
|
|
|
|
(cps- (car forms) `(lambda (,_)
|
|
|
|
,(begin->cps (cdr forms) k)))))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (lambda/cc args body)
|
2009-04-14 20:12:01 -04:00
|
|
|
`(cons 'lambda/cc (lambda ,args ,body)))
|
2009-01-03 00:30:22 -05:00
|
|
|
|
|
|
|
; a utility used at run time to dispatch a call with or without
|
|
|
|
; the continuation argument, depending on the function
|
|
|
|
(define (funcall/cc f k . args)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(if (and (pair? f) (eq (car f) 'lambda/cc))
|
2009-04-14 20:12:01 -04:00
|
|
|
(apply (cdr f) (cons k args))
|
2009-02-09 00:38:40 -05:00
|
|
|
(k (apply f args))))
|
2009-01-03 00:30:22 -05:00
|
|
|
(define *funcall/cc-names*
|
2009-03-01 23:26:16 -05:00
|
|
|
(list->vector
|
2009-01-03 00:30:22 -05:00
|
|
|
(map (lambda (i) (intern (string 'funcall/cc- i)))
|
|
|
|
(iota 6))))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (def-funcall/cc-n args)
|
2009-02-09 00:38:40 -05:00
|
|
|
(let ((name (aref *funcall/cc-names* (length args))))
|
2009-01-03 00:30:22 -05:00
|
|
|
`(define (,name f k ,@args)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(if (and (pair? f) (eq (car f) 'lambda/cc))
|
2009-04-14 20:12:01 -04:00
|
|
|
((cdr f) k ,@args)
|
2009-02-09 00:38:40 -05:00
|
|
|
(k (f ,@args))))))
|
2009-01-03 00:30:22 -05:00
|
|
|
(def-funcall/cc-n ())
|
|
|
|
(def-funcall/cc-n (a0))
|
|
|
|
(def-funcall/cc-n (a0 a1))
|
|
|
|
(def-funcall/cc-n (a0 a1 a2))
|
|
|
|
(def-funcall/cc-n (a0 a1 a2 a3))
|
|
|
|
(def-funcall/cc-n (a0 a1 a2 a3 a4))
|
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
(define (rest->cps xformer form k argsyms)
|
2009-01-02 17:58:14 -05:00
|
|
|
(let ((el (car form)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (or (atom? el) (constant? el))
|
2009-01-02 17:58:14 -05:00
|
|
|
(xformer (cdr form) k (cons el argsyms))
|
|
|
|
(let ((g (gensym)))
|
|
|
|
(cps- el `(lambda (,g)
|
|
|
|
,(xformer (cdr form) k (cons g argsyms))))))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
2009-01-03 00:30:22 -05:00
|
|
|
(define (make-funcall/cc head ke args)
|
|
|
|
(let ((n (length args)))
|
|
|
|
(if (< n 6)
|
|
|
|
`(,(aref *funcall/cc-names* n) ,head ,ke ,@args)
|
|
|
|
`(funcall/cc ,head ,ke ,@args))))
|
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
; (f x) => (cps- f `(lambda (F) ,(cps- x `(lambda (X) (F ,k X)))))
|
|
|
|
(define (app->cps form k argsyms)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((atom? form)
|
2008-12-28 03:01:18 -05:00
|
|
|
(let ((r (reverse argsyms)))
|
2009-01-03 00:30:22 -05:00
|
|
|
(make-funcall/cc (car r) k (cdr r))))
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t (rest->cps app->cps form k argsyms))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
; (+ x) => (cps- x `(lambda (X) (,k (+ X))))
|
|
|
|
(define (builtincall->cps form k)
|
|
|
|
(prim->cps (cdr form) k (list (car form))))
|
|
|
|
(define (prim->cps form k argsyms)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((atom? form) `(,k ,(reverse argsyms)))
|
|
|
|
(#t (rest->cps prim->cps form k argsyms))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
2008-12-28 19:00:45 -05:00
|
|
|
(define *top-k* (gensym))
|
2009-04-17 10:41:15 -04:00
|
|
|
(set-top-level-value! *top-k* identity)
|
2008-12-28 19:00:45 -05:00
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
(define (cps form)
|
|
|
|
(η-reduce
|
|
|
|
(β-reduce
|
|
|
|
(macroexpand
|
2008-12-28 19:00:45 -05:00
|
|
|
(cps- (macroexpand form) *top-k*)))))
|
2008-12-28 03:01:18 -05:00
|
|
|
(define (cps- form k)
|
|
|
|
(let ((g (gensym)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((or (atom? form) (constant? form))
|
2008-12-28 03:01:18 -05:00
|
|
|
`(,k ,form))
|
|
|
|
|
|
|
|
((eq (car form) 'lambda)
|
2009-01-03 00:30:22 -05:00
|
|
|
`(,k (lambda/cc ,(cons g (cadr form)) ,(cps- (caddr form) g))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
((eq (car form) 'begin)
|
|
|
|
(begin->cps (cdr form) k))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
((eq (car form) 'if)
|
|
|
|
(let ((test (cadr form))
|
|
|
|
(then (caddr form))
|
|
|
|
(else (cadddr form)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (atom? k)
|
2008-12-28 03:01:18 -05:00
|
|
|
(cps- test `(lambda (,g)
|
|
|
|
(if ,g
|
|
|
|
,(cps- then k)
|
|
|
|
,(cps- else k))))
|
|
|
|
`(let ((,g ,k))
|
|
|
|
,(cps- form g)))))
|
|
|
|
|
2008-12-28 19:00:45 -05:00
|
|
|
((eq (car form) 'and)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((atom? (cdr form)) `(,k #t))
|
|
|
|
((atom? (cddr form)) (cps- (cadr form) k))
|
|
|
|
(#t
|
2009-05-30 13:04:34 -04:00
|
|
|
(if (atom? k)
|
2008-12-28 19:00:45 -05:00
|
|
|
(cps- (cadr form)
|
|
|
|
`(lambda (,g)
|
|
|
|
(if ,g ,(cps- `(and ,@(cddr form)) k)
|
|
|
|
(,k ,g))))
|
|
|
|
`(let ((,g ,k))
|
|
|
|
,(cps- form g))))))
|
|
|
|
|
|
|
|
((eq (car form) 'or)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((atom? (cdr form)) `(,k #f))
|
|
|
|
((atom? (cddr form)) (cps- (cadr form) k))
|
|
|
|
(#t
|
|
|
|
(if (atom? k)
|
2008-12-28 19:00:45 -05:00
|
|
|
(cps- (cadr form)
|
|
|
|
`(lambda (,g)
|
|
|
|
(if ,g (,k ,g)
|
|
|
|
,(cps- `(or ,@(cddr form)) k))))
|
|
|
|
`(let ((,g ,k))
|
|
|
|
,(cps- form g))))))
|
|
|
|
|
|
|
|
((eq (car form) 'while)
|
|
|
|
(let ((test (cadr form))
|
|
|
|
(body (caddr form))
|
|
|
|
(lastval (gensym)))
|
|
|
|
(cps- (macroexpand
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
`(let ((,lastval #f))
|
2008-12-28 19:00:45 -05:00
|
|
|
((label ,g (lambda ()
|
|
|
|
(if ,test
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (set! ,lastval ,body)
|
2008-12-28 19:00:45 -05:00
|
|
|
(,g))
|
|
|
|
,lastval))))))
|
|
|
|
k)))
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
((eq (car form) 'set!)
|
2008-12-28 03:01:18 -05:00
|
|
|
(let ((var (cadr form))
|
|
|
|
(E (caddr form)))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(cps- E `(lambda (,g) (,k (set! ,var ,g))))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
((eq (car form) 'reset)
|
2008-12-28 19:00:45 -05:00
|
|
|
`(,k ,(cps- (cadr form) *top-k*)))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
((eq (car form) 'shift)
|
|
|
|
(let ((v (cadr form))
|
2008-12-28 19:00:45 -05:00
|
|
|
(E (caddr form))
|
|
|
|
(val (gensym)))
|
2009-01-03 00:30:22 -05:00
|
|
|
`(let ((,v (lambda/cc (,g ,val) (,g (,k ,val)))))
|
2008-12-28 19:00:45 -05:00
|
|
|
,(cps- E *top-k*))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
2009-01-04 21:45:21 -05:00
|
|
|
((eq (car form) 'without-delimited-continuations)
|
|
|
|
`(,k ,(cadr form)))
|
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
((and (constant? (car form))
|
|
|
|
(builtin? (eval (car form))))
|
2008-12-28 03:01:18 -05:00
|
|
|
(builtincall->cps form k))
|
|
|
|
|
|
|
|
; ((lambda (...) body) ...)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
((and (pair? (car form))
|
2008-12-28 03:01:18 -05:00
|
|
|
(eq (caar form) 'lambda))
|
|
|
|
(let ((largs (cadr (car form)))
|
|
|
|
(lbody (caddr (car form))))
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((null? largs) ; ((lambda () body))
|
2009-01-03 00:30:22 -05:00
|
|
|
(cps- lbody k))
|
2009-01-31 20:53:58 -05:00
|
|
|
((symbol? largs) ; ((lambda x body) args...)
|
2009-01-03 00:30:22 -05:00
|
|
|
(cps- `((lambda (,largs) ,lbody) (list ,@(cdr form))) k))
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t
|
2009-01-03 00:30:22 -05:00
|
|
|
(cps- (cadr form) `(lambda (,(car largs))
|
|
|
|
,(cps- `((lambda ,(cdr largs) ,lbody)
|
|
|
|
,@(cddr form))
|
|
|
|
k)))))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t
|
2008-12-28 03:01:18 -05:00
|
|
|
(app->cps form k ())))))
|
|
|
|
|
|
|
|
; (lambda (args...) (f args...)) => f
|
2008-12-28 19:00:45 -05:00
|
|
|
; but only for constant, builtin f
|
2008-12-28 03:01:18 -05:00
|
|
|
(define (η-reduce form)
|
2009-01-31 20:53:58 -05:00
|
|
|
(cond ((or (atom? form) (constant? form)) form)
|
2008-12-28 03:01:18 -05:00
|
|
|
((and (eq (car form) 'lambda)
|
|
|
|
(let ((body (caddr form))
|
2009-01-03 00:30:22 -05:00
|
|
|
(args (cadr form)))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(and (pair? body)
|
2009-05-30 17:13:13 -04:00
|
|
|
(equal? (cdr body) args)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(constant? (car (caddr form))))))
|
2009-01-03 00:30:22 -05:00
|
|
|
(car (caddr form)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t (map η-reduce form))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
2008-12-28 19:00:45 -05:00
|
|
|
(define (contains x form)
|
|
|
|
(or (eq form x)
|
|
|
|
(any (lambda (p) (contains x p)) form)))
|
|
|
|
|
2008-12-28 03:01:18 -05:00
|
|
|
(define (β-reduce form)
|
2009-01-31 20:53:58 -05:00
|
|
|
(if (or (atom? form) (constant? form))
|
2009-01-02 17:58:14 -05:00
|
|
|
form
|
2009-01-31 20:53:58 -05:00
|
|
|
(β-reduce- (map β-reduce form))))
|
2008-12-28 19:00:45 -05:00
|
|
|
|
2009-01-02 17:58:14 -05:00
|
|
|
(define (β-reduce- form)
|
2008-12-28 19:00:45 -05:00
|
|
|
; ((lambda (f) (f arg)) X) => (X arg)
|
2009-03-04 22:48:17 -05:00
|
|
|
(cond ((and (length= form 2)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(pair? (car form))
|
2008-12-28 03:01:18 -05:00
|
|
|
(eq (caar form) 'lambda)
|
|
|
|
(let ((args (cadr (car form)))
|
|
|
|
(body (caddr (car form))))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(and (pair? body) (pair? args)
|
2009-03-04 22:48:17 -05:00
|
|
|
(length= body 2)
|
|
|
|
(length= args 1)
|
2008-12-28 03:01:18 -05:00
|
|
|
(eq (car body) (car args))
|
|
|
|
(not (eq (cadr body) (car args)))
|
2009-01-31 20:53:58 -05:00
|
|
|
(symbol? (cadr body)))))
|
2009-01-02 17:58:14 -05:00
|
|
|
`(,(cadr form)
|
2008-12-28 03:01:18 -05:00
|
|
|
,(cadr (caddr (car form)))))
|
2008-12-28 19:00:45 -05:00
|
|
|
|
|
|
|
; (identity x) => x
|
|
|
|
((eq (car form) *top-k*)
|
2009-01-02 17:58:14 -05:00
|
|
|
(cadr form))
|
2008-12-28 19:00:45 -05:00
|
|
|
|
|
|
|
; uncurry:
|
|
|
|
; ((lambda (p1) ((lambda (args...) body) exprs...)) s) =>
|
|
|
|
; ((lambda (p1 args...) body) s exprs...)
|
|
|
|
; where exprs... doesn't contain p1
|
2009-03-04 22:48:17 -05:00
|
|
|
((and (length= form 2)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(pair? (car form))
|
2008-12-28 19:00:45 -05:00
|
|
|
(eq (caar form) 'lambda)
|
2009-01-31 20:53:58 -05:00
|
|
|
(or (atom? (cadr form)) (constant? (cadr form)))
|
2008-12-28 19:00:45 -05:00
|
|
|
(let ((args (cadr (car form)))
|
|
|
|
(s (cadr form))
|
2009-01-02 17:58:14 -05:00
|
|
|
(body (caddr (car form))))
|
2009-03-04 22:48:17 -05:00
|
|
|
(and (pair? args) (length= args 1)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(pair? body)
|
|
|
|
(pair? (car body))
|
2008-12-28 19:00:45 -05:00
|
|
|
(eq (caar body) 'lambda)
|
|
|
|
(let ((innerargs (cadr (car body)))
|
|
|
|
(innerbody (caddr (car body)))
|
|
|
|
(params (cdr body)))
|
|
|
|
(and (not (contains (car args) params))
|
|
|
|
`((lambda ,(cons (car args) innerargs)
|
|
|
|
,innerbody)
|
|
|
|
,s
|
|
|
|
,@params)))))))
|
|
|
|
|
2009-01-31 20:53:58 -05:00
|
|
|
(#t form)))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (with-delimited-continuations . code)
|
2009-05-29 00:38:50 -04:00
|
|
|
(cps `((lambda () ,@code))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-macro (define-generator form . body)
|
2008-12-28 03:01:18 -05:00
|
|
|
(let ((ko (gensym))
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(cur (gensym))
|
|
|
|
(name (car form))
|
|
|
|
(args (cdr form)))
|
|
|
|
`(define (,name ,@args)
|
|
|
|
(let ((,ko #f)
|
|
|
|
(,cur #f))
|
2008-12-28 03:01:18 -05:00
|
|
|
(lambda ()
|
|
|
|
(with-delimited-continuations
|
|
|
|
(if ,ko (,ko ,cur)
|
|
|
|
(reset
|
|
|
|
(let ((yield
|
|
|
|
(lambda (v)
|
|
|
|
(shift yk
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (set! ,ko yk)
|
|
|
|
(set! ,cur v))))))
|
2009-05-20 20:56:25 -04:00
|
|
|
,@body)))))))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
; a test case
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(define-generator (range-iterator lo hi)
|
2008-12-28 03:01:18 -05:00
|
|
|
((label loop
|
|
|
|
(lambda (i)
|
|
|
|
(if (< hi i)
|
|
|
|
'done
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (yield i)
|
2008-12-28 03:01:18 -05:00
|
|
|
(loop (+ 1 i))))))
|
|
|
|
lo))
|
|
|
|
|
2008-12-28 19:00:45 -05:00
|
|
|
; example from Chung-chieh Shan's paper
|
2009-05-30 17:13:13 -04:00
|
|
|
(assert (equal?
|
2008-12-28 19:00:45 -05:00
|
|
|
(with-delimited-continuations
|
|
|
|
(cons 'a (reset (cons 'b (shift f (cons 1 (f (f (cons 'c ())))))))))
|
|
|
|
'(a 1 b b c)))
|
|
|
|
|
2009-01-31 20:53:58 -05:00
|
|
|
#t
|
2008-12-28 03:01:18 -05:00
|
|
|
|
|
|
|
#|
|
|
|
|
todo:
|
2009-01-03 00:30:22 -05:00
|
|
|
* tag lambdas that accept continuation arguments, compile computed
|
2008-12-28 03:01:18 -05:00
|
|
|
calls to calls to funcall/cc that does the right thing for both
|
|
|
|
cc-lambdas and normal lambdas
|
|
|
|
|
2009-01-03 00:30:22 -05:00
|
|
|
* handle dotted arglists in lambda
|
|
|
|
|
2009-03-28 17:39:04 -04:00
|
|
|
- optimize constant functions, e.g. (funcall/cc-0 #:g65 (lambda (#:g58) 'done))
|
|
|
|
|
2009-01-03 00:30:22 -05:00
|
|
|
- implement CPS version of apply
|
2008-12-28 19:00:45 -05:00
|
|
|
|
2009-01-02 17:58:14 -05:00
|
|
|
- use fewer gensyms
|
|
|
|
|
2008-12-28 19:00:45 -05:00
|
|
|
here's an alternate way to transform a while loop:
|
|
|
|
|
|
|
|
(let ((x 0))
|
|
|
|
(while (< x 10)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (print x) (set! x (+ 1 x)))))
|
2008-12-28 19:00:45 -05:00
|
|
|
=>
|
|
|
|
(let ((x 0))
|
|
|
|
(reset
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(let ((l #f))
|
2008-12-28 19:00:45 -05:00
|
|
|
(let ((k (shift k (k k))))
|
|
|
|
(if (< x 10)
|
switching to scheme #t, #f, and () values
porting code to sort out which NILs are false and which are
empty lists
switching to scheme-style special forms. however you feel about
scheme names vs. CL names, using both is silly.
mostly switching to scheme predicate names, with compatibility
aliases for now. adding set-constant! to make this efficient.
adding null?, eqv?, assq, assv, assoc, memq, memv, member
adding 2-argument form of if
allowing else as final cond condition
looking for init file in same directory as executable, so flisp
can be started from anywhere
renaming T to FL_T, since exporting a 1-character symbol is
not very nice
adding opaque type boilerplate example file
adding correctness checking for the pattern-lambda benchmark
bugfix in int2str
2009-01-28 20:04:23 -05:00
|
|
|
(begin (set! l (begin (print x)
|
|
|
|
(set! x (+ 1 x))))
|
2008-12-28 19:00:45 -05:00
|
|
|
(k k))
|
|
|
|
l)))))
|
2008-12-28 03:01:18 -05:00
|
|
|
|#
|