aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-03-27 11:48:57 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-03-27 11:48:57 +0300
commitdf110a9bee56548770a7256845e0d1b84a959972 (patch)
tree431bc78354e1ab264922e0c2c6419405a4227083 /examples
parent860b7939b067102e01acbad9ef3effd48b4bf5af (diff)
downloadcsx-df110a9bee56548770a7256845e0d1b84a959972.tar
csx-df110a9bee56548770a7256845e0d1b84a959972.tar.xz
csx-df110a9bee56548770a7256845e0d1b84a959972.zip
Ackermann function example added.
Diffstat (limited to 'examples')
-rw-r--r--examples/ackermann.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/ackermann.c b/examples/ackermann.c
new file mode 100644
index 0000000..08acd4d
--- /dev/null
+++ b/examples/ackermann.c
@@ -0,0 +1,25 @@
+#include <csxbind.h>
+#include <stdio.h>
+
+
+int main()
+{
+ init();
+ char *m = N("m");
+ char *n = N("n");
+ char *ackermann = N("ackermann");
+ printf("%d\n", *(int *)R(L(_do,
+ L(set, ackermann, L(fn, L(m, n, 0),
+ L(_if,
+ L(same, m, I(0), 0), L(_plus, n, I(1), 0),
+ L(same, n, I(0), 0), L(ackermann, L(_plus, m, I(-1), 0), I(1), 0),
+ L(ackermann,
+ L(_plus, m, I(-1), 0),
+ L(ackermann, m, L(_plus, n, I(-1), 0), 0),
+ 0),
+ 0),
+ 0), 0),
+ L(ackermann, I(3), I(7), 0),
+ 0)));
+ return 0;
+}