You know how repetition of language has a tendency to render it meaningless? After a certain threshold has passed – let’s say ten repetitions – the definition slips away, leaving a smear of alien letters on the page.

“Tail?” What’s a tail? I DON’T KNOW.


#lang racket
#| Annotate tail calls in Scheme code built from non-quoted literals, variables, 'if', 'set!', 'λ', and function call.
Tail calls are annotated as (τ: ...). |#
(provide annotate-tails)
(require (only-in "match-diamond.rkt" match◇))
(define (annotate-tails code [tail? #t])
(let ([tail (λ (code) (annotate-tails code #t))]
[not-tail (λ (code) (annotate-tails code #f))]
[preserve-tail (λ (code) (annotate-tails code tail?))])
(match◇ code
((λ
...
)

,@(map not-tail `)
,(tail `)))
((if

)
(if ,(not-tail `)
,(preserve-tail `)
,(preserve-tail `)))
((set! )
(set! ,(not-tail `)))
(( ...)
(,@(if tail? '(τ:) '())
,(not-tail `) ,@(map not-tail `)))
(
))))

Advertisement