From 166c9d488992a0d14e150b5db9448d508d2ccf8c Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 5 Jul 2021 01:14:39 -0400 Subject: [PATCH] Add simple 'switch' implemented in pbl --- src/examples/lib.pbl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/examples/lib.pbl b/src/examples/lib.pbl index 91c7782..e85b374 100644 --- a/src/examples/lib.pbl +++ b/src/examples/lib.pbl @@ -18,3 +18,15 @@ ; Return the smaller of the two (def min (fn (a b) (if (< a b) a b))) + +(def switch (fn (pair_list) + (if (= 0 (len pair_list)) + "no match" + ( + (def _pair (at 0 pair_list)) + (if (at 0 _pair) + (at 1 _pair) + (switch (rest pair_list)) + ) + )) +))