Skip to content

Instantly share code, notes, and snippets.

@tcdowney
Created January 21, 2013 02:12
Show Gist options
  • Select an option

  • Save tcdowney/4583140 to your computer and use it in GitHub Desktop.

Select an option

Save tcdowney/4583140 to your computer and use it in GitHub Desktop.
Scheme snippet that returns true if the variable is a free variable in the expression. Taken from C311 notes and uses pmatch library.
(define free?
(lambda (y e ce)
(pmatch e
[,x (guard (symbol? x)) (and (eq? x y) (not (memq y ce)))]
[(lambda (,x) ,body) (free? y body (cons x ce))]
[(,rator ,rand) (or (free? y rator ce)(free? y rand ce))])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment