Skip to content

Instantly share code, notes, and snippets.

@kmicinski
Last active April 1, 2019 05:26
Show Gist options
  • Save kmicinski/c3f3eda4928d1fd29f0bdcda5e6e5f8e to your computer and use it in GitHub Desktop.
Save kmicinski/c3f3eda4928d1fd29f0bdcda5e6e5f8e to your computer and use it in GitHub Desktop.
Find all possible redexes of a given lambda term
#lang racket
(define (find-redexes e)
(match e
[`(λ (,x) ,body) (find-redexes body)]
[(? symbol? x) (void)]
[`((λ (,x) ,body) ,arg)
(begin
(display "I found this redex!\n")
(pretty-print e)
(find-redexes body)
(find-redexes arg))]
[`(,e0 ,e1)
(begin
(find-redexes e0)
(find-redexes e1))]))
(define example '((λ (x) ((λ (y) (x y)) x)) (λ (z) (z z))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment