Paste: Typed and nested sequences
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 12:25:39 |
Plain Text |
ERROR: similar-type element index sequence ;
MIXIN: nested-sequence
INSTANCE: nested-sequence sequence
TUPLE: nested-array < array
;
INSTANCE: nested-array nested-sequence
DEFER: }} ( -- * ) delimiter
SYNTAX: {{ \ }} [ >nested-array ] parse-literal ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 12:43:06 |
Plain Text |
Usage
{{ { 1 2 3 } { 4 5 6 } { 7 8 9 } }} sum
{{ {{ { 1 2 3 } { 4 5 6 } }} {{ { 7 8 9 } }} }} sum
M: sum nested-sequence [ sum ] map call-next-method ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 12:54:02 |
Plain Text |
GENERIC: product ( seq -- n )
M: product nested-sequence [ product ] map call-next-method ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 15:45:40 |
Plain Text |
TUPLE: wrapped-array { underlying array read-only } ;
TUPLE: nested-array < wrapped-array ;
INSTANCE: nested-array nested-sequence
ERROR: not-all-sequences ;
: >nested-array ( seq -- nested-array )
dup [ sequence? ] all? [ not-all-sequences ] unless
>array nested-array boa ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 17:18:28 |
Plain Text |
MIXIN: nested-sequence
INSTANCE: nested-sequence sequence
TUPLE: wrapped-array { underlying array read-only } ;
CONSULT: sequence-protocol wrapped-array underlying>> ;
TUPLE: nested-array < wrapped-array ;
INSTANCE: nested-array nested-sequence
ERROR: not-all-sequences ;
: >nested-array ( seq -- nested-array )
dup [ sequence? ] all? [ not-all-sequences ] unless
>array nested-array boa ;
DEFER: }} ( -- * ) delimiter
SYNTAX: {{ \ }} [ >nested-array ] parse-literal ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 17:26:51 |
Plain Text |
MIXIN: nested-sequence
INSTANCE: nested-sequence sequence
TUPLE: wrapped-array { underlying array read-only } ;
CONSULT: sequence-protocol wrapped-array underlying>> ;
TUPLE: nested-array < wrapped-array ;
CONSULT: sequence-protocol nested-array underlying>> ;
INSTANCE: nested-array nested-sequence
ERROR: not-all-sequences ;
: >nested-array ( seq -- nested-array )
dup [ sequence? ] all? [ not-all-sequences ] unless
>array nested-array boa ;
DEFER: }} ( -- * ) delimiter
SYNTAX: {{ \ }} [ >nested-array ] parse-literal ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 31 Oct 2023 17:29:25 |
Plain Text |
{{ { 1 2 3 } { 4 5 6 } { 7 8 9 } }} sum
{{ {{ { 1 2 3 } { 4 5 6 } }} {{ { 7 8 9 } }} }} sum
M: sum nested-sequence [ sum ] map sum ;
New Annotation