Added support for curry shorthand

master
Mark 2022-10-21 19:13:07 -07:00
parent 3ff496e1d6
commit ef19fc42a6
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
4 changed files with 37 additions and 20 deletions

View File

@ -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
- Pin header to top of screen
## Mention in Docs
- lambda functions only work with single-letter arguments

26
main.py
View File

@ -36,19 +36,19 @@ greeting.show()
r = runner.Runner()
r.run_lines([
"T = λab.a",
"F = λab.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)"
])

View File

@ -24,7 +24,12 @@ class Parser:
# Right associative.
#
# <var> => <exp>
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.

View File

@ -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,