Skip to content

Commit

Permalink
Merge pull request #21 from DestyNova/main
Browse files Browse the repository at this point in the history
Fix broken table rendering in pandoc + add another example of partial application shorthand
  • Loading branch information
razetime authored Feb 3, 2024
2 parents d74ab0e + 8599e5b commit b2dd4d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 04-index-apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ To fix this, we should instead pass `a` via projection:

as compared to assigning to `a` globally (`f:{a::x;{a+y}}`), this keeps data within the function, and makes the function side-effect free. This is not only useful in K, but helps for any programming task in general.

We can also express this using the shorthand for partial application:

```
f:{a:x;+[a;]}[1]
f[3]
4
```

Now, if you remember from the beginning of this chapter, functions, arrays and dictionaries are all treated the same way in K. So projections can *also* apply to arrays and dictionaries!

Expand All @@ -197,7 +204,7 @@ For an array, a projection will take all elements from the nth dimension of an a
1 4 7
```

For dictonaries, it will index into each nested dictionary within, and pull out the respective values:
For dictionaries, it will index into each nested dictionary within, and pull out the respective values:
```
(1 2 3!(3#,1 2 3!4 5 6))[;2]
1 2 3!5 5 5
Expand Down
1 change: 1 addition & 0 deletions 06-numbers-and-logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ signify the absence of a value, and generally denote a special value in a given
where null values are found are in indexing, where an out of bounds index returns a null value, and in find.

**Null Values for each data type**

| Type | Null |
| ---- | ---- |
|Integer | `0N` |
Expand Down

0 comments on commit b2dd4d4

Please sign in to comment.