Added support for curry shorthand
parent
3ff496e1d6
commit
ef19fc42a6
10
README.md
10
README.md
|
@ -7,13 +7,19 @@
|
||||||
- Python files: installable, package list, etc
|
- Python files: installable, package list, etc
|
||||||
- $\alpha$-equivalence check
|
- $\alpha$-equivalence check
|
||||||
- Versioning
|
- Versioning
|
||||||
|
- Automatic church numerals
|
||||||
|
- Prettyprint functions (combine args, rename bound variables)
|
||||||
|
- Documentation in README
|
||||||
|
- Don't crash on errors
|
||||||
|
|
||||||
## Todo:
|
## Todo:
|
||||||
- live syntax check
|
- live syntax check
|
||||||
- Command and macro autocomplete
|
- Command and macro autocomplete
|
||||||
- step-by-step reduction
|
- step-by-step reduction
|
||||||
- Documentation in README
|
|
||||||
- Maybe a better icon?
|
- Maybe a better icon?
|
||||||
- Warn when overwriting macro
|
- Warn when overwriting macro
|
||||||
- Syntax highlighting: parenthesis, bound variables, macros, etc
|
- 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
26
main.py
|
@ -36,19 +36,19 @@ greeting.show()
|
||||||
r = runner.Runner()
|
r = runner.Runner()
|
||||||
|
|
||||||
r.run_lines([
|
r.run_lines([
|
||||||
"T = λa.λb.a",
|
"T = λab.a",
|
||||||
"F = λa.λb.b",
|
"F = λab.b",
|
||||||
"NOT = \\a.(a F T)",
|
"NOT = λa.(a F T)",
|
||||||
#"AND = a -> b -> (a F b)",
|
"AND = λab.(a F b)",
|
||||||
#"OR = a -> b -> (a T b)",
|
"OR = λab.(a T b)",
|
||||||
#"XOR = a -> b -> (a (NOT a b) b)",
|
"XOR = λab.(a (NOT a b) b)",
|
||||||
#"w = x -> (x x)",
|
"w = λx.(x x)",
|
||||||
#"W = (w w)",
|
"W = (w w)",
|
||||||
#"Y = f -> ( (x -> (f (x x))) (x -> (f (x x))) )",
|
"Y = λf.( (λx.(f (x x))) (λx.(f (x x))) )",
|
||||||
#"l = if_true -> if_false -> which -> ( which if_true if_false )"
|
"PAIR = λabi.( i a b )",
|
||||||
#"inc = n -> f -> x -> (f (n f x))",
|
"inc = λnfa.(f (n f a))",
|
||||||
#"zero = a -> x -> x",
|
"zero = λax.x",
|
||||||
#"one = f -> x -> (f x)",
|
"one = λfx.(f x)"
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,12 @@ class Parser:
|
||||||
# Right associative.
|
# Right associative.
|
||||||
#
|
#
|
||||||
# <var> => <exp>
|
# <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)
|
pp_lambda_fun.set_parse_action(tokens.lambda_func.from_parse)
|
||||||
|
|
||||||
# Assignment.
|
# Assignment.
|
||||||
|
|
14
tokens.py
14
tokens.py
|
@ -207,10 +207,16 @@ class lambda_func(LambdaToken):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_parse(result):
|
def from_parse(result):
|
||||||
return lambda_func(
|
if len(result[0]) == 1:
|
||||||
result[0],
|
return lambda_func(
|
||||||
result[1]
|
macro(result[0][0]),
|
||||||
)
|
result[1]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return lambda_func(
|
||||||
|
macro(result[0].pop(0)),
|
||||||
|
lambda_func.from_parse(result)
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
Reference in New Issue