From 930bfa94e97dc53d74e5e8142bab80335b2a7d6b Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Thu, 30 May 2024 20:45:07 -0700 Subject: [PATCH] renames --- docs/examples.md | 18 +++++++++--------- docs/reference.md | 16 ++++++---------- src/prelude.nk | 6 +++--- src/words.c | 12 ++++++------ tests/inter.md | 4 ++-- tests/prelude.md | 20 ++++++++++---------- tests/words.md | 28 ++++++++++++++-------------- 7 files changed, 50 insertions(+), 54 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index f60eca6..96e1de3 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -28,7 +28,7 @@ ```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 @@ -36,7 +36,7 @@ [ 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 @@ -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 ``` @@ -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 @@ -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 ``` @@ -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 diff --git a/docs/reference.md b/docs/reference.md index 5bb6edf..84d96be 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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 diff --git a/src/prelude.nk b/src/prelude.nk index 37c9c8b..723e57e 100644 --- a/src/prelude.nk +++ b/src/prelude.nk @@ -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 diff --git a/src/words.c b/src/words.c index b7b8ab4..a503752 100644 --- a/src/words.c +++ b/src/words.c @@ -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); @@ -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); @@ -556,7 +556,7 @@ DEF_WORD("scan", scan) { PUSH(result); } -DEF_WORD("apply", apply_cell) { +DEF_WORD(",apply", apply) { POP(op); POP(x); @@ -570,7 +570,7 @@ DEF_WORD("apply", apply_cell) { PUSH(result); } -DEF_WORD("pairwise", pairwise_cell) { +DEF_WORD(",pairwise", pairwise) { POP(op); POP(x); @@ -587,7 +587,7 @@ DEF_WORD("pairwise", pairwise_cell) { PUSH(result); } -DEF_WORD("power", power) { +DEF_WORD(",power", power) { POP(op); POP(n); @@ -595,7 +595,7 @@ DEF_WORD("power", power) { DO(i, as_size_t(n)) { inter_dict_entry(inter, e); } } -DEF_WORD("trace", trace) { +DEF_WORD(",trace", trace) { POP(op); POP(x); diff --git a/tests/inter.md b/tests/inter.md index 3004e9f..39c32cf 100644 --- a/tests/inter.md +++ b/tests/inter.md @@ -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. ; diff --git a/tests/prelude.md b/tests/prelude.md index a7eb97f..b46c99e 100644 --- a/tests/prelude.md +++ b/tests/prelude.md @@ -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 ] ``` diff --git a/tests/words.md b/tests/words.md index 88a326f..92ca649 100644 --- a/tests/words.md +++ b/tests/words.md @@ -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 ] ```