Created
January 21, 2013 02:12
-
-
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.
This file contains hidden or 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
| (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