summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-11-03 20:55:01 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-11-03 20:55:01 +0100
commit877a1dbf7c9cd2901a7f5de175afca1b45df2956 (patch)
treea93e8302c569efa247c0da7562ac11bd96bc5e36
parent121afda5a559ed39c42060697fe39e736e3383d9 (diff)
downloadmew-877a1dbf7c9cd2901a7f5de175afca1b45df2956.tar.gz
mew-877a1dbf7c9cd2901a7f5de175afca1b45df2956.tar.xz
mew-877a1dbf7c9cd2901a7f5de175afca1b45df2956.zip
prn: return value of last argument
Hat tip to Tom Lord, who called this `peek`.
-rw-r--r--mew.scm18
-rw-r--r--mew.svnwiki2
-rw-r--r--tests/test.mew3
3 files changed, 14 insertions, 9 deletions
diff --git a/mew.scm b/mew.scm
index 78c6558..0383116 100644
--- a/mew.scm
+++ b/mew.scm
@@ -126,13 +126,17 @@
         (for-each display args))))
 
   (define (prn . args)
-    (if (null? args)
-      (newline)
-      (begin
-        (write (car args))
-        (unless (null? (cdr args))
-          (display " "))
-        (apply prn (cdr args)))))
+    (let loop ((args args)
+               (ret (void)))
+      (if (null? args)
+        (begin
+          (newline)
+          ret)
+        (begin
+          (write (car args))
+          (unless (null? (cdr args))
+            (display " "))
+          (loop (cdr args) (car args))))))
 
   (define-syntax def
     (syntax-rules ()
diff --git a/mew.svnwiki b/mew.svnwiki
index a4916ef..142fb2a 100644
--- a/mew.svnwiki
+++ b/mew.svnwiki
@@ -223,7 +223,7 @@ Returns true if {{<va>}} is an unspecified value, else false.
 <procedure>(prn . <args>)</procedure>
 
 {{write}} all {{args}} separated by spaces and terminated by a newline
-to the current output stream.
+to the current output stream.  Returns the value of the last argument.
 
 <procedure>(puts . <args>)</procedure>
 
diff --git a/tests/test.mew b/tests/test.mew
index 82c793a..82a2e71 100644
--- a/tests/test.mew
+++ b/tests/test.mew
@@ -93,7 +93,8 @@
 (test-group "prn"
   (test "1 2 3\n" (with-output-to-string (fun () (prn 1 2 3))))
   (test "\"a\" b #t\n" (with-output-to-string (fun () (prn "a" 'b #t))))
-  (test "\n" (with-output-to-string (fun () (prn)))))
+  (test "\n" (with-output-to-string (fun () (prn))))
+  (test 3 (esc ret (with-output-to-string (fun () (ret (prn 1 2 3)))))))
 
 (test-group "def"
   (test "define variable"