Created
August 13, 2012 20:26
-
-
Save takikawa/3343874 to your computer and use it in GitHub Desktop.
Tail recursion in the FYFF model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require redex | |
redex/examples/delim-cont/grammar | |
redex/examples/delim-cont/meta | |
redex/examples/delim-cont/reduce) | |
;; nullary Z combinator | |
(define Z | |
(term (λ (f) | |
((λ (x) (f (λ () (x x)))) | |
(λ (x) (f (λ () (x x)))))))) | |
;; unary Z combinator | |
(define Z1 | |
(term (λ (f) | |
((λ (x) (f (λ (v) ((x x) v)))) | |
(λ (x) (f (λ (v) ((x x) v)))))))) | |
;; recursively install handlers | |
(define default-handler | |
(term (,Z1 (λ (f) (λ (th) (% 0 (th) f)))))) | |
;; not safe for space due to repeated prompt installation | |
(traces | |
:-> | |
(term (<> | |
() [] | |
(,Z (λ (f) | |
(% | |
0 | |
(call/comp | |
(λ (k) (abort 0 (λ () (f)))) | |
0) | |
,default-handler)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment