aboutsummaryrefslogtreecommitdiffstats
path: root/testcases-cons
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-16 21:43:08 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-16 21:43:08 -0700
commit08a6a0d241335e37bb5ff1b4f0007ed924b6ff48 (patch)
treeca81f967c0f8e5e8d3b211777209f4b88aa1cca4 /testcases-cons
parentc959e1622732a6cc32ed23575764dcbdf0e9d63e (diff)
downloadcppawk-08a6a0d241335e37bb5ff1b4f0007ed924b6ff48.tar.gz
cppawk-08a6a0d241335e37bb5ff1b4f0007ed924b6ff48.tar.bz2
cppawk-08a6a0d241335e37bb5ff1b4f0007ed924b6ff48.zip
cons: push, pop: document, test.
Diffstat (limited to 'testcases-cons')
-rw-r--r--testcases-cons29
1 files changed, 29 insertions, 0 deletions
diff --git a/testcases-cons b/testcases-cons
index 4dc2788..c80bb5d 100644
--- a/testcases-cons
+++ b/testcases-cons
@@ -799,3 +799,32 @@ BEGIN {
(1 2 3 . 4)
(2 3 . 4)
(3 . 4)
+--
+42:
+$cppawk '
+#include <cons.h>
+
+function rev(li,
+ out)
+{
+ out = nil
+
+ while (!endp(li))
+ push(pop(li), out)
+
+ return out
+}
+
+BEGIN {
+ print sexp(rev(list(1, 2, 3)));
+ x = nil
+ print sexp(pop(x))
+ x = cons(3, 4)
+ print sexp(pop(x))
+ print x
+}'
+:
+(3 2 1)
+nil
+3
+4