diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-06-18 13:43:47 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-06-18 13:43:47 -0400 |
| commit | 6605baf33d58d5cd469c5f2747598c553921de4d (patch) | |
| tree | 9ef0fb9653b0a0cfde93d109e285803ebc878f4b | |
| parent | 3e5334df0e830c2b143a807ffe5b866a08b6f3d4 (diff) | |
char iterator example
| -rw-r--r-- | fib_import.kpl | 2 | ||||
| -rw-r--r-- | letter_table.kpl | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/fib_import.kpl b/fib_import.kpl index 75bfe48..6f4e055 100644 --- a/fib_import.kpl +++ b/fib_import.kpl @@ -1,7 +1,7 @@ // Import and run fib_string function -`use "io" [write; stdout] +`use "file" [write; stdout] `import "./fib.kpl" [fib_string] @ 0 .. 30 {[n] 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: % % <file>#\n" `format (args `get 0; args `get 1) + ) + } + `use "file" [open; read] + `log letter_table `sync String $ read `sync open `sync args `get -1 +) |
