From 7b7bf727da3250907284368b98b0083a4b4e2386 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 3 Jun 2023 20:22:18 +0000 Subject: initial commit --- p99/p18.neb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 p99/p18.neb (limited to 'p99/p18.neb') diff --git a/p99/p18.neb b/p99/p18.neb new file mode 100644 index 0000000..7ccf0b7 --- /dev/null +++ b/p99/p18.neb @@ -0,0 +1,27 @@ +; P18 Extract a slice from a list. +; Given two indices, I and K, the slice is the list containing the elements between the +; I'th and K'th element of the original list (both limits included). Start counting the elements with 1. + +(def a (list "a" "b" "c" "d" "e" "f" "g" "h" "i" "k")) + +(func my-slice (lst idx1 idx2) + (my-slice lst idx1 idx2 (list))) + +(func my-slice (lst :nil idx1 idx2 acc) acc) + +(func my-slice (lst :{:any} idx1 idx2 acc) + (my-slice + (rest lst) + (-- idx1) + (-- idx2) + (if + (or + (> idx1 1) + (< idx2 1)) + acc + (append acc (first lst))))) + +(func -- (num) (- num 1)) + +(print (->string a)) +(print (->string (my-slice a 3 7))) -- cgit v1.2.3