Skip to content

Instantly share code, notes, and snippets.

@kmicinski
Created February 29, 2024 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmicinski/4dac3ace3757665e12675362fda74069 to your computer and use it in GitHub Desktop.
Save kmicinski/4dac3ace3757665e12675362fda74069 to your computer and use it in GitHub Desktop.
#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