diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d5e28..352a634 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * Fixed some errors in the documentation. * Fixed a bug in `\binomial`. Now it returns `0` when the second argument is negative. * Fixed a bug in `\factor`. In earlier versions, it may return incorrect results. -* New particles: `\concatMap`, `\fixedPoint`, `\unconcatMap`. +* New particles: `\concatMap`, `\fixedPoint`, `\onAny`, `\unconcatMap`. ### Breaking changes diff --git a/analysis/Ideas.md b/analysis/Ideas.md index 4ac1034..5f4d693 100644 --- a/analysis/Ideas.md +++ b/analysis/Ideas.md @@ -152,14 +152,6 @@ LiberationMono 字体所支持的字符列举于[此文件](analysis/LiberationM - [ ] `\polPow`:将一个列表视为多项式的系数,求多项式的 n 次幂。感觉不会太常用。 -### [Ways to add 1 to lists of lists](https://codegolf.stackexchange.com/q/237377/9288) - -``` -\onAny { \swap \cons } -``` - -- [ ] `\onAny`:助词,将一个函数应用到列表的任意一个元素上。比如说 `[1,2,3] \onAny \increment` 有三种可能的结果:`[2,2,3]`、`[1,3,3]`、`[1,2,4]`。 - ### [Remove falsy rows and columns](https://codegolf.stackexchange.com/q/269954/9288) ``` diff --git a/analysis/corpus.txt b/analysis/corpus.txt index 21d3b3a..2a3b04f 100644 --- a/analysis/corpus.txt +++ b/analysis/corpus.txt @@ -1,7 +1,7 @@ "ᵉĝ,"ᵉĝ, 1:ᶦ{$ᵉ+ ʷ{←Pᶜ← -ᶣ#3< +ᴶ#3< qŁƀ=ũ ↕= S= @@ -110,7 +110,7 @@ RḞŤ Oᵐ{x= *äK R:∙ -*ĕ$∑= +ʰ_∙ž ᵒ+7f ĭᵐ↔Ĭ 258Ɗ+12%→ @@ -176,7 +176,7 @@ o↔ĭ∑ä R:E∏ ux→=∕$p= ĭ$Ĭ -ᵈ;ᵈCcc, +ʰ{$c ƊsC↔~cɗ- ¢Bx¢E$y↔∫ ṖÞx→↕= @@ -208,7 +208,7 @@ D:×Ṁ Øc;$ᶻ,ŤxᶻŘ Ṗ↕ũṀ←½ Rᶠ{$R~ᵃƂ×Öƃ= -ĉᶣj +ĉᴶj ᶠ{JS=}ş ᵐµṀ o:h-l @@ -241,7 +241,7 @@ RS2L::∙√ɔ$≤ q£E→∫x>çƆᵖLÅ ᶦ{:Ɔ≥$tI}ṁ SjŢ½ađ -R↔$∆çᶣ{CᵈAc}-ň +R↔$∆çᴶ{CᵈAc}-ň ∑½$ṁ±*$:#←c≥ ʷ{P↕1:Ð-:Cž¿?}žz õx-çṀ @@ -306,7 +306,7 @@ Jĭ?∑hÅ ʷ∑→ᵉbD ᶦ{Ƃ2ŗɔƃ3M ĎSᵉti¦ -ᶣ{x:ᵒ≈>~}aş# +ᴶ{x:ᵒ≈>~}aş# →r$ÇƆ/←ŗ0ɔ$ᵑ∆ 1D∑ rjŢ @@ -337,7 +337,7 @@ Z:Ť‼Ť$ḟ Ħ¬ ᵐ#:x+Ṁ$ᵒ%ᵐᶻ@ji ŤđᵃSᵒÐj↕= -↕ᶣŤŤđ≡¿ᵐ≡ +↕ᴶŤŤđ≡¿ᵐ≡ Ňr26%→Ɔ64+$∑→řH 7R¢ɔ∙11¦ ᵃ#*R↕v#Š:ᵐ∑ᵈv=¿:∑ᵈ§=¿ @@ -347,4 +347,4 @@ Sđ∙Z pƆᵗ≤ᵗ≥ o$2ᵑ{Jĭᵃjᵈ↔,}= +ʸ{CU$x3+þç++;ž¿Ø? -*∙Ɗᶣɗ= +*∙Ɗᴶɗ= diff --git a/analysis/freq_1gram.txt b/analysis/freq_1gram.txt index d82fc08..ee51a38 100644 --- a/analysis/freq_1gram.txt +++ b/analysis/freq_1gram.txt @@ -1,13 +1,13 @@ -{ : 79 +{ : 80 $ : 56 -= : 55 += : 54 : : 50 + : 46 -∑ : 40 +∑ : 39 ᵐ : 35 → : 33 -* : 32 R : 32 +* : 31 ← : 30 x : 29 } : 28 @@ -16,9 +16,9 @@ j : 26 - : 25 o : 24 ç : 24 -, : 23 2 : 23 ᵉ : 22 +, : 22 ↕ : 22 Ť : 21 # : 20 @@ -44,7 +44,6 @@ t : 15 Ƃ : 14 Ɗ : 14 Ň : 14 -; : 14 L : 14 ᶦ : 13 < : 13 @@ -52,35 +51,34 @@ L : 14 ᶻ : 13 ≡ : 13 ∫ : 13 +; : 13 +∙ : 13 q : 12 ½ : 12 Ë : 12 -∙ : 12 ∆ : 12 +_ : 12 ʷ : 11 Q : 11 r : 11 +ž : 11 ᵑ : 11 ? : 11 -c : 11 ± : 11 -_ : 11 J : 11 ũ : 10 ˡ : 10 Ţ : 10 E : 10 -ž : 10 ŋ : 10 +c : 10 @ : 10 % : 10 ᶠ : 10 N : 10 ∏ : 10 O : 10 -C : 10 z : 10 -ᵈ : 10 ᶜ : 9 ¬ : 9 ≥ : 9 @@ -88,6 +86,7 @@ z : 10 ŗ : 9 ≈ : 9 i : 9 +C : 9 P : 8 f : 8 ᵚ : 8 @@ -101,6 +100,7 @@ f : 8 ᵗ : 8 4 : 8 ¿ : 8 +ᵈ : 8 Ƶ : 7 H : 7 Ä : 7 @@ -114,7 +114,7 @@ h : 7 ä : 7 Ř : 7 ¢ : 7 -ᶣ : 6 +ᴶ : 6 ᵏ : 6 ƃ : 6 Ď : 6 @@ -124,7 +124,6 @@ h : 7 ş : 6 Ŝ : 6 ɔ : 6 -ĕ : 6 > : 6 Þ : 6 ∩ : 6 @@ -145,6 +144,7 @@ G : 5 Å : 5 s : 5 µ : 5 +ĕ : 5 M : 5 8 : 5 √ : 5 @@ -190,6 +190,7 @@ g : 2 ḟ : 2 ē : 2 K : 2 +ʰ : 2 ¥ : 2 e : 1 : 1 diff --git a/analysis/freq_2gram.txt b/analysis/freq_2gram.txt index 54ea369..65d75f4 100644 --- a/analysis/freq_2gram.txt +++ b/analysis/freq_2gram.txt @@ -3,8 +3,8 @@ ʷ{ : 9 ˡ{ : 8 ᶠ{ : 7 +{$ : 6 ᵑ{ : 6 -{$ : 5 {: : 5 Ťđ : 5 ↕= : 4 @@ -53,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Ac : 1 ᵈAc} : 1 @@ -968,7 +964,7 @@ Jĭ?∑ : 1 ĎSᵉt : 1 Sᵉti : 1 ᵉti¦ : 1 -ᶣ{x: : 1 +ᴶ{x: : 1 {x:ᵒ : 1 x:ᵒ≈ : 1 :ᵒ≈> : 1 @@ -1087,8 +1083,8 @@ $ᵒ%ᵐ : 1 SᵒÐj : 1 ᵒÐj↕ : 1 Ðj↕= : 1 -↕ᶣŤŤ : 1 -ᶣŤŤđ : 1 +↕ᴶŤŤ : 1 +ᴶŤŤđ : 1 ŤŤđ≡ : 1 Ťđ≡¿ : 1 đ≡¿ᵐ : 1 @@ -1163,6 +1159,6 @@ x3+þ : 1 +;ž¿ : 1 ;ž¿Ø : 1 ž¿Ø? : 1 -*∙Ɗᶣ : 1 -∙Ɗᶣɗ : 1 -Ɗᶣɗ= : 1 +*∙Ɗᴶ : 1 +∙Ɗᴶɗ : 1 +Ɗᴶɗ= : 1 diff --git a/analysis/freq_5gram.txt b/analysis/freq_5gram.txt index 02dbb93..4e9c1fb 100644 --- a/analysis/freq_5gram.txt +++ b/analysis/freq_5gram.txt @@ -124,7 +124,6 @@ o;↔ᶻÐ : 1 {C4+> : 1 C4+>‼ : 1 Oᵐ{x= : 1 -*ĕ$∑= : 1 258Ɗ+ : 1 58Ɗ+1 : 1 8Ɗ+12 : 1 @@ -231,9 +230,6 @@ ux→=∕ : 1 x→=∕$ : 1 →=∕$p : 1 =∕$p= : 1 -ᵈ;ᵈCc : 1 -;ᵈCcc : 1 -ᵈCcc, : 1 ƊsC↔~ : 1 sC↔~c : 1 C↔~cɗ : 1 @@ -451,11 +447,11 @@ $tI}ṁ : 1 SjŢ½a : 1 jŢ½ađ : 1 R↔$∆ç : 1 -↔$∆çᶣ : 1 -$∆çᶣ{ : 1 -∆çᶣ{C : 1 -çᶣ{Cᵈ : 1 -ᶣ{CᵈA : 1 +↔$∆çᴶ : 1 +$∆çᴶ{ : 1 +∆çᴶ{C : 1 +çᴶ{Cᵈ : 1 +ᴶ{CᵈA : 1 {CᵈAc : 1 CᵈAc} : 1 ᵈAc}- : 1 @@ -752,7 +748,7 @@ Jĭ?∑h : 1 ŗɔƃ3M : 1 ĎSᵉti : 1 Sᵉti¦ : 1 -ᶣ{x:ᵒ : 1 +ᴶ{x:ᵒ : 1 {x:ᵒ≈ : 1 x:ᵒ≈> : 1 :ᵒ≈>~ : 1 @@ -846,8 +842,8 @@ $ᵒ%ᵐᶻ : 1 ᵃSᵒÐj : 1 SᵒÐj↕ : 1 ᵒÐj↕= : 1 -↕ᶣŤŤđ : 1 -ᶣŤŤđ≡ : 1 +↕ᴶŤŤđ : 1 +ᴶŤŤđ≡ : 1 ŤŤđ≡¿ : 1 Ťđ≡¿ᵐ : 1 đ≡¿ᵐ≡ : 1 @@ -912,5 +908,5 @@ x3+þç : 1 ++;ž¿ : 1 +;ž¿Ø : 1 ;ž¿Ø? : 1 -*∙Ɗᶣɗ : 1 -∙Ɗᶣɗ= : 1 +*∙Ɗᴶɗ : 1 +∙Ɗᴶɗ= : 1 diff --git a/analysis/particles.txt b/analysis/particles.txt index 8530ce5..25299ed 100644 --- a/analysis/particles.txt +++ b/analysis/particles.txt @@ -1,5 +1,5 @@ particle : with "{" / total -ᵈ : 0 / 10 +ᵈ : 0 / 8 ᵉ : 0 / 22 ʳ : 0 / 5 ˣ : 0 / 4 diff --git a/doc/Builtins.md b/doc/Builtins.md index e2316e9..4229d33 100644 --- a/doc/Builtins.md +++ b/doc/Builtins.md @@ -2361,12 +2361,20 @@ If the input is an number, apply the function to each integer from 0 to the inpu If the function takes no argument, return a list of n copies of the result of the function, where n is the length of the input. +__Examples__: + +- `[1,2,3] ᵐ{1+}` → `[2,3,4]` + ### `mapWith` (`ᵚ`, `(1 -> 1) -> (2 -> 1) or (m -> 1) -> (m -> 1) where m > 1`) Map a binary function over its first argument. If the function is unary, return a list of n copies of the result of applying the function to the second argument, where n is the length of the first argument. +__Examples__: + +- `[1,2,3] 4 ᵚ{+}` → `[5,6,7]` + ### `zipWith` (`ᶻ`, `(m -> 1) -> (m -> 1) where m > 1`) Zip two lists and apply a function to each pair of values. @@ -2375,6 +2383,10 @@ Fail if the lists have different lengths. If one of the input is an number, apply the function to each integer from 0 to the input minus 1. +__Examples__: + +- `[1,2,3] [4,5,6] ᶻ{+}` → `[5,7,9]` + ### `zipWithTrunc` (`ᶾ`, `(m -> 1) -> (m -> 1) where m > 1`) Zip two lists and apply a function to each pair of values. @@ -2383,24 +2395,40 @@ If the lists have different lengths, truncate the longer list to the length of t If one of the input is an number, apply the function to each integer from 0 to the input minus 1. +__Examples__: + +- `[1,2,3] [4,5,6,7] ᶾ{+}` → `[5,7,9]` + ### `outer` (`ᵒ`, `(m -> 1) -> (m -> 1) where m > 1`) Apply a function to every possible pair of values in two lists and return a list of lists. If one of the input is an number, apply the function to each integer from 0 to the input minus 1. +__Examples__: + +- `[1,2,3] [4,5] ᵒ{+}` → `[[5,6],[6,7],[7,8]]` + ### `concatMap` (`ʲ`, `(0 -> 1) -> (1 -> 1) or (m -> 1) -> (m -> 1) where m > 0`) Map a function over a list and concatenate the results. See the documentation for `concat` and `map`. -### `unconcatMap` (`ᶣ`, `(0 -> 1) -> (1 -> 1) or (m -> 1) -> (m -> 1) where m > 0`) +__Examples__: + +- `[[1,2],[3,4]] ʲ{1+}` → `[2,3,4,5]` + +### `unconcatMap` (`ᴶ`, `(0 -> 1) -> (1 -> 1) or (m -> 1) -> (m -> 1) where m > 0`) Unconcatenate a list, and then map a function over the results. See the documentation for `unconcat` and `map`. +__Examples__: + +- `[1,2,3] ᴶ{1+}` → `[[2],[3],[4]] [[2],[3,4]] [[2,3],[4]] [[2,3,4]]` + ### `predicate` (`ᵖ`, `(m -> n) -> (1 -> 1)`) Check if a function would succeed without actually applying it. @@ -2409,6 +2437,11 @@ If the function fails, replace the top value with Fail. Otherwise, do nothing. +__Examples__: + +- `1 ᵖ{2<}` → `1` +- `1 ᵖ{2>}` → Fail + ### `predicateNot` (`ᵗ`, `(m -> n) -> (1 -> 1)`) Check if a function would fail without actually applying it. @@ -2417,48 +2450,101 @@ If the function does not fail, replace the top value with Fail. Otherwise, do nothing. +__Examples__: + +- `1 ᵗ{2<}` → Fail +- `1 ᵗ{2>}` → `1` + ### `filter` (`ᶠ`, `(m -> n) -> (1 -> 1)`) For each value in a list, check if a function would succeed without actually applying it, and remove the value if it fails. If the input is an number, convert it to a list of integers from 0 to the input minus 1 before filtering. +__Examples__: + +- `[1,2,3] ᶠ{2<}` → `[1]` + ### `orApply` (`ᶜ`, `(n -> n) -> (n -> n)`) Apply a function zero or one time non-deterministically. +__Examples__: + +- `1 ᶜ{1+}` → `1 2` + ### `iterate` (`ᶦ`, `(n -> n) -> (n -> n)`) Apply a function zero or more times non-deterministically, until the top value of the stack is Fail. This is different from `while` in that it returns the intermediate results. +__Examples__: + +- `1 ᶦ{1+}` → `1 2 3 4 5 ...` + ### `nTimes` (`ᵑ`, `(n -> n) -> (n + 1 -> n)`) Take an integer from the top of the stack, and apply a function that many times. +__Examples__: + +- `1 3 ᵑ{1+}` → `4` + ### `while` (`ʷ`, `(n -> n) -> (n -> n)`) Apply a function zero or more times, until the top value of the stack is Fail. This is different from `iterate` in that it does not return the intermediate results. +__Examples__: + +- `1 ʷ{1+ 4<}` → `3` + ### `lengthWhile` (`ˡ`, `(n -> n) -> (n -> 1)`) Apply a function zero or more times, until the top value of the stack is Fail, and return the number of times the function was applied. +__Examples__: + +- `1 ˡ{1+ 4<}` → `2` + ### `fixedPoint` (`ʸ`, `(n -> n) -> (n -> n)`) Apply a function zero or more times, until the top value of the stack no longer changes. +__Examples__: + +- `1 ʸ{1+ 4m}` → `4` + ### `firstInt` (`ᵏ`, `(m -> n) -> (0 -> 1)`) Find the smallest non-negative integer for which a function does not fail, and return it. +__Examples__: + +- `ᵏ{4>}` → `5` + ### `fold1` (`ʳ`, `(m -> 1) -> (m - 1 -> 1) where m > 1`) Apply a function to the first two values of a list, then apply it to the result and the third value, and so on until the end of the list. If the input is an number, convert it to a list of integers from 0 to the input minus 1 before folding. +__Examples__: + +- `[1,2,3] ʳ{+}` → `6` + +### `onAny` (`ʰ`, `(0 -> 1) -> (1 -> 1) or (m -> 1) -> (m -> 1) where m > 0`) + +Apply a function to one value in a list. The value is chosen non-deterministically. + +Fail if the list is empty. + +If the input is an number, it is converted to a list of integers from 0 to the input minus 1 before applying the function. + +__Examples__: + +- `[1,2,3] ʰ{1+}` → `[2,2,3] [1,3,3] [1,2,4]` + diff --git a/doc/CodePage.md b/doc/CodePage.md index 1bd07a6..9c872b8 100644 --- a/doc/CodePage.md +++ b/doc/CodePage.md @@ -14,8 +14,8 @@ The language is still in an early stage, so the code page is incomplete. Unassig |**5_**|`P`|`Q`|`R`|`S`|`T`|`U`|`V`|`W`|`X`|`Y`|`Z`|`[`|`\`|`]`|`^`|`_`| |**6_**|`` ` ``|`a`|`b`|`c`|`d`|`e`|`f`|`g`|`h`|`i`|`j`|`k`|`l`|`m`|`n`|`o`| |**7_**|`p`|`q`|`r`|`s`|`t`|`u`|`v`|`w`|`x`|`y`|`z`|`{`|`\|`|`}`|`~`|`\n`| -|**8_**|`ᵃ`|`ᶜ`|`ᵈ`|`ᵉ`|`ᵋ`|`ᶠ`|`ᶦ`|`ʲ`|`ᶣ`|`ᵏ`|`ˡ`|`ᵐ`|`ᵚ`|`ᵑ`|`ᵒ`|`ᵖ`| -|**9_**|`ʳ`|`ᵗ`|`ʷ`|`ˣ`|`ʸ`|`ᶻ`|`ᶾ`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`| +|**8_**|`ᵃ`|`ᶜ`|`ᵈ`|`ᵉ`|`ᵋ`|`ᶠ`|`ʰ`|`ᶦ`|`ʲ`|`ᴶ`|`ᵏ`|`ˡ`|`ᵐ`|`ᵚ`|`ᵑ`|`ᵒ`| +|**9_**|`ᵖ`|`ʳ`|`ᵗ`|`ʷ`|`ˣ`|`ʸ`|`ᶻ`|`ᶾ`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`| |**A_**|`Ä`|`Å`|`Ƃ`|`Ç`|`Ĉ`|`Ď`|`Ð`|`Ɗ`|`Ë`|`Ḟ`|`Ĝ`|`Ģ`|`Ħ`|`Ĩ`|`Ĭ`|`Ļ`| |**B_**|`Ł`|`Ṁ`|`Ṃ`|`Ň`|`Ö`|`Ø`|`Ɔ`|`Ƥ`|`Ṗ`|`Ř`|`Ŝ`|`Š`|`Ş`|`Ţ`|`Ť`|`Ŭ`| |**C_**|`Ž`|`Ƶ`|`Þ`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`|`�`| diff --git a/src/Nekomata/CodePage.hs b/src/Nekomata/CodePage.hs index cc3a5c8..210df32 100644 --- a/src/Nekomata/CodePage.hs +++ b/src/Nekomata/CodePage.hs @@ -27,8 +27,8 @@ codePage = ++ "PQRSTUVWXYZ[\\]^_" ++ "`abcdefghijklmno" ++ "pqrstuvwxyz{|}~\n" - ++ "ᵃᶜᵈᵉᵋᶠᶦʲᶣᵏˡᵐᵚᵑᵒᵖ" - ++ "ʳᵗʷˣʸᶻᶾ���������" + ++ "ᵃᶜᵈᵉᵋᶠʰᶦʲᴶᵏˡᵐᵚᵑᵒ" + ++ "ᵖʳᵗʷˣʸᶻᶾ��������" ++ "ÄÅƂÇĈĎÐƊËḞĜĢĦĨĬĻ" ++ "ŁṀṂŇÖØƆƤṖŘŜŠŞŢŤŬ" ++ "ŽƵÞ�������������" diff --git a/src/Nekomata/Particle.hs b/src/Nekomata/Particle.hs index 6f9f529..c9915e6 100644 --- a/src/Nekomata/Particle.hs +++ b/src/Nekomata/Particle.hs @@ -162,7 +162,7 @@ builtinParticles = \from 0 to the input minus 1.\n\ \If the function takes no argument, return a list of n copies \ \of the result of the function, where n is the length of the input." - [] + [("[1,2,3] ᵐ{1+}", all_ ["[2,3,4]"])] , BuiltinParticle "mapWith" 'ᵚ' @@ -173,7 +173,7 @@ builtinParticles = \If the function is unary, return a list of n copies of the \ \result of applying the function to the second argument, where \ \n is the length of the first argument." - [] + [("[1,2,3] 4 ᵚ{+}", all_ ["[5,6,7]"])] , BuiltinParticle "zipWith" 'ᶻ' @@ -183,7 +183,7 @@ builtinParticles = \Fail if the lists have different lengths.\n\ \If one of the input is an number, apply the function to each \ \integer from 0 to the input minus 1." - [] + [("[1,2,3] [4,5,6] ᶻ{+}", all_ ["[5,7,9]"])] , BuiltinParticle "zipWithTrunc" 'ᶾ' @@ -194,7 +194,7 @@ builtinParticles = \to the length of the shorter list.\n\ \If one of the input is an number, apply the function to each \ \integer from 0 to the input minus 1." - [] + [("[1,2,3] [4,5,6,7] ᶾ{+}", all_ ["[5,7,9]"])] , BuiltinParticle "outer" 'ᵒ' @@ -204,7 +204,7 @@ builtinParticles = \and return a list of lists.\n\ \If one of the input is an number, apply the function to each \ \integer from 0 to the input minus 1." - [] + [("[1,2,3] [4,5] ᵒ{+}", all_ ["[[5,6],[6,7],[7,8]]"])] , BuiltinParticle "concatMap" 'ʲ' @@ -213,16 +213,16 @@ builtinParticles = \or (m -> 1) -> (m -> 1) where m > 0" "Map a function over a list and concatenate the results.\n\ \See the documentation for `concat` and `map`." - [] + [("[[1,2],[3,4]] ʲ{1+}", all_ ["[2,3,4,5]"])] , BuiltinParticle "unconcatMap" - 'ᶣ' + 'ᴶ' unconcatMap' "(0 -> 1) -> (1 -> 1) \ \or (m -> 1) -> (m -> 1) where m > 0" "Unconcatenate a list, and then map a function over the results.\n\ \See the documentation for `unconcat` and `map`." - [] + [("[1,2,3] ᴶ{1+}", all_ ["[[2],[3],[4]]", "[[2],[3,4]]", "[[2,3],[4]]", "[[2,3,4]]"])] , BuiltinParticle "predicate" 'ᵖ' @@ -231,7 +231,9 @@ builtinParticles = "Check if a function would succeed without actually applying it.\n\ \If the function fails, replace the top value with Fail.\n\ \Otherwise, do nothing." - [] + [ ("1 ᵖ{2<}", all_ ["1"]) + , ("1 ᵖ{2>}", all_ []) + ] , BuiltinParticle "predicateNot" 'ᵗ' @@ -240,7 +242,9 @@ builtinParticles = "Check if a function would fail without actually applying it.\n\ \If the function does not fail, replace the top value with Fail.\n\ \Otherwise, do nothing." - [] + [ ("1 ᵗ{2<}", all_ []) + , ("1 ᵗ{2>}", all_ ["1"]) + ] , BuiltinParticle "filter" 'ᶠ' @@ -250,14 +254,14 @@ builtinParticles = \without actually applying it, and remove the value if it fails.\n\ \If the input is an number, convert it to a list of integers \ \from 0 to the input minus 1 before filtering." - [] + [("[1,2,3] ᶠ{2<}", all_ ["[1]"])] , BuiltinParticle "orApply" 'ᶜ' orApply "(n -> n) -> (n -> n)" "Apply a function zero or one time non-deterministically." - [] + [("1 ᶜ{1+}", all_ ["1", "2"])] , BuiltinParticle "iterate" 'ᶦ' @@ -267,7 +271,7 @@ builtinParticles = \until the top value of the stack is Fail.\n\ \This is different from `while` in that it returns \ \the intermediate results." - [] + [("1 ᶦ{1+}", truncate_ ["1", "2", "3", "4", "5"])] , BuiltinParticle "nTimes" 'ᵑ' @@ -275,7 +279,7 @@ builtinParticles = "(n -> n) -> (n + 1 -> n)" "Take an integer from the top of the stack, \ \and apply a function that many times." - [] + [("1 3 ᵑ{1+}", all_ ["4"])] , BuiltinParticle "while" 'ʷ' @@ -285,7 +289,7 @@ builtinParticles = \until the top value of the stack is Fail.\n\ \This is different from `iterate` in that it does not \ \return the intermediate results." - [] + [("1 ʷ{1+ 4<}", all_ ["3"])] , BuiltinParticle "lengthWhile" 'ˡ' @@ -294,7 +298,7 @@ builtinParticles = "Apply a function zero or more times, \ \until the top value of the stack is Fail, \ \and return the number of times the function was applied." - [] + [("1 ˡ{1+ 4<}", all_ ["2"])] , BuiltinParticle "fixedPoint" 'ʸ' @@ -302,7 +306,7 @@ builtinParticles = "(n -> n) -> (n -> n)" "Apply a function zero or more times, \ \until the top value of the stack no longer changes." - [] + [("1 ʸ{1+ 4m}", all_ ["4"])] , BuiltinParticle "firstInt" 'ᵏ' @@ -310,7 +314,7 @@ builtinParticles = "(m -> n) -> (0 -> 1)" "Find the smallest non-negative integer for which a function \ \does not fail, and return it." - [] + [("ᵏ{4>}", all_ ["5"])] , BuiltinParticle "fold1" 'ʳ' @@ -321,7 +325,19 @@ builtinParticles = \and so on until the end of the list.\n\ \If the input is an number, convert it to a list of integers \ \from 0 to the input minus 1 before folding." - [] + [("[1,2,3] ʳ{+}", all_ ["6"])] + , BuiltinParticle + "onAny" + 'ʰ' + onAny + "(0 -> 1) -> (1 -> 1) \ + \or (m -> 1) -> (m -> 1) where m > 0" + "Apply a function to one value in a list. \ + \The value is chosen non-deterministically.\n\ + \Fail if the list is empty.\n\ + \If the input is an number, it is converted to a list of integers \ + \from 0 to the input minus 1 before applying the function." + [("[1,2,3] ʰ{1+}", all_ ["[2,2,3]", "[1,3,3]", "[1,2,4]"])] ] -- | The map of from names to builtin particles @@ -701,3 +717,28 @@ fold1 = Particle fold1' in (x >>= liftList (tryFoldl1 f' i) . toTryList) :+ dropStack (m - 2) s fold1' _ = Nothing + +onAny :: Particle +onAny = Particle onAny' + where + onAny' (Function (Arity 0 1) f) = + Just + . Function (Arity 1 1) + $ \i (x :+ s) -> + let f' i' x' = top $ f i' (Val x' :+ s) + in (x >>= liftList (onAny_ f' i) . toTryList) :+ s + onAny' (Function (Arity m 1) f) | m > 0 = + Just + . Function (Arity m 1) + $ \i (x :+ s) -> + let f' i' x' = top $ f i' (Val x' :+ s) + in (x >>= liftList (onAny_ f' i) . toTryList) + :+ dropStack (m - 1) s + onAny' _ = Nothing + onAny_ :: (Id -> a -> Try a) -> (Id -> ListTry (Try a) -> TryList (Try a)) + onAny_ _ _ Nil = Fail + onAny_ f i (Cons x xs) = + Choice + (leftId i) + (Val $ Cons (x >>= f (leftId (rightId i))) xs) + (Val . Cons x $ xs >>= onAny_ f (rightId (rightId i))) diff --git a/test/Eval.hs b/test/Eval.hs index 7d45848..ab7621f 100644 --- a/test/Eval.hs +++ b/test/Eval.hs @@ -79,7 +79,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do , ("9", Count 55) ] specEval - "ᶣ#3<" + "ᴶ#3<" [ ("0", Count 1) , ("1", Count 1) , ("2", Count 2) @@ -1225,7 +1225,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q146059: Is my triangle right?" $ do specEval - "*ĕ$∑=" + "ʰ_∙ž" [ ("[5,3,4]", Check True) , ("[3,5,4]", Check True) , ("[12,37,35]", Check True) @@ -1944,12 +1944,12 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q237377: Ways to add 1 to lists of lists" $ do specEval - "ᵈ;ᵈCcc," - [ ("9 []", all_ []) - , ("9 [[]]", all_ ["[[9]]"]) - , ("10 [[1,2,3]]", all_ ["[[10,1,2,3]]"]) - , ("7 [[1,2],[3,4],[5],[]]", all_ ["[[7,1,2],[3,4],[5],[]]", "[[1,2],[7,3,4],[5],[]]", "[[1,2],[3,4],[7,5],[]]", "[[1,2],[3,4],[5],[7]]"]) - , ("2 [[1,2],[2,2],[2]]", all_ ["[[2,1,2],[2,2],[2]]", "[[1,2],[2,2,2],[2]]", "[[1,2],[2,2],[2,2]]"]) + "ʰ{$c" + [ ("[] 9", all_ []) + , ("[[]] 9", all_ ["[[9]]"]) + , ("[[1,2,3]] 10", all_ ["[[10,1,2,3]]"]) + , ("[[1,2],[3,4],[5],[]] 7", all_ ["[[7,1,2],[3,4],[5],[]]", "[[1,2],[7,3,4],[5],[]]", "[[1,2],[3,4],[7,5],[]]", "[[1,2],[3,4],[5],[7]]"]) + , ("[[1,2],[2,2],[2]] 2", all_ ["[[2,1,2],[2,2],[2]]", "[[1,2],[2,2,2],[2]]", "[[1,2],[2,2],[2,2]]"]) ] describe "q238607: Converge to a number" $ do specEval @@ -2285,7 +2285,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q252303: Cut along the lines" $ do specEval - "ĉᶣj" + "ĉᴶj" [ ("[1,0]", all_ ["[[1],[0]]", "[[1,0]]"]) , ("[1,1,1,1]", all_ ["[[1,1,1,1]]"]) , ("[1,1,0,0,1]", all_ ["[[1,1],[0,0],[1]]", "[[1,1],[0,0,1]]", "[[1,1,0,0],[1]]", "[[1,1,0,0,1]]"]) @@ -2591,7 +2591,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q259083: Is it traversable?" $ do specEval - "R↔$∆çᶣ{CᵈAc}-ň" + "R↔$∆çᴶ{CᵈAc}-ň" [ ("0 [1,1,1,1,1]", Check True) , ("0 [50,45,20,19,18,10,1,1,1]", Check True) , ("5 [1,6,11,16,21,26,31]", Check True) @@ -3306,7 +3306,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q266049: How many umbrellas to cover the beach?" $ do specEval - "ᶣ{x:ᵒ≈>~}aş#" + "ᴶ{x:ᵒ≈>~}aş#" [ ("[9,2,1,3,2,4,2,1] 1", first_ "1") , ("[1,1,1,1,1,1,1,1] 1", first_ "8") , ("[2,1,4,1,4,1,1,3,1] 1", first_ "2") @@ -3651,7 +3651,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do , ("[[6,1],[1,6]]", Check False) ] specEval - "↕ᶣŤŤđ≡¿ᵐ≡" + "↕ᴶŤŤđ≡¿ᵐ≡" [ ("[[1,1]]", Check True) , ("[[1,1],[1,2]]", Check True) , ("[[1,1],[1,1],[2,1]]", Check True) @@ -3755,7 +3755,7 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do ] describe "q274690: Cubic Concatenation" $ do specEval - "*∙Ɗᶣɗ=" + "*∙Ɗᴶɗ=" [ ("[1,5,3]", Check True) , ("[2,2,13]", Check True) , ("[4,0,7]", Check True)