aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples
diff options
context:
space:
mode:
authorMarvin Borner2024-02-21 20:28:55 +0100
committerMarvin Borner2024-02-21 22:25:09 +0100
commitc9b30f99992c98745d52807f5e45a12f6aee2c5f (patch)
tree68eaf084eaed2ae515e62fb9c55d52836a327b24 /samples
parent241315c452b1b06e4b9721cf336d9ab150f7234d (diff)
Additions for Rosetta Code
Diffstat (limited to 'samples')
-rw-r--r--samples/rosetta/empty_program.bruijn1
-rw-r--r--samples/rosetta/universal_lambda_machine.bruijn19
2 files changed, 20 insertions, 0 deletions
diff --git a/samples/rosetta/empty_program.bruijn b/samples/rosetta/empty_program.bruijn
new file mode 100644
index 0000000..42e2f47
--- /dev/null
+++ b/samples/rosetta/empty_program.bruijn
@@ -0,0 +1 @@
+main [0]
diff --git a/samples/rosetta/universal_lambda_machine.bruijn b/samples/rosetta/universal_lambda_machine.bruijn
new file mode 100644
index 0000000..2f003ce
--- /dev/null
+++ b/samples/rosetta/universal_lambda_machine.bruijn
@@ -0,0 +1,19 @@
+:import std/Combinator .
+:import std/Number/Binary .
+:import std/Meta .
+:import std/List .
+
+# converts string to list of bits
+str→blc map (c ∘ lsb)
+
+:test (str→blc "0010") ([[1]] : ([[1]] : ([[0]] : {}[[1]])))
+
+# converts list of bits to string
+blc→str map [0 '0' '1']
+
+:test (blc→str ([[1]] : ([[1]] : ([[0]] : {}[[1]])))) ("0010")
+
+# reduces BLC string to BLC string
+main str→blc → blc→meta → β* → meta→blc → blc→str
+
+:test (main "0010") ("0010")