OSDN Git Service

joy-first
authorsforman <sforman@hushmail.com>
Sat, 21 Oct 2023 18:10:36 +0000 (11:10 -0700)
committersforman <sforman@hushmail.com>
Sat, 21 Oct 2023 18:10:36 +0000 (11:10 -0700)
implementations/scheme-chicken/joy.scm

index 919257f..0008d2b 100644 (file)
@@ -80,8 +80,8 @@
 
     ((concat) (joy-func append stack expression dict))
     ((cons) (joy-func cons stack expression dict))
-    ((first) (values (cons (caar stack) (cdr stack)) expression dict))
-    ((rest)  (values (joy-rest stack) expression dict))
+    ((first) (values (joy-first stack) expression dict))
+    ((rest)  (values (joy-rest  stack) expression dict))
 
     ((i) (joy-i stack expression dict))
     ((dip) (joy-dip stack expression dict))
       (abort "Cannot take rest of empty list.")
       (cons (cdr el) stack))))
 
+(define (joy-first stack0)
+  (receive (el stack) (pop-list stack0)
+    (if (null-list? el)
+      (abort "Cannot take first of empty list.")
+      (cons (car el) stack))))
+
 
 (define (pop-any stack)
   (if (null-list? stack)