diff --git a/README.md b/README.md index 96ec63c..cd72363 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,19 @@ - Python files: installable, package list, etc - $\alpha$-equivalence check - Versioning + - Automatic church numerals + - Prettyprint functions (combine args, rename bound variables) + - Documentation in README + - Don't crash on errors ## Todo: - live syntax check - Command and macro autocomplete - step-by-step reduction - - Documentation in README - Maybe a better icon? - Warn when overwriting macro - Syntax highlighting: parenthesis, bound variables, macros, etc - - Pin header to top of screen \ No newline at end of file + - Pin header to top of screen + +## Mention in Docs + - lambda functions only work with single-letter arguments \ No newline at end of file diff --git a/main.py b/main.py index 8edf3bf..e42d202 100755 --- a/main.py +++ b/main.py @@ -36,19 +36,19 @@ greeting.show() r = runner.Runner() r.run_lines([ - "T = λa.λb.a", - "F = λa.λb.b", - "NOT = \\a.(a F T)", - #"AND = a -> b -> (a F b)", - #"OR = a -> b -> (a T b)", - #"XOR = a -> b -> (a (NOT a b) b)", - #"w = x -> (x x)", - #"W = (w w)", - #"Y = f -> ( (x -> (f (x x))) (x -> (f (x x))) )", - #"l = if_true -> if_false -> which -> ( which if_true if_false )" - #"inc = n -> f -> x -> (f (n f x))", - #"zero = a -> x -> x", - #"one = f -> x -> (f x)", + "T = λab.a", + "F = λab.b", + "NOT = λa.(a F T)", + "AND = λab.(a F b)", + "OR = λab.(a T b)", + "XOR = λab.(a (NOT a b) b)", + "w = λx.(x x)", + "W = (w w)", + "Y = λf.( (λx.(f (x x))) (λx.(f (x x))) )", + "PAIR = λabi.( i a b )", + "inc = λnfa.(f (n f a))", + "zero = λax.x", + "one = λfx.(f x)" ]) diff --git a/parser.py b/parser.py index 729c4d1..6e75be1 100755 --- a/parser.py +++ b/parser.py @@ -24,7 +24,12 @@ class Parser: # Right associative. # # => - pp_lambda_fun = (pp.Suppress("λ") | pp.Suppress("\\")) + pp_macro + pp.Suppress(".") + pp_expr + pp_lambda_fun = ( + (pp.Suppress("λ") | pp.Suppress("\\")) + + pp.Group(pp.Char(pp.alphas)[1, ...]) + + pp.Suppress(".") + + pp_expr + ) pp_lambda_fun.set_parse_action(tokens.lambda_func.from_parse) # Assignment. diff --git a/tokens.py b/tokens.py index 2fdba5f..a30d48f 100755 --- a/tokens.py +++ b/tokens.py @@ -207,10 +207,16 @@ class lambda_func(LambdaToken): @staticmethod def from_parse(result): - return lambda_func( - result[0], - result[1] - ) + if len(result[0]) == 1: + return lambda_func( + macro(result[0][0]), + result[1] + ) + else: + return lambda_func( + macro(result[0].pop(0)), + lambda_func.from_parse(result) + ) def __init__( self,