35 lines
793 B
Plaintext
35 lines
793 B
Plaintext
[ witheach peek ] is {peek} ( { p --> x )
|
|
|
|
[ dip dup
|
|
witheach [ peek dup ]
|
|
drop ] is depack ( { p --> * )
|
|
|
|
[ reverse
|
|
witheach
|
|
[ dip swap poke ] ] is repack ( * p --> { )
|
|
|
|
[ dup dip
|
|
[ rot dip
|
|
[ depack drop ] ]
|
|
repack ] is {poke} ( x { p --> { )
|
|
|
|
[ 0 swap of
|
|
nested swap of ] is 2array ( n n --> [ )
|
|
|
|
|
|
$ "Array width (at least 2): " input $->n drop
|
|
$ "Array length (at least 5): " input $->n drop
|
|
|
|
say "Creating " over echo say " by "
|
|
dup echo say " array." cr
|
|
|
|
2array
|
|
|
|
say "Writing 12345 to element {1,4} of array." cr
|
|
|
|
12345 swap ' [ 1 4 ] {poke}
|
|
|
|
say "Reading element {1,4} of array: "
|
|
|
|
' [ 1 4 ] {peek} echo
|