Created
February 29, 2024 17:35
-
-
Save kmicinski/4dac3ace3757665e12675362fda74069 to your computer and use it in GitHub Desktop.
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 | |
;; Some example λ calculus terms in Racket | |
;; ID (identity) applied to ID | |
;; ((λ (x) x) (λ (x) x)) | |
;; can't run this, y is free--but I can still β reduce it | |
;;((λ (x) y) (λ (z) y)) | |
;; ⟶β y <-- error, in Racket, because we don't know what y is | |
;; The Ω combinator -- I can't run this because it is an infinite loop | |
;; ((λ (x) (x x)) (λ (x) (x x))) | |
;; In general, anything I write in the λ-calculus can be | |
;; run in the Racket interpreter. But since Racket isn't | |
;; using reduction literally (instead it is following | |
;; the strategy of last class, creating closures), I can't | |
;; see the reduction textually. | |
(define (freevars e) | |
(match e | |
[(? symbol? x) (set x)] | |
[`(lambda (,x) ,eb) (set-remove (freevars eb) x)] | |
[`(,e0 ,e1) (set-union (freevars e0) (freevars e1))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment