Skip to content

Commit

Permalink
🔖 v0.3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AlephAlpha committed Jun 7, 2023
1 parent 29eb789 commit 5a1ed18
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 60 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Revision history for Nekomata

## 0.3.4.0 -- Unreleased
## 0.3.4.0 -- 2023-06-07

* New built-in functions: `\chunks`, `\convolve`, `\half`, `\toBase2Rev`.
* New built-in functions: `\andThen`, `\chunks`, `\convolve`, `\extract`, `\half`, `\isZero`, `\toBase2Rev`.
* New particle: `\filter`.
* The code page is updated. The character `` (unused) is replaced with `½`.

### Breaking changes

* The code page is updated. The character `` is replaced with `½`, and the character `` is replaced with `¿`.

## 0.3.3.0 -- 2023-05-27

Expand Down
33 changes: 1 addition & 32 deletions Ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Nekomata 现在已经有了一个非常简单的解释器。不过已有的内
此处总结一下 Code Page 中已有但还没有用上的字符:

```
≈&'.VWXY`vwy|
≈&'.VWXY`vwy|
```

有些是已经确定分配给什么函数的,比如说 `|``\bitOr``&``\bitAnd``X``\bitXor`。别的都还没想好。
Expand Down Expand Up @@ -118,16 +118,6 @@ fghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º

- [ ] `\sortBy`:输入两个列表,其长度必须一致。将第一个列表中的元素按照第二个列表中的元素的大小进行排序。这要求排序算法是稳定的。

## [Split some points](https://codegolf.stackexchange.com/q/257870/9288)

参考现有的 Vyxal 解答:

```
\integer \allValues \dup \anyPair \lengthIs \predicate { 1 \neg \cons \swap \map { 1 \cons \reverse \dot \sign \nonzero } \sum 0 \eq }
```

- [ ] `\anyPair`:输入两个列表,输出一个二元组,第一个元素是第一个列表的任意一个元素,第二个元素是第二个列表的任意一个元素。这个函数是 non-deterministic 的。实现时要注意两个列表的长度都可能是无穷的。

## [Mode (most common element) of a list](https://codegolf.stackexchange.com/q/42529/9288)

```
Expand All @@ -138,20 +128,6 @@ fghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º

- [ ] `\maximumBy`:输入两个列表,其长度必须一致。根据第一个列表中最大的元素的索引,返回第二个列表中对应的元素。由于最大的元素可能不止一个,所以这个函数是 non-deterministic 的。

## [Painting with Line Filler](https://codegolf.stackexchange.com/q/256978/9288)

```
\while { \orApply \transpose \extract \allEqual \delete } \isEmpty
```

10 个字节,还用了一堆未实现的函数。输的比较惨。

- [ ] `\extract`:从一个列表中任意取出一个元素,原来的列表中删去这个元素。这个函数是 non-deterministic 的。
- [ ] `\delete`:从一个列表中删除所有等于某个元素的元素。
- [ ] `\isEmpty`:检查一个列表是否为空。

Vyxal、Jelly、05AB1E 都用到了类似于 fixed-point 的函数,但这个在 non-deterministic 语言中不好弄,语义也不是很明确。

## [Shortest Valid Parentheses](https://codegolf.stackexchange.com/q/258511/9288)

目前的解法有 17 个字节,输得比较惨。主要问题是缺乏字符串操作。比如说,如果有一个字符串替换的 built-in 的话,可以:
Expand All @@ -177,7 +153,6 @@ Vyxal、Jelly、05AB1E 都用到了类似于 fixed-point 的函数,但这个
\range0 \toBase2Rev \dup \outer { \dip \dup \bitxor 2 \mul \add \cons0 4 \recip \fromBaseRev }
```

- [ ] `\toBase2Rev`:将一个数转换成二进制表示,低位在前。
- [ ] `\bitxor`:按位异或。

或者:
Expand Down Expand Up @@ -330,12 +305,6 @@ Vyxal、Jelly、05AB1E 都用到了类似于 fixed-point 的函数,但这个
\tally \minimumBy
```

```
\extract \swap \allEqual \then
```

- [ ] `\then`: 相当于 `Try` monad 里的 `>>`

## [Most Common Multiple](https://codegolf.stackexchange.com/q/170047/9288)

```
Expand Down
8 changes: 4 additions & 4 deletions Nekomata.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name: Nekomata
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.3.3.0
version: 0.3.4.0

-- A short (one-line) description of the package.
synopsis:
Expand Down Expand Up @@ -85,7 +85,7 @@ library
-- Other library packages from which modules are imported.
build-depends:
, arithmoi ^>=0.12
, base >=4.13 && <5
, base >=4.13 && <5
, containers ^>=0.6
, integer-roots ^>=1.0
, parsec ^>=3.1
Expand Down Expand Up @@ -114,7 +114,7 @@ executable Nekomata

-- Other library packages from which modules are imported.
build-depends:
, base >=4.13 && <5
, base >=4.13 && <5
, bytestring ^>=0.11
, containers ^>=0.6
, haskeline ^>=0.8
Expand Down Expand Up @@ -151,6 +151,6 @@ test-suite Nekomata-test

-- Test dependencies.
build-depends:
, base >=4.13 && <5
, base >=4.13 && <5
, hspec ^>=2.10
, Nekomata
24 changes: 22 additions & 2 deletions doc/Builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ Count the number of values in a non-deterministic object.

Remove duplicate values from a non-deterministic object.

This function is non-deterministic.

### `normalForm` (`¤`, `1 -> 1`)

Convert a non-deterministic object to the normal form.
Expand All @@ -44,6 +42,12 @@ I haven't given a formal definition for the normal form. This function basically

Choose the first value that doesn't fail between two values.

### `andThen` (`¿`, `2 -> 1`)

Take two values,

and return the first one if the second one doesn't fail.

### `drop` (`^`, `1 -> 0`)

Drop the top value of the stack.
Expand Down Expand Up @@ -94,6 +98,14 @@ If it is, push the number itself, otherwise fail.

This function is automatically vectorized.

### `isZero` (`ž`, `1 -> 1`)

Check if a number is zero.

If it is, push the number itself, otherwise fail.

This function is automatically vectorized.

### `less` (`<`, `2 -> 1`)

Check if the first number is less than the second.
Expand Down Expand Up @@ -646,6 +658,14 @@ Get a permutation of a list or a string.

This function is non-deterministic.

### `extract` (`ĕ`, `1 -> 2`)

Extract an element from a list or a character from a string.

Returns the element and the rest of the list or string.

This function is non-deterministic.

### `allEqual` (``, `1 -> 1`)

Check if all elements in a list are equal.
Expand Down
4 changes: 2 additions & 2 deletions doc/CodePage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The language is still in an early stage, so the code page is incomplete. Unassig
| |**_0**|**_1**|**_2**|**_3**|**_4**|**_5**|**_6**|**_7**|**_8**|**_9**|**_A**|**_B**|**_C**|**_D**|**_E**|**_F**|
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
|**0_**|`¡`|`¢`|`£`|`¤`|`¥`|`¦`|`§`|`¬`|`±`|`×`|`÷`|``|``|``|``|``|
|**1_**|``|``|``|``|``|``|``|`½`|``|``|``|``|``|`µ`|``|``|
|**1_**|`¿`|``|``|``|``|``|``|`½`|``|``|``|``|``|`µ`|``|``|
|**2_**|` `|`!`|`"`|`#`|`$`|`%`|`&`|`'`|`(`|`)`|`*`|`+`|`,`|`-`|`.`|`/`|
|**3_**|`0`|`1`|`2`|`3`|`4`|`5`|`6`|`7`|`8`|`9`|`:`|`;`|`<`|`=`|`>`|`?`|
|**4_**|`@`|`A`|`B`|`C`|`D`|`E`|`F`|`G`|`H`|`I`|`J`|`K`|`L`|`M`|`N`|`O`|
Expand All @@ -18,7 +18,7 @@ The language is still in an early stage, so the code page is incomplete. Unassig
|**9_**|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|
|**A_**|`Ƃ`|`Ç`|`Ð`|`Ĩ`|``|`Ň`|`Ø`|`Ɔ`|`Ƥ`|``|`Ř`|`Ţ`|`Ť`|`Ŭ`|`Ž`|``|
|**B_**|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|
|**C_**|`ç`|`ĉ`|`đ`|``|`ƒ`|``|``|`ɔ`|`ƥ`|`ŗ`|`ř`|`ũ`|``|``|``|``|
|**C_**|`ç`|`ĉ`|`đ`|``|`ĕ`|`ƒ`|``|``|`ɔ`|`ƥ`|`ŗ`|`ř`|`ũ`|`ž`|``|``|
|**D_**|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|
|**E_**|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|
|**F_**|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|``|
Expand Down
23 changes: 21 additions & 2 deletions src/Nekomata/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ builtins =
"uniqueValue"
'ũ'
uniqueValue
"Remove duplicate values from a non-deterministic object.\n\
\This function is non-deterministic."
"Remove duplicate values from a non-deterministic object."
, Builtin
"normalForm"
'¤'
Expand All @@ -108,6 +107,12 @@ builtins =
'I'
if'
"Choose the first value that doesn't fail between two values."
, Builtin
"andThen"
'¿'
andThen
"Take two values, \n\
\and return the first one if the second one doesn't fail."
, Builtin "drop" '^' drop' "Drop the top value of the stack."
, Builtin "dup" ':' dup "Duplicate the top value of the stack."
, Builtin "swap" '$' swap "Swap the top two values of the stack."
Expand Down Expand Up @@ -148,6 +153,13 @@ builtins =
"Check if a number is positive.\n\
\If it is, push the number itself, otherwise fail.\n\
\This function is automatically vectorized."
, Builtin
"isZero"
'ž'
isZero
"Check if a number is zero.\n\
\If it is, push the number itself, otherwise fail.\n\
\This function is automatically vectorized."
, Builtin
"less"
'<'
Expand Down Expand Up @@ -735,6 +747,13 @@ builtins =
permutation
"Get a permutation of a list or a string.\n\
\This function is non-deterministic."
, Builtin
"extract"
'ĕ'
extract
"Extract an element from a list or a character from a string.\n\
\Returns the element and the rest of the list or string.\n\
\This function is non-deterministic."
, Builtin
"allEqual"
''
Expand Down
3 changes: 3 additions & 0 deletions src/Nekomata/Builtin/Basic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ normalForm' = Function (Arity 1 1) $ \_ (x :+ s) -> normalForm x :+ s
if' :: Function
if' = choice .* oneValue

andThen :: Function
andThen = Function (Arity 2 1) $ \_ (x :+ y :+ s) -> (normalForm x >> y) :+ s

drop' :: Function
drop' = Function (Arity 1 0) $ \_ (_ :+ s) -> s

Expand Down
27 changes: 18 additions & 9 deletions src/Nekomata/Builtin/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Nekomata.Builtin.List where

import Control.Arrow (first, second, (***))
import Control.Arrow (first, (***))
import Control.Monad (join, liftM2)
import Data.Functor ((<&>))
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -427,15 +427,24 @@ permutation = unary permutation'
permutation_ :: Id -> ListTry a -> TryList a
permutation_ _ Nil = Val Nil
permutation_ i xs =
extract' (leftId i) xs >>= \(x, xs') ->
extract_ (leftId i) xs >>= \(xs', x) ->
Val $ Cons x (xs' >>= permutation_ (rightId i))
extract' :: Id -> ListTry a -> Try (a, TryList a)
extract' _ Nil = Fail
extract' i (Cons x xs) =
Choice
(leftId i)
(Val (x, xs))
(xs >>= extract' (rightId i) <&> second (Val . Cons x))

extract :: Function
extract = unary2 extract'
where
extract' i (DStringT xs) =
liftString12 (fmap (first AsString) . extract_ i) xs
extract' i (DListT xs) = liftList12 (extract_ i) xs
extract' _ _ = (Fail, Fail)

extract_ :: Id -> ListTry a -> Try (TryList a, a)
extract_ _ Nil = Fail
extract_ i (Cons x xs) =
Choice
(leftId i)
(Val (xs, x))
(xs >>= extract_ (rightId i) <&> first (Val . Cons x))

allEqual :: Function
allEqual = unary allEqual'
Expand Down
6 changes: 6 additions & 0 deletions src/Nekomata/Builtin/Math.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ isPositive = predicateVec isPositive'
isPositive' _ (DNumT x) = (> 0) . unDet <$> x
isPositive' _ _ = Fail

isZero :: Function
isZero = predicateVec isZero'
where
isZero' _ (DNumT x) = (== 0) . unDet <$> x
isZero' _ _ = Fail

less :: Function
less = predicateVec2 less'
where
Expand Down
4 changes: 2 additions & 2 deletions src/Nekomata/CodePage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Data.Word (Word8)
codePage :: String
codePage =
"¡¢£¤¥¦§¬±×÷‼←→↔↕"
++ "∆∏∑∕∙√½∩∫≈≠≡µ≤≥"
++ "¿∆∏∑∕∙√½∩∫≈≠≡µ≤≥"
++ " !\"#$%&'()*+,-./"
++ "0123456789:;<=>?"
++ "@ABCDEFGHIJKLMNO"
Expand All @@ -21,7 +21,7 @@ codePage =
++ "����������������"
++ "ƂÇÐĨṀŇØƆƤṖŘŢŤŬŽ�"
++ "����������������"
++ "çĉđḍƒṁṇɔƥŗřũ����"
++ "çĉđḍĕƒṁṇɔƥŗřũž��"
++ "����������������"
++ "����������������"
++ "����������������"
Expand Down
Loading

0 comments on commit 5a1ed18

Please sign in to comment.