Skip to content

Commit

Permalink
trivial split demo
Browse files Browse the repository at this point in the history
  • Loading branch information
mikea committed Jun 12, 2024
1 parent 750d1e9 commit 57f888b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ _test:
bin/niko -t docs/reference.md
bin/niko -t docs/example_test.md
bin/niko -t docs/examples/rubik-2x2.md
bin/niko -t docs/examples/h2o.md

[private]
_benchmarks:
Expand Down
6 changes: 6 additions & 0 deletions docs/examples/h2o.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# h2o

```nkt
> "tests/h2o-small.csv" load_text 10 c8 split .
[ "id1,id2,id3,id4,id5,id6,v1,v2,v3" "id016,id016,id0000042202,15,24,5971,5,11,37.211254" "id039,id045,id0000029558,40,49,39457,5,4,48.951141" "id047,id023,id0000071286,68,20,74463,2,14,60.469241" "id043,id057,id0000015141,32,43,63743,1,15,7.692145" "id054,id040,id0000011083,9,25,16920,2,9,22.863525" "id029,id020,id0000017974,40,43,14435,3,13,87.521355" "id047,id023,id0000084849,90,96,35790,2,9,93.348148" "id091,id022,id0000031441,50,44,71525,3,11,81.013682" "id090,id048,id0000067778,24,2,51862,4,9,30.718821" "id070,id008,id0000091167,78,4,23333,5,15,70.95464" "id039,id084,id0000013708,94,81,44406,1,3,54.368009" "id023,id061,id0000011331,36,67,86498,5,2,13.847979" "id070,id054,id0000099110,24,15,47054,4,2,92.057305" "id022,id008,id0000038862,38,92,63088,3,10,33.517765" "id020,id070,id0000028952,17,57,50831,4,15,48.060814" "id078,id022,id0000082008,69,44,15891,1,4,95.75571" "id024,id033,id0000074157,1,57,83341,2,1,72.118722" "id053,id076,id0000061759,55,43,59469,5,10,10.574836" "id058,id087,id0000094028,14,49,72962,4,4,37.914258" "id095,id091,id0000066931,35,20,98979,3,3,16.733062" "id054,id061,id0000004843,69,58,14096,4,13,53.746802" "id019,id078,id0000047661,5,33,13347,5,5,95.013936" "id086,id088,id0000039469,45,86,65332,3,11,65.71087" "id021,id055,id0000035603,96,97,36475,4,9,90.835613" "id004,id034,id0000008260,99,8,73046,3,11,69.540405" "id053,id052,id0000008764,47,13,49231,1,15,32.039599" "id014,id050,id0000066034,45,32,33268,2,3,93.752279" "id099,id057,id0000062408,27,7,63984,5,6,77.454794" "id013,id067,id0000046109,69,90,21214,4,6,83.899656" "id042,id043,id0000025883,64,21,85711,4,14,84.141247" "id024,id062,id0000026824,79,16,49757,2,10,15.822967" "id058,id077,id0000016555,71,8,24728,3,9,92.085521" "id053,id012,id0000005595,73,28,79781,2,10,6.053862" "id100,id096,id0000073858,11,9,25962,1,10,87.268781" "id069,id061,id0000020990,62,55,83993,4,5,77.328007" "id057,id042,id0000093964,14,23,10611,3,7,36.4346" "id051,id098,id0000052576,6,87,21100,1,7,43.659955" "id085,id005,id0000065731,77,44,85693,1,15,1.252545" "id067,id037,id0000098601,56,13,29783,5,14,62.14696" "id076,id022,id0000083893,17,12,13087,5,6,76.226644" "id061,id014,id0000038222,90,49,44757,4,7,27.381984" "id025,id058,id0000068555,18,13,13894,1,13,66.583113" ]
```
10 changes: 8 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,20 @@ Words that starts from '\' are indended to be used during development
|`take`|`(x s -> y)`|takes `x` according to the shape `s` repeating or truncating if necessary|
|`reverse`|`(x -> y)`|reverses all values in the array `x` keeping its shape|
|`repeat`|`(x n -> y)`|repeat cells of `x` according to values of `n`|
|`split`|`(x y -> z)`|splits x using content of y as delimiter|

## Unary Operations

|Word|Signature|Description|
|---|---|---|
|`abs`|`(x -> y)`|replaces array with new array of the same type and shape with absolute values
|`neg`|`(x -> y)`|replaces array with new array of the same type and shape with negative values
|`abs`|`(x -> y)`|replaces array with new array of the same type and shape with absolute values|
|`neg`|`(x -> y)`|replaces array with new array of the same type and shape with negative values|

### Conversions

|Word|Signature|Description|
|---|---|---|
|`c8`|`(x -> y)`|converts array to c8 type|

### Mathematical Functions

Expand Down
2 changes: 1 addition & 1 deletion src/print.c++
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ttT T format_atom(type_t t, bool quote, const void* ptr, T out) {
if (strchr(s, '.') || strchr(s, 'e')) return format_to(out, "{}", s);
else return format_to(out, "{}.", s);
}
case T_C8: NOT_IMPLEMENTED;
case T_C8: return format_to(out, "'{}'", *(char*)ptr);
case T_ARR: return format_to(out, "{}", *(array_p*)ptr);
case T_FFI: NOT_IMPLEMENTED; // return fprintf(f, "<native_function>");
case T_DICT_ENTRY: {
Expand Down
9 changes: 8 additions & 1 deletion src/words.c++
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ REG_FN11(not, i64_t, not_impl);

#pragma endregion bool

#pragma region conversions

ttX char c8_impl(X x) { return (char)x; }
REG_FN11(c8, c8_t, c8_impl);

#pragma endregion conversions

#pragma region math

ttX X neg_impl(X x) { return -x; }
Expand Down Expand Up @@ -458,7 +465,7 @@ ttX struct w_split {
POP(y);
POP(x);
CHECK(x->t == y->t, "types are not the same: {} vs {}", x->t, y->t);
assert(y->a); // not implemented
assert(y->n == 1); // not implemented

auto needle = y->data<X>()[0];
size_t s = 0;
Expand Down
14 changes: 13 additions & 1 deletion tests/words.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ ERROR: expected single value
[ -1 -1. ]
```

### conversions

#### `c8`

```nkt
> [ 50 51 52 ] c8 .
"234"
> 10 c8 .
'
'
```

### abs

```nkt
Expand Down Expand Up @@ -632,7 +644,7 @@ ERROR: stack underflow

## IO

###
### `.`

```nkt
> 1000 index .
Expand Down

0 comments on commit 57f888b

Please sign in to comment.