about summary refs log tree commit diff stats
path: root/lambda-to-mu.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-07-22 14:15:24 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-07-22 14:15:24 -0700
commit1813abc696b741ec651f106e393eadeba157578d (patch)
treeb3e25d5b92e115300671c63bb49be63dfd0e9d13 /lambda-to-mu.mu
parent4cb5b56763461373b59902f8f653cb15ded79585 (diff)
downloadmu-1813abc696b741ec651f106e393eadeba157578d.tar.gz
3127
Diffstat (limited to 'lambda-to-mu.mu')
-rw-r--r--lambda-to-mu.mu43
1 files changed, 43 insertions, 0 deletions
diff --git a/lambda-to-mu.mu b/lambda-to-mu.mu
index 855137bf..bfdc0e9d 100644
--- a/lambda-to-mu.mu
+++ b/lambda-to-mu.mu
@@ -81,3 +81,46 @@ scenario pair-is-not-atom [
     11 <- 1
   ]
 ]
+
+def first x:address:cell -> result:address:cell [
+  local-scope
+  load-ingredients
+  pair:pair, pair?:boolean <- maybe-convert *x, pair:variant
+  reply-unless pair?, 0/nil
+  result <- get pair, first:offset
+]
+
+def rest x:address:cell -> result:address:cell [
+  local-scope
+  load-ingredients
+  pair:pair, pair?:boolean <- maybe-convert *x, pair:variant
+  reply-unless pair?, 0/nil
+  result <- get pair, rest:offset
+]
+
+scenario cell-operations-on-atom [
+  local-scope
+  s:address:array:character <- new [a]
+  x:address:cell <- new-atom s
+  10:address:cell/raw <- first x
+  11:address:cell/raw <- rest x
+  memory-should-contain [
+    10 <- 0  # first is nil
+    11 <- 0  # rest is nil
+  ]
+]
+
+scenario cell-operations-on-pair [
+  local-scope
+  # construct (a . nil)
+  s:address:array:character <- new [a]
+  x:address:cell <- new-atom s
+  y:address:cell <- new-pair x, 0/nil
+  x2:address:cell <- first y
+  10:boolean/raw <- equal x, x2
+  11:address:cell/raw <- rest y
+  memory-should-contain [
+    10 <- 1  # first is correct
+    11 <- 0  # rest is nil
+  ]
+]