From 48aca48d1f2cbe0d4f7ed1036409b7c64dc31d75 Mon Sep 17 00:00:00 2001 From: Nakidai Date: Tue, 8 Apr 2025 14:58:46 +0300 Subject: Add cnt.ccl example --- examples/cnt.ccl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/cnt.ccl (limited to 'examples/cnt.ccl') diff --git a/examples/cnt.ccl b/examples/cnt.ccl new file mode 100644 index 0000000..f700aad --- /dev/null +++ b/examples/cnt.ccl @@ -0,0 +1,30 @@ +^++=t/wo + +c/ount elements on the stack but more complicated / end [... elem] start -- end [... elem] count +{ + + / increment counter + %t / get last elem + E? / if it's end then stop counting + %t / reverse back + # + ; + + &e=e / pop elem saving + @c / end [...] start+1 + $e%t / reverse back +} + +C/ount elements on the stack / [elem ...] -- [elem ...] elem-count +{ + $E / push end on the stack + %_ / reverse the stack + ^- @c / count elements + &c=c / save count + %_ / reverse back + =_ / get rid of end + $c / push count back +} + +^-=E / end of count +^^^^^ +@C -- cgit 1.4.1