Create a two-dimensional array at runtime: Difference between revisions

Added Quackery.
(→‎{{header|D}}: add crystal solution)
(Added Quackery.)
Line 1,967:
myarray[(0,0)] = 3.5
print (myarray[(0,0)])</lang>
 
=={{header|Quackery}}==
 
<lang Quackery> [ witheach peek ] is {peek} ( { p --> x )
 
[ dip dup
witheach [ peek dup ]
drop ] is unpack ( { p --> * )
 
[ reverse
witheach
[ dip swap poke ] ] is repack ( * p --> { )
 
[ dup dip
[ rot dip
[ unpack 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</lang>
 
{{out}}
 
<pre>Array width (at least 2): 2
Array length (at least 5): 5
Creating 2 by 5 array.
Writing 12345 to element {1,4} of array.
Reading element {1,4} of array: 12345
</pre>
 
=={{header|R}}==
1,462

edits