Commit Graph

42 Commits

Author SHA1 Message Date
Julien Fischer
778e75f696 Fix problems in the library.
library/array.m:
library/builtin.m:
library/construct.m:
    Fix copy-and-paste errors.

library/arrayd2d.m:
    Use the mode array2d_di instead of array_di in a spot.

    Delete an extra space from an exception message.

library/bimap.m:
    Fix formatting.

library/bit_buffer.m:
    Fix inverted argument types.

library/dir.m:
    Say that make_single_directory/4 returns an error rather
    than saying that it fails.

library/io.m:
    Fix errors in obsolete pragmas.

library/assoc_list.m:
library/bag.m:
library/cord.m:
library/deconstruct.m:
library/enum.m:
library/fat_sparse_bitset.m:
library/getopt*.m:
library/int*.m:
library/io*.m:
library/type_desc.m:
    Fix documentation errors.

tests/hard_coded/array2d_from_array.exp:
    Conform to the changed exception message in array2d.m.
2026-02-19 15:24:59 +11:00
Julien Fischer
0b92543c5e Fix more library documentation errors.
library/*.m:
   As above.
2026-01-23 19:53:58 +11:00
Zoltan Somogyi
2625382237 Fix comment rot. 2025-10-02 19:37:50 +10:00
Zoltan Somogyi
3f72528869 Update module stability levels. 2025-08-11 22:32:52 +02:00
Zoltan Somogyi
34e64a623b Replace "iff" with "if-and-only-if" in the library. 2025-06-08 10:33:56 +10:00
Zoltan Somogyi
a19bcaaed5 Updates to programming style in the library.
library/bt_array.m:
    Reorder the arguments of the resize and shrink predicates
    to make them easier to use with state variables.

tests/general/array_test.m:
    Update the test calls to these two predicates.

library/version_array2d.m:
    Rewrite part of this module using a programming style that includes
    variable names that are longer than one character :-(. In the absence
    of comprehensive, or even basic, test cases, leave the rest using
    the old style.

    Add a non-field-syntax lookup operation.

    Mark the site of a probable bug.

library/version_bitmap.m:
    Add non-field-syntax versions of the get_bit and set_bit operations.

NEWS.md:
    Announce the reordering and the new predicates above.

library/getopt.m:
library/getopt_io.m:
    Apply to getopt_io.m an update that was previously applied to getopt.m,
    even though getopt.m is now computed from getopt_io.m.

library/array2d.m:
library/bit_buffer.m:
library/bit_buffer.read.m:
library/bit_buffer.write.m:
library/bitmap.m:
library/cord.m:
library/edit_distance.m:
library/edit_seq.m:
library/fat_sparse_bitset.m:
library/fatter_sparse_bitset.m:
library/list.m:
library/one_or_more.m:
library/pair.m:
library/ra_list.m:
library/rbtree.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_tree234.m:
library/set_unordlist.m:
library/solutions.m:
library/sparse_bitset.m:
library/test_bitset.m:
library/thread.barrier.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/tree_bitset.m:
library/version_array.m:
library/version_hash_table.m:
library/version_store.m:
    General updates to style, the main ones being the following.

    Using standard names for type variables:

    - K and V for key and value types in map-like structures
    - A to F for types of accumulators
    - T for most everything else, possibly with a numeric suffix
      to distinguish two separate types that nevertheless play
      similar roles.

    (I left descriptive type var names such as Stream and Store unchanged.)

    Adding or expanding descriptions of exported predicates and functions.

    Declaring and defining field syntax getters and setters without using ^,
    while keeping the use of field syntax, including ^, in the operations'
    descriptions.

    Defining field syntax operations operations in terms of the
    non-field-syntax versions, not vice versa.

    Defining function versions of operations in terms of the predicate
    versions, not vice versa.
2024-12-29 20:09:09 +11:00
Julien Fischer
9aa08276ae Minor documentation fix.
library/bt_array.m:
    s/an/and/ in a spot where the latter was intended.
2022-07-02 14:16:52 +10:00
Zoltan Somogyi
3459266a7a Carve stdlib module ra_list.m out of bt_array.m.
library/ra_list.m:
    As above.

    Rename ra_list_lookup to ra_list_search, since it fails if the item
    to be accessed does not exist. Add a version, ra_list_lookup, which
    aborts in that case.

    Add predicates to append two ra_lists, and to convert ra_lists
    to just plain lists.

    Change the argument order of some predicates to be more
    state variable friendly.

    Add some documentation.

library/bt_array.m:
    Delete the moved code, and update the references to the changed predicates.

library/Mercury.options:
    Now that the ra_list predicates have been moved to their own module,
    stop giving bt_array.m a free pass on inconsistent predicate order.

library/MODULES_DOC:
library/library.m:
    Add ra_list.m as a documented module of the Mercury standard library.

library/array.m:
    Delete a predicate that served as a test for an ancient bug fix.

NEWS:
    Announce both the new ra_list module, and the deletion of the predicate
    from array.m.

tests/hard_coded/array_sort.m:
    Don't call the predicate deleted from array.m.

tests/hard_coded/ra_list_test.{m,exp}:
    A new test case to test operations on ra_lists.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2022-06-11 11:11:30 +10:00
Zoltan Somogyi
e9d9726014 Organize array.m, bt_array.m and pprint.m.
library/array.m:
library/bt_array.m:
library/pprint.m:
    In each of these modules,

    - put related predicates next to each other,
    - put the groups of related predicates into a meaningful order, and
    - improve the documentation of some predicates, and
    - improve some variable names in the implementation, including giving
      explicit names to some function results.

library/Mercury.options:
    Enable the warning about inconsistent predicate order for two of those
    modules, but not bt_array.m, pending a decision about making its
    informal "submodule" an actual separate module.
2022-06-08 19:59:15 +10:00
Julien Fischer
e7d28ff90f Update copyright notices in stdlib.
library/*.m:
    As above.
2022-06-07 21:51:03 +10:00
Zoltan Somogyi
8ff61f8a4b Delete quotes from `VarNames' in stdlib comments.
In the Mercury standard library, every exported predicate or function
has (or at least *should* have) a comment that documents it, including
the meanings of its arguments. About 35-40% of these modules put `'s
(left and right quotes) around the names of the variable representing
those arguments. Some tried to do it consistently (though there were spots
with unquoted or half quoted names), while some did it only a few places.
This is inconsistent: we should either do it everywhere, or nowhere.
This diff makes it nowhere, because

- this is what the majority of the standard library modules do;
- this is what virtually all of the modules in the compiler, profiler,
  deep_profiler etc directories do;
- typing all those quotes when adding new predicates in modules that
  follow this convention is a pain in the ass; and because
- on many modern terminals, `' looks non-symmetrical and weird.

Likewise, the comment explaining a predicate often started with

    % `predname(arguments)' returns ...

This diff deletes these quotes as well, since they add nothing useful.

This diff does leave in place quotes around code fragments, both terms
and goals, where this helps delineate the boundaries of that fragment.
2022-03-07 11:49:00 +11:00
Zoltan Somogyi
06f81f1cf0 Add end_module declarations ...
.. to modules which did not yet have them.
2022-01-09 10:36:15 +11:00
Zoltan Somogyi
0d7c8a7654 Specify pred or func for all pragmas.
*/*.m:
    As above.

configure.ac:
    Require the installed compiler to support this capability.
2021-06-16 15:23:58 +10:00
Zoltan Somogyi
95f8f56716 Delete unneeded $module args from calls to expect/unexpected. 2019-07-03 22:37:19 +02:00
Zoltan Somogyi
a12692a0de Replace /* */ comments with // in the library.
Keep the old style comments where they do not go to the end of the line,
or where it is important that the comment line not have a // on it.
2018-06-21 18:55:08 +02:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Peter Wang
6df99209b9 Improve documentation for array bounds predicates.
library/array.m:
library/bt_array.m:
    Do not assume that the lower bound is zero in the documentation for
    array.max.

    Make explicit the argument order of bounds/3 predicates
    and document behaviour on empty arrays.
2017-12-03 09:57:28 +11:00
Peter Wang
d7d1471881 Clarify behaviour of upper bounds functions for array types.
library/array.m:
library/bt_array.m:
library/version_array.m:
    As above.
2017-12-01 17:36:20 +11:00
Zoltan Somogyi
1da267e9f0 Fix a bug in handling instances with --warn-unused-imports.
This fixes Mantis bug #412.

compiler/unused_imports.m:
    Consider that an instance declaration makes a module "used" only if
    it occurs in the module being compiled, not in an imported or ancestor
    module. (Mantis bug 412 was caused by instance declarations in implicitly
    imported modules.)

    Fixing #412 also exposed another bug. When computing the set of modules
    used by predicates, we considered (besides some non-type entities)
    only the types of the predicate's arguments, not the types of non-argument
    variables. In one case in the compiler (mmc_analysis.m), this lead to
    some actually-used modules not being marked as such, which lead to
    false unused-import warnings to be generated for them. Fix this by scanning
    the types of all variables in all of a predicate's procedures, not just
    the arguments.

    Improve the infrastructure for debugging similar problems.

    Note some possibilities for future improvement.

    Change a predicate name to fit the naming scheme.

compiler/analysis.m:
    Add an XXX about a possible improvement.

compiler/hlds_out_module.m:
    Make the output we generate for instance methods more readable.
    As part of this, fix an old bug in the printing of the instance table:
    the first line of the first method of each concrete instance declaration
    was accidentally commented out.

compiler/parse_tree_out.m:
    Export a different utility predicate for hlds_out_module.m. Make its name
    conform to the scheme used by related predicates.

browser/browse.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/check_for_missing_type_defns.m:
compiler/check_promise.m:
compiler/exception_analysis.m:
compiler/handle_options.m:
compiler/inst_match.m:
compiler/mercury_to_mercury.m:
compiler/ml_tailcall.m:
compiler/module_qual.m:
compiler/op_mode.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_tree_out_clause.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_pred_decl.m:
compiler/parse_tree_out_term.m:
compiler/parse_type_defn.m:
compiler/parse_type_name.m:
compiler/parse_util.m:
compiler/parse_vars.m:
compiler/prog_ctgc.m:
compiler/recompilation.usage.m:
compiler/resolve_unify_functor.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/write_deps_file.m:
library/bt_array.m:
    Delete unused imports.

compiler/module_qual.qual_errors.m:
    Import a module that the parent module_qual.m doesn't import anymore.

tests/warnings/bug412.{m,exp}:
    The test case for this bug.

tests/warnings/Mmakefile:
tests/warnings/Mercury.options:
    Enable the new test case.

tests/invalid/import_in_parent.err_exp:
    Update the expected output for this test case. The parent module
    does not use the imported module (bool) at all, so this is what the
    error message says after this diff, though its submodule does use bool.
2016-07-17 10:20:29 +02:00
Zoltan Somogyi
f0ffbbc13c Convert (C->T;E) to (if C then T else E). 2015-12-01 05:35:29 +11:00
Zoltan Somogyi
8410473315 Prevent overflow when computing Mid in binary searches.
library/array.m:
library/bt_array.m:
    As above.
2014-12-21 21:12:37 +11:00
Zoltan Somogyi
7f9791aa26 Standardize divider line lengths in the library.
library/*.m:
    As above.

tool/stdlines:
    A new shell script to do the job.
2014-11-23 22:05:34 +11:00
Julien Fischer
bed96b93ff Avoid module qualification in library interfaces where possible.
NOTE: this change does not affect the io module -- I've left that for a
separate change.

library/*.m:
	As per the recent change to the coding standard, avoid module
	qualification in library interfaces where possible.

	Reformat declarations and descriptive comments to better utilise
	any space freed up by the above.
2014-10-10 15:08:24 +11:00
Julien Fischer
9cd94b5c72 Various minor cleanups and syntax updates for the standard library.
Estimated hours taken: 1
Branches: main

Various minor cleanups and syntax updates for the standard library.
There are no changes to any algorithms.

library/injection.m:
library/set.m:
library/sparse_bitset.m:
	Use promise_equivalent_clauses where appropriate.

library/set_ordlist.m:
library/set_unordlist.m:
	Convert these module to 4-space indentation:
		Convert these module to 4-space indentation

library/*.m:
	Convert some if-then-elses into switches.

	Remove unnecessary module qualification - this is related
	mainly to the breakup of std_util and the fact that on
	the 0.13 branche we had two versions of the all-solutions
	predicates.

	Various other style cleanups.

vim/syntax/mercury.vim:
	Highlight promise_equivalent_clauses appropriately.
2006-10-23 00:33:04 +00:00
Peter Ross
84ffc0924d Fix --warn-unused-imports warnings in some of the modules.
Estimated hours taken: 4
Branches: main

library/*.m:
compiler/*.m:
	Fix --warn-unused-imports warnings in some of the modules.
2006-09-27 06:17:09 +00:00
Julien Fischer
e0f5ac47db Make it easier for vi to jump past the initial comments
Estimated hours taken: 0.1
Branches: main

library/*.m:
	Make it easier for vi to jump past the initial comments
	at the head of a module.
2006-04-19 05:18:00 +00:00
Zoltan Somogyi
b293bd999d Replace __ with . as the module qualifier everywhere.
Estimated hours taken: 1
Branches: main

library/*.m:
	Replace __ with . as the module qualifier everywhere.

tests/hard_coded/test_injection.exp:
	Replace __ with . as the module qualifier in expected exceptions.
2006-03-07 22:23:58 +00:00
Zoltan Somogyi
57b8f436eb Convert to four-space indentation most of the library modules that
Estimated hours taken: 4
Branches: main

library/*.m:
	Convert to four-space indentation most of the library modules that
	weren't already indented that way. Use predmode syntax where possible.
	In some modules, shorten long lines by deleting module name prefixes.
	Fix departures from our coding standards.

	In some modules, simplify code, mostly using field names and/or state
	variables.

	There are no changes in algorithms, except for neg_list in integer.m.
2005-10-17 11:35:22 +00:00
Zoltan Somogyi
88c7539230 Import only one module per line, as we already do in the compiler
Estimated hours taken: 0.3
Branches: main

library/*.m:
	Import only one module per line, as we already do in the compiler
	directory.
2005-06-16 04:08:07 +00:00
Julien Fischer
0361ac54fa Fix some spelling errors in documentation/comments.
Estimated hours taken: 0.1
Branches: main

library/array.m:
library/bt_array.m:
library/io.m:
library/math.m:
library/store.m:
	Fix some spelling errors in documentation/comments.
2003-08-28 06:56:51 +00:00
Peter Moulder
e2083c49d3 Fix copy&paste doc error. At the same time, switch from imperative
Estimated hours taken: 0.2

library/bt_array.m:
	Fix copy&paste doc error.  At the same time, switch from imperative
	to declarative comment.
2003-08-17 02:54:20 +00:00
Zoltan Somogyi
6554ef7daa Replace "is" with "=".
Estimated hours taken: 2
Branches: main

Replace "is" with "=".
Add field names where relevant.
Replace integers with counters where relevant.
2003-05-26 09:01:46 +00:00
Mark Brown
3b7bf4b7d2 Remove the assumption on user supplied comparison predicates that
Estimated hours taken: 3
Branches: main

Remove the assumption on user supplied comparison predicates that
C(X, Y, =) implies X = Y (similarly for comparison functions).  Our code
shouldn't need to assume this, and sometimes more general orderings are
useful (for example, when you only want to compare the key of a key-value
pair).  The existing assumptions were not documented anywhere, so we now
document the remaining assumptions in builtin.m.

With this assumption gone the issue of the stability of library sorting
predicates that allow a user supplied ordering arises, since elements may
be equivalent according to the ordering even though they are not equal.
Therefore modify the documentation of standard library predicates to make
clear what we do with equivalent elements, and make minor modifications to
the code to ensure that it does as we claim.

Although the builtin comparison predicates are guaranteed to satisfy the
assumption, we nevertheless remove it from the implementation of predicates
in list.m that use builtin comparison.  The rationale for this is that we
don't need the assumption, and it may not be robust if in future we ever
decide to allow user defined comparison.

NEWS:
	Mention the changed assumptions about user supplied comparison
	predicates and functions.

	Mention the new predicate exported from list.m.

library/builtin.m:
	Add types comparison_pred/1 and comparison_func/1, and corresponding
	insts.  Document the assumptions we make about comparison predicates
	and functions.

library/list.m:
	Modify sort/3, sort_and_remove_dups/3, merge/4 and
	merge_and_remove_dups/4, as well as any functional versions, to use
	the new types.  Document the stability of sorting, and modify the
	code to ensure that we conform to this.

	Add remove_adjacent_dups/3, which takes a user supplied comparison
	predicate and determines whether elements are duplicates based on
	this, rather than the usual equality.

	Modify the implementation of some predicates that use compare, to
	avoid the unnecessary assumption.

	Fix some spelling and grammatical errors.

library/array.m:
library/bt_array.m:
	Modify the interface of {,bt_}array__bsearch to use the new types
	and insts.  Update the documentation.

tests/hard_coded/Mmakefile:
tests/hard_coded/stable_sort.exp:
tests/hard_coded/stable_sort.m:
	A test case that checks the stability of list__sort.
2002-09-16 06:07:49 +00:00
Simon Taylor
550e253206 Allow field access functions to take extra arguments.
Estimated hours taken: 5

Allow field access functions to take extra arguments.
Change the field update function names from `'field:='/2' to `'field :='/2'.

compiler/make_hlds.m:
        Handle field names with arguments.

compiler/hlds_pred.m:
        Add " :=" as the suffix for a field update function,
        rather than ":=".

compiler/typecheck.m:
        Update instances of `field:='/2 in comments.

compiler/det_util.m:
compiler/simplify.m:
        `det_info_vartypes' was defined using the `field:=' syntax.
        Change it into a normal predicate for bootstrapping.

library/array.m:
library/bt_array.m:
library/map.m:
        Add field access functions `elem/2' and `'elem :='/3'.
        For maps, the `elem' function calls `map__search',
        so add field access functions `det_elem' and `det_elem :='
        to call `map__lookup' and `map__det_update'.

NEWS:
doc/reference_manual.tex:
        Document the changes.

        Improve readability by changing occurrences
        of `X^field' to `X ^ field'.

tests/hard_coded/typeclasses/record_syntax.{m,exp}:
        Test field names with arguments.

tests/invalid/record_syntax_errors.err_exp:
	Update the expected output.
2000-12-13 00:00:55 +00:00
Simon Taylor
dedcf29a30 Make the function versions of predicates appear in the
Estimated hours taken: 2.5

library/*.m
	Make the function versions of predicates appear in the
	Mercury Library Reference Manual.
2000-11-12 08:51:39 +00:00
Fergus Henderson
6a6e5495ed Ralph Becket <rwab1@cam.sri.com>'s changes to add functions for
Estimated hours taken: 6

library/pqueue.m:
library/assoc_list.m:
library/getopt.m:
library/bag.m:
library/bimap.m:
library/bintree.m:
library/bintree_set.m:
library/bt_array.m:
library/eqvclass.m:
library/graph.m:
library/group.m:
library/queue.m:
library/rbtree.m:
library/stack.m:
library/term.m:
library/varset.m:
library/tree234.m:
library/relation.m:
library/set.m:
library/set_bbbtree.m:
library/set_ordlist.m:
library/set_unordlist.m:
	Ralph Becket <rwab1@cam.sri.com>'s changes to add functions for
	the remaining output det predicates in a number of modules in the
	standard library.  Basically, for each

		:- pred f(in, ..., in, out) is det.

	he has added the declaration

		:- func f(in, ..., in) = out.

	and definition

		f(X1, ..., Xn) = Y :-
			f(X1, ..., Xn, Y).

	The changes were made using a mostly automatic process.
1999-10-30 04:16:13 +00:00
Fergus Henderson
7cb525fde3 Undo Zoltan's bogus update of all the copyright dates.
Estimated hours taken: 0.5

library/*.m:
compiler/*.m:
	Undo Zoltan's bogus update of all the copyright dates.
	The dates in the copyright header should reflect the years
	in which the file was modified (and no, changes to the
	copyright header itself don't count as modifications).
1998-01-23 12:33:43 +00:00
Zoltan Somogyi
9ae7acc593 Update all the copyright dates for 1998.
Estimated hours taken: 0.5

library/*.m:
	Update all the copyright dates for 1998.
1998-01-13 10:01:32 +00:00
Fergus Henderson
06e476c165 A few small changes towards supporting backtrackable destructive update
Estimated hours taken: 1

A few small changes towards supporting backtrackable destructive update
better.

library/mercury_builtin.m:
	Add new insts mdi/1 and mostly_dead/0.

library/array.m:
	Change the name of the inst for unique arrays
	from `array' to `uniq_array' (someone got over-enthusiastic
	with global search and replace when uniq_array.m was
	renamed array.m).
	Add insts for non-unique arrays and mostly-unique arrays.

library/bt_array.m:
	Add a comment.
1997-09-06 18:23:40 +00:00
Andrew Bromage
e1e0e68f42 Changed some functional versions of -/2 into is/2 so that
Estimated hours taken: 0.1

library/bt_array.m:
	Changed some functional versions of -/2 into is/2 so that
	the module works in Prolog.
1997-07-28 05:27:51 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Andrew Bromage
c485413c8c The main purpose of this change is to rename array.m as bt_array.m, and
Estimated hours taken: 6

The main purpose of this change is to rename array.m as bt_array.m, and
uniq_array.m as array.m.  The interfaces of those two modules have grown
slightly so that they match a little more closely.  Details are in the
file NEWS.

The implementation of bt_array (formerly array) has been changed to use
a slightly more efficient implementation.

NEWS:
	Interface changes documented.

library/array.m:
library/bt_array.m:
	Changes mentioned above and detailed in the NEWS file.

library/uniq_array.m:
	Bereft of life and resting in peace.

library/io.m:
library/library.m:
library/std_util.m:
library/term.m:
compiler/base_type_layout.m:
runtime/deep_copy.c:
runtime/type_info.h:
	Minor changes to fix the special case of base_type_layout
	operations for arrays rather than uniq_arrays.

tests/hard_coded/write.exp:
tests/hard_coded/write.m:
	Test writing of arrays.

tests/general/array_test.exp:
tests/general/array_test.m:
	Test some array/bt_array operations.
1997-07-25 05:15:17 +00:00