2018-11-15 00:51:42 +01:00
|
|
|
#!/usr/bin/env retro -i -s
|
|
|
|
|
|
|
|
By WilhelmVonWeiner: Matrices that store their bounds and a
|
|
|
|
couple rushedly written tests.
|
|
|
|
|
|
|
|
~~~
|
|
|
|
{{
|
|
|
|
:prepare (nms--knms) push dup-pair * rot rot pop ;
|
|
|
|
:create (nms--) d:create dup-pair * #2 + allot ;
|
2020-08-09 05:27:42 +02:00
|
|
|
:initialise (nm--) d:last.xt store-next store-next ;
|
2018-11-15 00:51:42 +01:00
|
|
|
:fill (na--a) [ store-next ] times ;
|
|
|
|
---reveal---
|
|
|
|
:matrix (nms--a) create initialise ;
|
2018-11-25 00:28:26 +01:00
|
|
|
:matrix<xs> (xn...x1nms-) prepare matrix swap fill drop ;
|
2018-11-15 00:51:42 +01:00
|
|
|
}}
|
|
|
|
~~~
|
|
|
|
|
|
|
|
Test matrix, should print "matrix works!" and not "broken!".
|
|
|
|
|
|
|
|
```
|
|
|
|
:get-next n:dec dup fetch ;
|
|
|
|
:broken 'broken s:put nl ;
|
|
|
|
#3 #1 'tester matrix
|
|
|
|
get-next #3 -eq? [ broken ] if
|
|
|
|
get-next #1 -eq? [ broken ] if
|
|
|
|
'matrix_works!_at_ s:put n:put nl
|
|
|
|
```
|
|
|
|
|
|
|
|
Test matrix<xs>, should be "contained!" thrice.
|
|
|
|
|
|
|
|
```
|
2019-12-30 16:34:24 +01:00
|
|
|
#30 #20 #10 #3 #1 'tester matrix<xs>
|
2018-11-20 04:05:56 +01:00
|
|
|
{ tester #2 + #3 [ fetch-next swap ] times drop }
|
2019-04-24 16:02:15 +02:00
|
|
|
[ { #10 #20 #30 } a:contains? [ 'contained! s:put sp nl ] if ] a:for-each
|
2018-11-15 00:51:42 +01:00
|
|
|
```
|