Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed May 31, 2024
1 parent 4739369 commit 930bfa9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 54 deletions.
18 changes: 9 additions & 9 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

```nk
: next_fib dup sum swap -1 [] swap 2 cat ;
: fib [ 0 1 ] swap next_fib' power 0 [] ;
: fib [ 0 1 ] swap next_fib' ,power 0 [] ;
```

```nkt
> [ 1 1 ] next_fib .
[ 1 2 ]
> [ 1 2 ] next_fib .
[ 2 3 ]
> [ 1 1 ] 10 next_fib' power .
> [ 1 1 ] 10 next_fib' ,power .
[ 89 144 ]
> 10 fib .
55
Expand All @@ -59,9 +59,9 @@ single iteration: `x1=x-f(x)/f'(x)` in this case is `x=x-(x^2-2)/2x`:
1.5
> 1.5 sqrt2_step .
1.41666666666667
> 1. 3 sqrt2_step' power .
> 1. 3 sqrt2_step' ,power .
1.41421568627451
> 1. 10 sqrt2_step' power .
> 1. 10 sqrt2_step' ,power .
1.41421356237309
```

Expand All @@ -81,8 +81,8 @@ $p_n < n(log n + log log n), n>=6$

```nk
: prime_upper_bound dup log log over log + * ceil ;
: prime dup prime_upper_bound index 2 + swap 1 - next_prime' power head ;
: primes dup prime_upper_bound index 2 + swap 1 - next_prime' trace head' apply ;
: prime dup prime_upper_bound index 2 + swap 1 - next_prime' ,power head ;
: primes dup prime_upper_bound index 2 + swap 1 - next_prime' ,trace head' ,apply ;
```

```nkt
Expand All @@ -105,9 +105,9 @@ $p_n < n(log n + log log n), n>=6$
### Conditional execution

```nkt
> 10 0 cos' power .
> 10 0 cos' ,power .
10
> 10 1 cos' power .
> 10 1 cos' ,power .
-0.839071529076452
```

Expand All @@ -125,7 +125,7 @@ $p_n < n(log n + log log n), n>=6$
### Problem 2

```nk
: fibs [ 0 1 ] swap next_fib' trace head' apply ;
: fibs [ 0 1 ] swap next_fib' ,trace head' ,apply ;
```

```nkt
Expand Down
16 changes: 6 additions & 10 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,12 @@ Words that starts from '\' are indended to be used during development

|Word|Signature|Description|
|---|---|---|
|`fold`|`(x op' -> y)`| fold cells of rank `0` using `op`|
|`fold[]`|`(x r op' -> y)`| fold cells of rank `r` using `op`|
|`scan`|`(x op' -> y)`| fold cells of rank `0` using `op` organizing all intermediate results in `x`'s shape|
|`scan[]`|`(x r op' -> y)`| fold cells of rank `r` using `op` organizing all intermediate results in `x`'s shape|
|`apply`|`(x r op' -> y)`| applies `op` to cells of rank `0` organizing results into `x`'s shape|
|`apply[]`|`(x r op' -> y)`| applies `op` to cells of rank `r` organizing results into `x`'s shape|
|`power`|`(x n op' -> y)`|applies `op` `n` times to `x`|
|`trace`|`(x s op' -> y)`|applies `op` multiple times to `x` and organizes intermediate results into `s` shape|
|`pairwise`|`(x op' -> y)`| applies `op` to consequent pais of `x` leaving first element unchanged|
|`pairwise[]`|`(x r op' -> y)`| applies `op` to consequent pais of cells of rank `r` leaving first element unchanged|
|`,fold`|`(x op' -> y)`| ,fold cells of rank `0` using `op`|
|`,scan`|`(x op' -> y)`| ,fold cells of rank `0` using `op` organizing all intermediate results in `x`'s shape|
|`,apply`|`(x r op' -> y)`| applies `op` to cells of rank `0` organizing results into `x`'s shape|
|`,power`|`(x n op' -> y)`|applies `op` `n` times to `x`|
|`,trace`|`(x s op' -> y)`|applies `op` multiple times to `x` and organizes intermediate results into `s` shape|
|`,pairwise`|`(x op' -> y)`| applies `op` to consequent pais of `x` leaving first element unchanged|

## Input/Output

Expand Down
6 changes: 3 additions & 3 deletions src/prelude.nk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

: swap- swap - ;

: sum +' fold ;
: sums +' scan ;
: deltas swap-' pairwise ;
: sum +' ,fold ;
: sums +' ,scan ;
: deltas swap-' ,pairwise ;

2.7182818284590452354 const E
1.4426950408889634074 const LOG2E
Expand Down
12 changes: 6 additions & 6 deletions src/words.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ DEF_WORD("\\s", slash_stack) { DO(i, stack_len(stack)) fprintf(inter->out, "%ld:

#pragma region adverbs

DEF_WORD("fold", fold_cell) {
DEF_WORD(",fold", fold) {
POP(op);
POP(x);

Expand All @@ -540,7 +540,7 @@ DEF_WORD("fold", fold_cell) {
array_for_each_atom(x, __iter);
}

DEF_WORD("scan", scan) {
DEF_WORD(",scan", scan) {
POP(op);
POP(x);

Expand All @@ -556,7 +556,7 @@ DEF_WORD("scan", scan) {
PUSH(result);
}

DEF_WORD("apply", apply_cell) {
DEF_WORD(",apply", apply) {
POP(op);
POP(x);

Expand All @@ -570,7 +570,7 @@ DEF_WORD("apply", apply_cell) {
PUSH(result);
}

DEF_WORD("pairwise", pairwise_cell) {
DEF_WORD(",pairwise", pairwise) {
POP(op);
POP(x);

Expand All @@ -587,15 +587,15 @@ DEF_WORD("pairwise", pairwise_cell) {
PUSH(result);
}

DEF_WORD("power", power) {
DEF_WORD(",power", power) {
POP(op);
POP(n);

t_dict_entry e = as_dict_entry(op);
DO(i, as_size_t(n)) { inter_dict_entry(inter, e); }
}

DEF_WORD("trace", trace) {
DEF_WORD(",trace", trace) {
POP(op);
POP(x);

Expand Down
4 changes: 2 additions & 2 deletions tests/inter.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ ERROR: unbalanced ]
[ 100 101 102 103 104 105 106 107 108 109 ]
> : centigrade 32 - 5 * 9. / ; 72 centigrade .
22.2222222222222
> : test_sum +' fold ;
> : test_sum +' ,fold ;
> 10 index test_sum .
45
> : sums +' scan ;
> : sums +' ,scan ;
> 10 index sums .
[ 0 1 3 6 10 15 21 28 36 45 ]
> : test_1. 1. ;
Expand Down
20 changes: 10 additions & 10 deletions tests/prelude.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@
```

# higher order words
## fold
## ,fold

```nkt
> 10 index +' fold .
> 10 index +' ,fold .
45
> 10000 ones +' fold .
> 10000 ones +' ,fold .
10000
> 10 index 1 + *' fold .
> 10 index 1 + *' ,fold .
3628800
```

## scan
## ,scan

```nkt
> 10 index +' scan .
> 10 index +' ,scan .
[ 0 1 3 6 10 15 21 28 36 45 ]
> 1000 ones +' scan +' fold .
> 1000 ones +' ,scan +' ,fold .
500500
> 10 index 0. + +' scan .
> 10 index 0. + +' ,scan .
[ 0. 1. 3. 6. 10. 15. 21. 28. 36. 45. ]
```

## pairwise
## ,pairwise

```nkt
> 10 index +' pairwise .
> 10 index +' ,pairwise .
[ 0 1 3 5 7 9 11 13 15 17 ]
```

Expand Down
28 changes: 14 additions & 14 deletions tests/words.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,57 +457,57 @@ types:

## higher order words

### fold
### ,fold

```nkt
> 24 index +' fold .
> 24 index +' ,fold .
276
```

### scan
### ,scan

```nkt
> 24 index +' scan .
> 24 index +' ,scan .
[ 0 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 231 253 276 ]
```

### apply

```nkt
> 5 index index' apply .
> 5 index index' ,apply .
[ [ ] [ 0 ] [ 0 1 ] [ 0 1 2 ] [ 0 1 2 3 ] ]
> : head 0 [] ;
> [ [ 1 1. ] [ 2 2. ] ] head' apply .
> [ [ 1 1. ] [ 2 2. ] ] head' ,apply .
[ 1 2 ]
```

### pairwise
### ,pairwise

```nkt
> : -neg - neg ;
> [ 0 1 1 0 1 0 ] -neg' pairwise . \s
> [ 0 1 1 0 1 0 ] -neg' ,pairwise . \s
[ 0 1 0 -1 1 -1 ]
> 24 index -neg' pairwise . \s
> 24 index -neg' ,pairwise . \s
[ 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ]
```

### power
### ,power

```nk
: 2* 2 * ;
```

```nkt
> 1 10 2*' power .
> 1 10 2*' ,power .
1024
> [ 1 2 ] 10 2*' power .
> [ 1 2 ] 10 2*' ,power .
[ 1024 2048 ]
```

### trace
### ,trace

```nkt
> 1 10 2*' trace .
> 1 10 2*' ,trace .
[ 2 4 8 16 32 64 128 256 512 1024 ]
```

Expand Down

0 comments on commit 930bfa9

Please sign in to comment.