Skip to content

Commit

Permalink
added composition operator "of"
Browse files Browse the repository at this point in the history
  • Loading branch information
billhails committed Nov 23, 2024
1 parent 8b4f65f commit d6f0200
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions fn/fns.fn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print (car of cdr of cdr)([[], [], ['a']]);
26 changes: 13 additions & 13 deletions fn/pettersson92.fn
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let
typedef code {
symbol(string) |
case(code, list(code)) |
of(pattern, code) |
when(pattern, code) |
letrec(list(#(code, code)), code) |
lambda(list(code), code) |
apply(code, list(code))
Expand Down Expand Up @@ -195,7 +195,7 @@ let
}
}
(case(cond, rules)) { case(h(cond), rules |> h) }
(of(pattern, action)) { of(pattern, h(action)) }
(when(pattern, action)) { when(pattern, h(action)) }
(letrec(defs, body)) {
letrec(defs |> fn {
(#(name, value)) { #(h(name), h(value)) }
Expand Down Expand Up @@ -601,7 +601,7 @@ let
}
}
fn translateArc(arc(pat, _, state)) {
of(pat, translateState(state))
when(pat, translateState(state))
}
fn translateLambdas(lambdas) {
dict.values(lambdas) |> fn {
Expand Down Expand Up @@ -674,29 +674,29 @@ in
// #(symbol("Q$1"), lambda([symbol("x$2$0")], symbol("x$2$0"))),
// #(symbol("error"), lambda([], symbol("error")))],
// case(symbol("x$1"), [
// of(x$1=1,
// when(x$1=1,
// case(symbol("x$2"), [
// of(x$2=#(x$2$0=_, x$2$1=_),
// when(x$2=#(x$2$0=_, x$2$1=_),
// case(symbol("x$3"), [
// of(x$3=cons(x$3$0=_, x$3$1=_),
// when(x$3=cons(x$3$0=_, x$3$1=_),
// case(symbol("x$2$1"), [
// of(x$2$1=3,
// when(x$2$1=3,
// apply(symbol("cons"), [
// symbol("x$3$0"),
// symbol("x$3$1")])),
// of(x$2$1=_,
// when(x$2$1=_,
// apply(symbol("error"),
// []))])),
// of(x$3=nil,
// when(x$3=nil,
// apply(symbol("Q$1"),
// [symbol("x$2$0")]))]))])),
// of(x$1=_,
// when(x$1=_,
// case(symbol("x$2"), [
// of(x$2=#(x$2$0=_, x$2$1=_),
// when(x$2=#(x$2$0=_, x$2$1=_),
// case(symbol("x$3"), [
// of(x$3=nil,
// when(x$3=nil,
// apply(symbol("Q$1"),
// [symbol("x$2$0")])),
// of(x$3=_,
// when(x$3=_,
// apply(symbol("error"),
// []))]))]))])))
2 changes: 2 additions & 0 deletions src/preamble.fn
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ fn error_(line, file, message) {
exit(1);
}

infix right 120 "of" fn (f, g, x) { f(g(x)) };

fn append {
([], b) { b }
(h @ t, b) { h @ append(t, b) }
Expand Down
2 changes: 1 addition & 1 deletion vim/syntax/fnatural.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ syntax match fnOperator "\v\|"
syntax match fnOperator "\v\<"
syntax match fnOperator "\v\>"
syntax match fnOperator "\v\="
syntax keyword fnOperator and nand or nor not xor xnor
syntax keyword fnOperator and nand or nor not xor xnor of
highlight link fnOperator Operator

syntax region fnString start=/\v'/ skip=/\v\\./ end=/\v'/
Expand Down

0 comments on commit d6f0200

Please sign in to comment.