mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
library/array2d.m:
Add lookup and unsafe_lookup, in both function and predicate forms,
as alternatives to rafe's ^elem notation.
Use meaningful variable names in both code and documentation.
For example, use NumRows and NumColumns instead of M and N.
Replace the implementation of the function that converts a 2d array
back to lists. The new implementation has one loop over rows and one
loop over columns, while the old one had a single loop that did
both jobs. The new one returns [] (meaning no rows) for a 0x0 array,
while the old returned [[]] (meaning one row with no columns).
NEWS:
Announce the changes.
tests/hard_coded/test_array2d.m:
Use a lookup instead of ^elem.
tests/hard_coded/test_array2d.exp:
Expect the updated output from lists. Expect any exceptions to come
from lookup functions, not ^elem functions (since the latter now
just call the former).
45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
Empty =
|
|
[]
|
|
|
|
One =
|
|
[[1]]
|
|
One ^ elem(0, 0) = 1
|
|
|
|
Two =
|
|
[[1, 0]
|
|
[0, 2]]
|
|
Two ^ elem(0, 0) = 1
|
|
Two ^ elem(0, 1) = 0
|
|
Two ^ elem(1, 0) = 0
|
|
Two ^ elem(1, 1) = 2
|
|
|
|
Empty is empty
|
|
One is not empty
|
|
Two is not empty
|
|
|
|
Two_a =
|
|
[[1, 3]
|
|
[0, 2]]
|
|
|
|
Two_b =
|
|
[[1, 3]
|
|
[4, 2]]
|
|
|
|
Zeroes =
|
|
[[0, 0, 0]
|
|
[0, 0, 0]
|
|
[0, 0, 0]]
|
|
|
|
Empty ^ elem(0, 0) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(-1, 0) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(0, -1) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(-1, -1) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(3, 0) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(0, 3) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
Zeroes ^ elem(3, 3) = exception(univ_cons(software_error("function `array2d.lookup\'/3: indices out of bounds")))
|
|
|
|
[11, 12, 13, 14, 15, 16]
|
|
[21, 22, 23, 24, 25, 26]
|
|
[31, 32, 33, 34, 35, 36]
|
|
[41, 42, 43, 44, 45, 46]
|