From 6605baf33d58d5cd469c5f2747598c553921de4d Mon Sep 17 00:00:00 2001 From: nodist Date: Thu, 18 Jun 2026 13:43:47 -0400 Subject: char iterator example --- letter_table.kpl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 letter_table.kpl (limited to 'letter_table.kpl') diff --git a/letter_table.kpl b/letter_table.kpl new file mode 100644 index 0000000..29856b0 --- /dev/null +++ b/letter_table.kpl @@ -0,0 +1,26 @@ + +// Read a utf8 string and count all the occurrences of each letter found + +`export letter_table : ([string] + table : Map[Char; U64] $ () + @ string {[letter] + ? table `has letter { + ^ table `get letter {[count] count +: 1 } + } { + table `set (letter; 1) + } + } + table +) + +`is_main ([] + `use "sys" [args] + ? 3 != `length args { + `return `error String $ ( + "#BOLD#RED#Got: %#\n" `format " " `join args + "#BOLD#WHITE#Usage: % % #\n" `format (args `get 0; args `get 1) + ) + } + `use "file" [open; read] + `log letter_table `sync String $ read `sync open `sync args `get -1 +) -- cgit v1.2.3