|
1 | 1 | # Dictionaries, Tables, Strings and other Miscellaneous functions
|
2 | 2 |
|
3 |
| -Dictionaries and strings are not highly related, just that this chapter aims to show the rest of the verbs we have not covered in K, which happen to be mainly relating to dictionaries and strings. Think of it as a rapid-fire explanation of |
| 3 | +Dictionaries and strings are not highly related, just that this chapter aims to show the rest of the verbs we have not covered in K, |
| 4 | +which happen to be mainly relating to dictionaries and strings. Think of it as a rapid-fire explanation of their quirks. |
4 | 5 |
|
5 | 6 | ## Dictionary Trivia
|
6 |
| -Dictionaries are an *ordered collection*. this means that many primitives which work on arrays work similarly on dictionaries. This includes: |
| 7 | +Dictionaries are an *ordered collections*. This means that many primitives which work on arrays work similarly on dictionaries. This includes: |
7 | 8 |
|
8 | 9 | - concat `,` (values in `y` overwrite values in `x`)
|
9 | 10 | - reverse `|` (reverses key array and value array separately)
|
10 | 11 | - map `'` (applies on values)
|
11 | 12 | - first `*` (first value from key-value pair only)
|
12 | 13 | - not `~`
|
| 14 | +- at `@` preserves the structure of the dictionary when given as the second argument. |
13 | 15 | - filter `#` and filter-out `_` (filter by value)
|
14 | 16 | - where `&` (keys are repeated by values)
|
15 | 17 | - grade up `<` and grade down `>` (sort keys by values)
|
@@ -120,6 +122,8 @@ Finally, `0N?x` where `x` is an array will shuffle `x`. If `x` is a number, then
|
120 | 122 | #### Base Decode and Encode (`\` and `/`)
|
121 | 123 |
|
122 | 124 | ngn/k's base conversion adverbs are generalized: this means that you can do mixed-radix conversion and other cool things.
|
| 125 | +These adverbs will be familiar to APL programmers. Remember that these are adverbs, and not verbs. Some things you do with them may not work exactly as |
| 126 | +expected. |
123 | 127 |
|
124 | 128 | The simplest use, and the most often use for this, is conversion to and from base 2:
|
125 | 129 |
|
@@ -184,10 +188,17 @@ Monadic `.` when given a string is eval. This will evaluate any string as K code
|
184 | 188 | 3
|
185 | 189 | ```
|
186 | 190 |
|
187 |
| -Dyadic `:` is right. it returns its right argument. `:` has many special meanings , so it is better to call |
| 191 | +Dyadic `:` is right. it returns its right argument. `:` has many special meanings, so it is required to call |
188 | 192 | `:` with an M-Expression:
|
189 | 193 |
|
190 | 194 | ```
|
191 | 195 | :[1 2; 3 4]
|
192 | 196 | 3 4
|
193 | 197 | ```
|
| 198 | + |
| 199 | +*no new vocabulary for this chapter.* |
| 200 | + |
| 201 | +## Exercises |
| 202 | +1. Write a function to convert seconds into hours, minutes and seconds, using `\`. |
| 203 | +2. Write a function that takes a list of numbers `x` and a number `y`. Group the numbers in `x` into a dictionary based on whether they are multiples |
| 204 | + of `y`. `f[1 3 5 9;3]` -> `(0;1)!(1 5;3 9)` |
0 commit comments