Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Minimal Lambda Calculus Interpreter

Super simple call-by-value lambda calculus interpreter ! Made for a Purdue Hackers session ! Read the code to help yourself sleep at night !

https://groups.seas.harvard.edu/courses/cs152/2010sp/lectures/lec08.pdf

def subst(t1, v, t2):
    match t1:
        case ("variable", x) if x == v: return t2
        case ("variable", x) if x != v: return t1
        case ("function", x, t) if x == v: return t1
        case ("function", x, t) if x != v: return ("function", x, subst(t, v, t2))
        case ("application", lhs, rhs): return ("application", subst(lhs, v, t2), subst(rhs, v, t2))

def eval_subst(term):
    eval = eval_subst
    match term:
        case ("variable", x): raise Exception(f"unbound variable {x}")
        case ("function", x, t): return ("function", x, t)
        case ("application", t1, t2):
            match eval(t1):
                case ("function", x, t): return eval(subst(t, x, eval(t2)))
                case _: raise Exception("not a function")

About

simple lc interpreter for a workshop

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages