Commit Graph

5 Commits

Author SHA1 Message Date
Zoltan Somogyi
f8c67929de Modernize library/array2d.m.
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).
2020-10-05 00:06:37 +11:00
Zoltan Somogyi
12a870f8f6 Test another predicate in array2d. 2020-10-03 20:19:59 +10:00
Julien Fischer
f89054f165 Use error($pred, "...") in more spots in the standard library.
Also, throw software_error/1 exceptions rather than directly throwing strings
in a few spots.

Undo special Ralph-style formatting.

library/*.:
    As above.

tests/hard_coded/array2d_from_array.exp:
tests/hard_coded/array2d.exp:
tests/hard_coded/test_injection.exp:
   Update to conform with the above change.
2019-10-15 17:48:36 +11:00
Julien Fischer
a79bae00e8 Add io.write_array/[56] and array2d.is_empty/1.
library/io.m:
    Add predicates io.write_array/[56] which are are similar to
    io.write_list but work on arrays and do _not_ require converting
    the array into a list first.

library/array2d.m:
    Add array2d.is_empty/1.

NEWS:
    Announce the above additions.

tests/hard_coded/Mmakefile:
tests/hard_coded/write_array.{m,exp}:
    Add a test for write_array.

tests/hard_coded/test_array2d.{m,exp}:
    Extend this test to cover is_empty/1.
2016-03-18 12:06:10 +11:00
Ralph Becket
40f91a28ef Added a new library module, array2d.m, implementing 2d rectangular arrays.
Estimated hours taken: 4
Branches: main

Added a new library module, array2d.m, implementing 2d rectangular arrays.

NEWS:
	Report the new addition.

library/array2d.m:
	Added.

library/library.m:
	Added import for array2d.

compiler/modules.m:
	Added clause for array2d to mercury_std_library_module/1.

tests/hard_coded/test_array2d.m:
tests/hard_coded/test_array2d.exp:
tests/hard_coded/Mmakefile:
	Test case added.
2003-01-23 04:25:47 +00:00