aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/fib.c50
-rw-r--r--examples/strfib.c53
2 files changed, 50 insertions, 53 deletions
diff --git a/examples/fib.c b/examples/fib.c
new file mode 100644
index 0000000..0c94673
--- /dev/null
+++ b/examples/fib.c
@@ -0,0 +1,50 @@
+#include <csx.h>
+#include <stdio.h>
+
+
+static csx_list_fn *l;
+static csx_num_fn *n;
+
+char *define;
+char *fn;
+char *pair;
+char *head;
+char *tail;
+char *not;
+char *csx_if;
+char *inc;
+char *sum;
+char *diff;
+
+void process()
+{
+ char *fib = csx_name("fib");
+ char *num = csx_name("num");
+ csx_eval(l(define, fib, l(fn, l(num, 0),
+ l(csx_if, l(inc, num, n(2), 0), n(1),
+ l(sum,
+ l(fib, l(diff, num, n(1), 0), 0),
+ l(fib, l(diff, num, n(2), 0), 0),
+ 0),
+ 0),
+ 0), 0));
+ printf("fib 6 = %d\n", *(int *)csx_eval(l(fib, n(6), 0)));
+}
+
+int main()
+{
+ l = csx_list;
+ n = csx_num;
+ define = csx_name("define");
+ fn = csx_name("fn");
+ pair = csx_name("pair");
+ head = csx_name("head");
+ tail = csx_name("tail");
+ not = csx_name("not");
+ csx_if = csx_name("if");
+ inc = csx_name("inc");
+ sum = csx_name("sum");
+ diff = csx_name("diff");
+ process();
+ return 0;
+}
diff --git a/examples/strfib.c b/examples/strfib.c
deleted file mode 100644
index 6e22c7f..0000000
--- a/examples/strfib.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <csx/csx.h>
-#include <stdio.h>
-
-
-static csx_type_function_list *l;
-static csx_type_function_string *s;
-static csx_type_function_atom *a;
-static csx_type_function_evaluate *e;
-
-static char *append;
-static char *define;
-static char *cdr;
-static char *ifx;
-static char *not;
-
-void printfibs(char *strfib)
-{
- const char *input = "oooooooooo" + 9;
- int i;
- for (i = 0; i != 10; ++i)
- puts(e(l(strfib, s(input - i), 0)));
-}
-
-void process()
-{
- char *strfib = a("strfib");
- char *n = a("n");
- e(l(define, l(strfib, n, 0),
- l(ifx, l(not, n, 0), s(""),
- l(ifx, l(not, l(cdr, n, 0), 0), s("o"),
- l(append, l(strfib, l(cdr, n, 0), 0),
- l(strfib, l(cdr, l(cdr, n, 0), 0), 0), 0),
- 0),
- 0),
- 0));
- printfibs(strfib);
-}
-
-int main()
-{
- l = csx_list;
- s = csx_string;
- a = csx_atom;
- e = csx_evaluate;
- append = a("append");
- define = a("define");
- cdr = a("cdr");
- ifx = a("ifx");
- not = a("not");
- process();
- csx_free();
- return 0;
-}