Updating examples
This commit is contained in:
parent
77046e2645
commit
d22ed88f6e
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -1,3 +0,0 @@
|
|||
<> ((send ?:)) ()
|
||||
|
||||
(send (hello world))
|
|
@ -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))
|
|
@ -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
|
||||
\nthen, you continued: read stdin
|
||||
\nfinaly, you concluded: read stdin \n) print
|
|
@ -0,0 +1,3 @@
|
|||
<> (send ?:) (?:)
|
||||
|
||||
send (hello world)
|
|
@ -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)
|
|
@ -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;
|
|
@ -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
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<> (reverse List () ?*) (?*)
|
||||
<> (reverse (?*)) (reverse List (?*) ())
|
||||
<> (reverse List (?x ?y) ?z) (reverse List ?y (?x ?z))
|
||||
|
||||
(reverse (modal))
|
Loading…
Reference in New Issue