diff --git a/examples/combinators.modal b/examples/combinators.modal index 4f3aa96..8a425cf 100644 --- a/examples/combinators.modal +++ b/examples/combinators.modal @@ -1,11 +1,11 @@ +<> (M ?x) (?x ?x) +<> (KI ?x ?y) (?y) +<> (T ?x ?y) (?y ?y) +<> (W ?x ?y) (?x ?y ?y) +<> (K ?x ?y) (?x) +<> (C ?x ?y ?z) (?x ?z ?y) +<> (B ?x ?y ?z) (?x (?y ?z)) +<> (I ?x) (?x) +<> (S ?x ?y ?z) (?x ?z (?y ?z)) -define (M ?x) (?x ?x) -define (KI ?x ?y) (?y) -define (T ?x ?y) (?y ?y) -define (W ?x ?y) (?x ?y ?y) -define (K ?x ?y) (?x) -define (C ?x ?y ?z) (?x ?z ?y) -define (B ?x ?y ?z) (?x (?y ?z)) -define (I ?x) (?x) -define (S ?x ?y ?z) (?x ?z (?y ?z)) - +C KI x y z diff --git a/examples/concat.modal b/examples/concat.modal deleted file mode 100644 index f175cf2..0000000 --- a/examples/concat.modal +++ /dev/null @@ -1,8 +0,0 @@ -define (: ?x ?y ;) (define ?x ?y) -: (?x dup) (?x ?x) ; -: (?x ?y swap) (?y ?x) ; -: (?x drop) () ; -: (?x ?y p*) (?x * ?y) ; -: square (dup p*) ; - -10 square \ No newline at end of file diff --git a/examples/console_write.modal b/examples/console_write.modal deleted file mode 100644 index 4035038..0000000 --- a/examples/console_write.modal +++ /dev/null @@ -1,3 +0,0 @@ -<> ((send ?:)) () - -(send (hello world)) \ No newline at end of file diff --git a/examples/flip.modal b/examples/flip.modal deleted file mode 100644 index f8c9e7b..0000000 --- a/examples/flip.modal +++ /dev/null @@ -1,8 +0,0 @@ -<> (explode ?*) (str (?*)) -<> (reverse (str (?h ?t))) (reverse/l ?t (?h)) -<> (reverse (str (?h))) (?h) -<> (reverse/l (?h ?t) ?l) (reverse/l ?t (?h ?l)) -<> (reverse/l (?h) ?l) (str (?h ?l)) -<> (implode str ?*) (?*) - -(implode reverse (explode hello)) \ No newline at end of file diff --git a/examples/console_read.modal b/examples/io_read.modal similarity index 59% rename from examples/console_read.modal rename to examples/io_read.modal index 2c33054..f4eb35d 100644 --- a/examples/console_read.modal +++ b/examples/io_read.modal @@ -5,5 +5,5 @@ (Tell me three things: \n) print ' ' (You said: read stdin -then, you continued: read stdin -finaly, you concluded: read stdin) print \ No newline at end of file +\nthen, you continued: read stdin +\nfinaly, you concluded: read stdin \n) print \ No newline at end of file diff --git a/examples/io_write.modal b/examples/io_write.modal new file mode 100644 index 0000000..09bfb1f --- /dev/null +++ b/examples/io_write.modal @@ -0,0 +1,3 @@ +<> (send ?:) (?:) + +send (hello world) \ No newline at end of file diff --git a/examples/lisp.modal b/examples/lisp.modal deleted file mode 100644 index d082cd4..0000000 --- a/examples/lisp.modal +++ /dev/null @@ -1,13 +0,0 @@ -define nil () -define (pair (?x) (?y)) ((?x ?y)) -define (first (?x ?y)) (?x) -define (second (?x ?y)) (?y) - -define (quote ?x) (quote ?x) -define (if ?c ?t else ?f) (if/else ?c quote ?t quote ?f) -define (if/else (true) quote (?t) quote (?f)) (?t) -define (if/else (false) quote (?t) quote (?f)) (?f) - -define (hello) (bye) - -pair (pair (foo) (nil)) (baz) \ No newline at end of file diff --git a/examples/prelude.modal b/examples/prelude.modal deleted file mode 100644 index b2b2f0a..0000000 --- a/examples/prelude.modal +++ /dev/null @@ -1,144 +0,0 @@ -1 -> (s (0)); - - -neg (neg ?x) -> ?x; -neg (0) -> 0; - - -add (s ?x) (s ?y) -> s (add ?x (s ?y)); -add (0) (s ?x) -> s ?x; -add (s ?x) (0) -> s ?x; -add (0) (0) -> 0; - - -?x + ?y + ?z -> (?x + ?y) + ?z; - - -?x + ?y -> add ?x ?y; - - -sub (s ?x) (s ?y) -> sub ?x ?y; -sub (s ?x) (0) -> s ?x; -sub (0) (s ?x) -> neg (s ?x); -sub (0) (0) -> 0; - - -?x - ?y -> sub ?x ?y; - - -mul (s ?x) (s ?y) -> (s ?x) + (mul (s ?x) ((s ?y) - 1)); -mul (s ?x) (s (0)) -> s ?x; -mul (s ?x) (0) -> 0; -mul (0) (s ?x) -> 0; - - -?x * ?y -> mul ?x ?y; - - -Ensures that a list or a number has been reduced to its normal form. ; - -reduced (0) -> true; -reduced (nil) -> true; -reduced (s ?x) -> reduced ?x; -reduced (?h : ?t) -> reduced ?t; -reduced ?x -> false; - - -Because there may be conflicts with expressions that -are currently being reduced, we need to fold over reduced -lists, i.e ones that have already been fully generated. ; - -fold (?f) ?i ?l -> fold reduced ?l (?f) ?i ?l; -fold true (?f) ?i (nil) -> ?i; -fold true (?f) ?i (?h : (nil)) -> ?f ?i ?h; -fold true (?f) ?i (?h : ?t) -> ?f ?i (fold (?f) ?h ?t); -fold false (?f) ?i ?l -> fold (?f) ?i ?l; - - -factorial (s (0)) -> s (0); -factorial (s ?x) -> (s ?x) * (factorial ((s ?x) - 1)); - - -sum (?h : ?t) -> fold (add) (0) (?h : ?t); - - -range ?x (s (0)) -> ?x : (nil); -range ?x (s ?y) -> ?x : (range (?x + 1) ((s ?y) - 1)); - - -Disgusting (yet valid) hack for currying. -We need lambdas. ; - -unpack (?h : nil) -> ?h; -unpack (?h : ?t) -> ?h unpack ?t; -unpack (?x) -> ?x; -unpack (?x . -> ?x unpack (; - - -:: (?f) ?a -> ?f unpack ?a; - - -mapp (?f) ?a (nil) -> nil; -mapp (?f) ?a (?h : (nil)) -> (?f unpack ?a ?h) : (nil); -mapp (?f) ?a (?h : ?t) -> (?f unpack ?a ?h) : (mapp (?f) ?a ?t); - - -map (?f) (nil) -> nil; -map (?f) (?h : nil) -> (?f ?h) : (nil); -map (?f) (?h : ?t) -> (?f ?h) : (map (?f) ?t); - - -product ?x -> fold (mul) 1 ?x; - - -factorial2 ?x -> product (range 1 ?x); - - -contains ?x (nil) -> false; -contains ?x (?x : ?t) -> true; -contains ?x (?h : ?t) -> contains ?x ?t; - - -unique (nil) -> nil; -unique false (?h : ?t) -> ?h : (unique ?t); -unique true (?h : ?t) -> unique ?t; -unique (?h : ?t) -> unique contains ?h ?t (?h : ?t); - - -length (nil) -> 0; -length (?h : ?t) -> s (length ?t); - - -zipWith (?f) (nil) (nil) -> nil; -zipWith (?f) (?h : ?t) (nil) -> nil; -zipWith (?f) (nil) (?h : ?t) -> nil; -zipWith (?f) (?h1 : ?t1) (?h2 : ?t2) -> (?f ?h1 ?h2) : (zipWith (?f) ?t1 ?t2); - - -evens ?x -> zipWith (add) (range (0) ?x) (range (0) ?x); - - -not (not ?x) -> ?x; -not true -> false; -not false -> true; - - -any ?x -> contains true ?x; - - -all ?x -> not contains false ?x; - - -none ?x -> not any ?x; - - -add1 ?x -> add ?x 1; - - -square ?x -> ?x * ?x; - - -reduce (s ?x) -> s (reduce ?x); -reduce (0) -> (0); -reduce (?h : ?t) -> ?h : (reduce ?t); -reduce (nil) -> nil; diff --git a/examples/prelude2.modal b/examples/prelude2.modal deleted file mode 100644 index c24bd29..0000000 --- a/examples/prelude2.modal +++ /dev/null @@ -1,141 +0,0 @@ -define [-- ?x] {} - -define [form ?x ?y] { - define ?x ?y -} - -define [rule ?x ?y] { - define ?x ?y -} - -define [?x -> ?y] { - define ?x ?y -} - -[(?x) = (?x)] -> { - true -} - -[(?x) = (?y)] -> { - false -} - -[false or false] -> { - false -} - -[true or false] -> { - true -} - -[false or true] -> { - true -} - -[true or true] -> { - true -} - -[quote ?x] -> { - quote ?x -} - -[unquote (quote ?x)] -> { - ?x -} - -form [ - if ?condition - ?true - else - ?false -] -{ - if/else ?condition { - quote ?true - } { - quote ?false - } -} - -form [ - if ?condition - ?branch -] -{ - if/q ?condition { - quote ?branch - } -} - -rule [ - if/q (true) - ?branch -] -{ - unquote ?branch -} - -rule [ - if/q (false) - ?branch -] -{} - -rule [ - if/else (true) - ?true - ?false -] -{ - unquote ?true -} - -rule [ - if/else (false) - ?true - ?false -] -{ - unquote ?false -} - - -[factorial (?x)] -> { - if ((?x) = (1)) { - 1 - } - else { - ?x * factorial (?x - 1) - } -} - -[fibonacci (?number)] -> { - if((?number) = (0) or (?number) = (1)) { - ?number - } - else { - fibonacci (?number - 1) + fibonacci (?number - 2) - } -} - -[range (?low) (?high)] -> { - if((?low) = (?high + 1)) { - nil - } - else { - ?low : range (?low + 1) (?high) - } -} - -[fold (?operation) (?initial) (nil)] -> { - ?initial -} - -[fold (?operation) (?initial) (?head : ?tail)] -> { - ?operation ?head (fold (?operation) (?initial) ?tail) -} - -[sum ?list] -> { - fold (add) (0) ?list -} diff --git a/examples/string_reverse.modal b/examples/string_reverse.modal new file mode 100644 index 0000000..c784360 --- /dev/null +++ b/examples/string_reverse.modal @@ -0,0 +1,5 @@ +<> (reverse List () ?*) (?*) +<> (reverse (?*)) (reverse List (?*) ()) +<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z)) + +(reverse (modal)) \ No newline at end of file