Commit Graph

40 Commits

Author SHA1 Message Date
Zoltan Somogyi
a653024ab7 Update many aspects of style in sample programs.
If we want to encourage people to read the sample programs
and learn Mercury programming from them, they should not be written
in an obsolete style.

samples/beer.m:
samples/calculator.m:
samples/calculator2.m:
samples/concurrency/midimon/midimon.m:
samples/diff/diff_out.m:
samples/e.m:
samples/eliza.m:
samples/muz/dict.m:
samples/muz/higher_order.m:
samples/muz/muz.m:
samples/muz/typecheck.m:
samples/muz/word.m:
samples/muz/zabstract.m:
samples/muz/zlogic.m:
samples/muz/zparser.m:
samples/muz/ztoken.m:
samples/muz/ztoken_io.m:
samples/muz/ztype.m:
samples/muz/ztype_op.m:
samples/rot13/rot13_concise.m:
samples/rot13/rot13_gustavo.m:
samples/rot13/rot13_juergen.m:
samples/rot13/rot13_ralph.m:
samples/rot13/rot13_verbose.m:
samples/solutions/all_solutions.m:
samples/solutions/n_solutions.m:
samples/solutions/one_solution.m:
samples/solutions/some_solutions.m:
samples/solver_types/eqneq.m:
samples/solver_types/sudoku.m:
samples/solver_types/test_eqneq.m:
    Replace uses of __ as module qualifier with dot.

    Replace (C->T;E) with (if C then T else E).

    Use our usual indentation for if-then-elses and for switches.

    Import one module per line. Put those imports into alphabetical order.

    Replace many uses of DCGs with state variables, leaving DCGs
    mostly just for parsing code.

    Use predmode declarations where this helps.

    Put predicates in top-down order where relevant.

    Use io.format where this helps.

    Do not put more than one predicate call on one line.

    Put each function symbol in a du type on a separate line.

    Put spaces after commas, around the bar in list syntax,
    around arithmetic operators, and around minus signs used for pairs.

    Replace tab indentation with four-space indentation.

    Delete spaces at the ends of lines.
    Replace two or more consecutive blank lines with one blank line.
    Delete blank lines that do not help structure the code.

    There are probably still some examples of old practices remaining;
    I do not claim to have fixed them all.
2021-07-07 05:32:09 +10:00
Peter Wang
8da4853b49 Update programs for getopt changes.
benchmarks/progs/icfp2000_par/main.m:
benchmarks/progs/mandelbrot/mandelbrot.m:
benchmarks/tools/log_to_r/log_to_r.m:
extras/align_right/align_right.m:
extras/error/error.m:
extras/gator/evolve.m:
extras/moose/options.m:
samples/concurrency/midimon/midimon.m:
samples/diff/diff.m:
samples/muz/muz.m:
    Conform to getopt.process_options now returning structured errors
    instead of strings.
2020-10-26 16:24:11 +11:00
Zoltan Somogyi
4aed1a57e4 Print an arg type list diff for arg lists with wrong arity.
When a user writes a clause for a predicate (or function) that does not exist
with that arity, but does exist with one or more other arities, report not
just the list of the other arity/arities, but, for each such other arity,
a diff between the declared arg types and the inferred arg types.

After this diff, we generate output like this:

bad_pred_arity.m:027: Error: clause for predicate `bad_pred_arity.p'/4
bad_pred_arity.m:027:   without corresponding `:- pred' declaration.
bad_pred_arity.m:027:   However, predicates of that name do exist with arities
bad_pred_arity.m:027:   3 and 5.
bad_pred_arity.m:027: Inferred :- pred p(int, string, int, string).
bad_pred_arity.m:027:   The argument list difference from the arity 3 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   +     string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )
bad_pred_arity.m:027:   The argument list difference from the arity 5 version
bad_pred_arity.m:027:   is
bad_pred_arity.m:027:     pred(
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:   -     float,
bad_pred_arity.m:027:         string,
bad_pred_arity.m:027:         int,
bad_pred_arity.m:027:         string
bad_pred_arity.m:027:     )

compiler/typecheck_errors.m:
    Generate the diff part of the message above.

compiler/typecheck.m:
    Invoke typecheck_errors.m when relevant.

compiler/error_util.m:
    When comparing two error_specs, switch from a two-level comparison
    (first the contexts of error_msgs, then everything else) to three levels
    first the contexts of error_msgs, then their error_msg_components,
    then everything else). This is needed to allow the error message from
    make_hlds_error.m (which reports the error and mentions the arities
    with which the named predicate or function does exist) come out before
    the informational message from typecheck.m that prints the inferred
    arg types and their differences from the other arities. (With the old
    comparison, the difference in severity would trump the invisible order
    components that this diff includes in both specs to force the desire
    order.)

    Base the code comparing error_specs on the code for comparing error_msgs.
    Move the two previously separate pieces code for those tasks next to each
    other.

compiler/make_hlds_error.m:
    Add the invisble ordering component.

    When we see clauses with two or more wrong arities for a given predicate
    or function, don't list the automatically created pred declaration
    for an *earlier* wrong-arity clause as a real declaration whose arity
    is to be listed in the error messages we generate for *later* wrong-arity
    clauses.

    Add some documentation.

compiler/add_pred.m:
    Factor out some common code.

library/edit_seq.m:
    A new module for computing diffs.

library/library.m:
library/MODULES_DOC:
    Add the new module to the standard library.

tests/hard_coded/edit_seq_test.{m,exp}:
    A new test case for the diff algorithm.

tests/invalid/bad_pred_arity.{m,err_exp}:
    A new test case for the new error message.

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
    Enable the new test cases.

tests/invalid/bigtest.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_main.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/try_detism.err_exp2:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
    Update these files to expect error messages in the new order.

samples/diff/*.m:
    Fix comments, mostly by moving them to where our programming style
    wants them.
2019-01-03 08:57:20 +11:00
Paul Bone
fc4b3ff196 Remove .cvsignore files
Remove old .cvsignore files, moving their contents to .gitignore files.
There are now no .cvsignore files in the repository.

I've also sorted some .gitignore files and avoided repeating a pattern in a
subdirectory's .gitignore file when it is already mentioned in the parent
.gitignore file.
2017-04-04 12:05:56 +10:00
Julien Fischer
59933b6530 Update the syntax in diff sample.
samples/*.m:
    As above.
2015-12-15 01:44:08 +11:00
Julien Fischer
9c96387183 Fix formatting of sample programs.
samples/Mmakefile:
    Add the beer program to list of targets.

samples/*.m:
    Convert (C->T;E) to (if C then T else E).

    Delete trailing whitespace.

    Use predmode syntax instead of separate pred and mode
    declarations.

samples/interpreter.m:
    Fix up one predicate that had some clauses that used
    DCGs and others that used state variables.

    Don't use the name 'IO' for something that isn't the I/O state.

samples/diff/*.m:
samples/c_interface/c_calls_mercury/mercury_main.m:
samples/c_interface/short_example.m:
    Delete trailing whitespace.
2015-12-14 16:06:13 +11:00
Zoltan Somogyi
d33273d033 Tell vim not to expand tabs in Makefiles.
This file-specific setting will override a default setting of expandtabs
in $HOME/.vimrc.

*/Makefile:
*/Mmakefile:
    As above.

tests/hard_coded/.gitignore:
    Don't ignore the purity subdir. This ignore must have been left over
    from when purity.m was a test in hard_coded, not hard_coded/purity,
    and it ignored an executable, not a directory.
2015-01-08 22:07:29 +11:00
Julien Fischer
d2e55c1b22 Delete a reference to mtogl, which was removed several
Branches: main, 11.07

extras/graphics/README:
	Delete a reference to mtogl, which was removed several
	releases ago.

compiler/options.m:
HISTORY:
samples/diff/diff_out.m:
samples/diff/options.m:
	Fix spelling and doubled-up words.
2011-07-16 12:04:10 +00:00
Julien Fischer
5e5bd28d3a Conform to the change of argument ordering for array.set/4.
Branches: main

samples/diff/file.m:
samples/diff/match.m:
samples/diff/myers.m:
	Conform to the change of argument ordering for array.set/4.
2011-05-25 01:51:46 +00:00
Julien Fischer
9f68c330f0 Change the argument order of many of the predicates in the map, bimap, and
Branches: main

Change the argument order of many of the predicates in the map, bimap, and
multi_map modules so they are more conducive to the use of state variable
notation, i.e. make the order the same as in the sv* modules.

Prepare for the deprecation of the sv{bimap,map,multi_map} modules by
removing their use throughout the system.

library/bimap.m:
library/map.m:
library/multi_map.m:
	As above.
NEWS:
	Announce the change.

	Separate out the "highlights" from the "detailed listing" for
	the post-11.01 NEWS.

	Reorganise the announcement of the Unicode support.

benchmarks/*/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
extras/*/*.m:
mdbcomp/*.m:
profiler/*.m:
tests/*/*.m:
ssdb/*.m:
samples/*/*.m
slice/*.m:
	Conform to the above change.

	Remove any dependencies on the sv{bimap,map,multi_map} modules.
2011-05-03 04:35:04 +00:00
Julien Fischer
5b0fa9a80b Make this code conform to our current coding guidelines -- there
Branches: main, 11.01

samples/diff/*.m:
	Make this code conform to our current coding guidelines -- there
	are no changes to any algorithms.

	Delete imports of unused modules.
2011-01-07 16:35:36 +00:00
Julien Fischer
1b4eee18d4 Fix up various problems in some of the samples that cause the compiler
Branches: main, 11.01

Fix up various problems in some of the samples that cause the compiler
to emit warnings.

samples/diff/Mmakefile:
	Delete an old workaround for gcc 2.7.2 - we no longer support
	gcc versions that old.

samples/diff/options.m:
samples/muz/muz.m:
samples/typecheck.m:
	Avoid some Mercury compiler warnings.
2011-01-07 06:40:22 +00:00
Julien Fischer
39506995ce Update this file.
samples/diff/.cvsignore:
	Update this file.
2007-07-16 11:45:23 +00:00
Julien Fischer
9b9f28e4da Conform to recent changes in the standard library.
samples/diff/*.m:
	Conform to recent changes in the standard library.

	Conform to our current coding standard.
2006-06-28 09:22:40 +00:00
Peter Ross
f30ed91489 Backout some accidently committed changes.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_construct.c:
samples/diff/Mmakefile:
	Backout some accidently committed changes.
2003-03-10 14:25:44 +00:00
Peter Ross
efdaf1f224 Fix a performance bug where dead_pred_elim was taking a significant
Estimated hours taken: 6
Branches: main

Fix a performance bug where dead_pred_elim was taking a significant
amount of time to delete entries from the predicate_table.  With this
change dead_pred_elim goes from 12 minutes to 55 seconds CPU time in
the IL grade when compiling accumulator.m with
--intermodule-optimization turned on.

compiler/hlds_module.m:
	Implement a new predicate, predicate_table_restrict, which
	restricts the predicate_table to include only a subset of the
	predicates.
	Rather than deleting all the non-needed entries, this
	predicate builds the predicate_table from scratch again, hence
	this predicate is only useful when the number of predicates to
	keep is significantly less than the number of predicates to
	delete.
	Change predicate_table_do_insert so that it records in the
	pred_info whether or not a predicate can only be accessed by
	its fully qualified name, this is needed so that the
	predicate_table can be rebuilt correctly.

compiler/dead_proc_elim.m:
	Use predicate_table_restrict to restrict the set of pred_ids
	in the predicate_table rather than module_info_remove_predicate
	as the amount of predicates to keep is in general
	significantly smaller than the number of predicates to keep.

compiler/hlds_pred.m:
	Add a new pred_marker which indicates whether or not a
	predicate can only be accessed by its fully qualified name.

compiler/hlds_out.m:
compiler/intermod.m:
	Handle the new pred_marker.
2003-03-10 14:10:55 +00:00
Fergus Henderson
9f03abee9a Add missing `import_module' statements in the interface section.
Estimated hours taken: 2

compiler/globals.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/transform_llds.m:
compiler/vn_order.m:
compiler/vn_verify.m:
samples/diff/globals.m:
	Add missing `import_module' statements in the interface section.
	(The current version of the compiler doesn't detect these errors.
	I have a fix for that bug, but I plan to commit it separately.)
2001-02-08 11:37:53 +00:00
Fergus Henderson
ed4a6938f0 Fix a bug: it was passing `-O0' in MGNUCFLAGS, rather than CFLAGS.
Estimated hours taken: 0.25

samples/diff/Mmakefile:
	Fix a bug: it was passing `-O0' in MGNUCFLAGS, rather than CFLAGS.
	This broke things if you tried to pass an mgnuc option such as
	`--inline-alloc' in EXTRA_MGNUCFLAGS on the command-line.
2000-09-21 07:58:54 +00:00
Simon Taylor
869ba64018 Convert a call to copy to unsafe_promise_unique, since copy
Estimated hours taken: 0.25

samples/diff/globals.m:
	Convert a call to copy to unsafe_promise_unique, since copy
	is buggy at the moment.
1998-09-21 06:46:32 +00:00
Andrew Bromage
b3af56e8fa Modified files
Estimated hours taken: 30

Modified files
--------------

samples/diff/Mmakefile:
	Minor documentation update.

samples/diff/README:
samples/diff/TODO:
	Update stuff that's now done, do a couple of minor wording
	changes.

samples/diff/diff.m:
	Fix case of identical filenames (which implicitly assumed
	no_diff_implies_no_output).  Add new match pass, call the
	new diff algorithm.

samples/diff/diff_out.m:
	Add --cvs-merge-conflict output style.  Slight reorganisation
	of top-level predicate.  Lots of small fixes to use better
	syntax (e.g. functional style for integer maths operations).

samples/diff/difftype.m:
	Added first_mentioned_positions/3, last_mentioned_positions/3,
	add_edit/4.

samples/diff/file.m:
	Use io__read_line_as_string.

samples/diff/filter.m:
	Minor syntax/wording changes.

samples/diff/options.m:
	Update all the newly handled options.

New files
---------

samples/diff/myers.m:
	New diff algorithm.

samples/diff/match.m:
	New pass to match common lines in the files to be diffed.

Removed file
------------

samples/diff/lcss.m:
	Functionality replaced by myers.m.
1998-09-15 04:54:41 +00:00
Andrew Bromage
bc0a109801 Modified files
Estimated hours taken: 30

Modified files
--------------

samples/diff/README:
	Info about this new version.  Put the existing READMEs in
	reverse order, so that they'll be in the most sensible order
	for someone reading top-down.

samples/diff/Mmakefile:
	Supply more detail about which bit of this program GCC 2.7.2
	under Digital Unix 3.2 doesn't compile properly.

samples/diff/diff.m:
	Slight reorganisation.  Accept options, remove some high
	coupling betweem diff__do_diff and lcss.m.

samples/diff/file.m:
	Add support for attaching a filename to a file.

samples/diff/lcss.m:
	Add more documentation, one slight performance improvement.
	lcss__to_diff now works on the reversed LCSS, to avoid going
	to the trouble of reversing it.

New files
---------

samples/diff/TODO:
	Meaning should be obvious.

samples/diff/diff_out.m:
	Replacement for diffs.m (which was never a very good name).
	Now contains code to display a diff in lots more output
	styles than previously supported.

samples/diff/difftype.m:
	Replacement for lcsstype.m.  Contains the type of a diff (but
	not of an lcss, which is now local to lcss.m, hence the
	renaming).

samples/diff/filter.m:
	Contains code to filter a diff before being displayed.  This
	is only required if the user specified that they didn't want
	to see part of the diff (e.g. with --ignore-blank-lines).

samples/diff/globals.m:
samples/diff/options.m:
	Support for option handling.

Removed files
-------------

samples/diff/diffs.m:
	Functionality moved to diff_out.m.

samples/diff/lcsstype.m:
	Functionality moved to difftype.m.
1998-01-13 00:52:08 +00:00
Fergus Henderson
2c4bd735b4 Add comment "This source file is hereby placed in the public domain".
Estimated hours taken: 0.25

samples/*:
	Add comment "This source file is hereby placed in the public domain".
1997-09-10 11:01:12 +00:00
Andrew Bromage
34ecf2050a Minor documentation fix.
Estimated hours taken: 0.05

Minor documentation fix.

samples/diff/README:
	It was, of course, not the fix which caused diff to bomb out,
	it was the problem solved by the fix.
1997-07-28 20:02:48 +00:00
Andrew Bromage
fb95516511 Added a clitic which was left out of the previous by mistake.
Estimated hours taken: very little

samples/diff/README:
	Added a clitic which was left out of the previous by mistake.
1997-07-28 06:03:49 +00:00
Andrew Bromage
5d9c15639c General cleanup and bug fix for diff. Features of this diff:
Estimated hours taken: 4

General cleanup and bug fix for diff.  Features of this diff:

	- Changed indenting so it more closely matches the
	  coding standard.

	- Bug fix which was causing it to bomb out if the two
	  files were identical.

	- Update to use unique arrays (array.m).

samples/diff/README:
	Added something which resembles this log message.

samples/diff/Mmakefile:
	Turned C optimisation off to get around a gcc 2.7.2 bug.

samples/diff/diff.m:
samples/diff/diffs.m:
samples/diff/file.m:
samples/diff/lcss.m:
samples/diff/lcsstype.m:
	Changes detailed above.
1997-07-28 06:00:55 +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
Fergus Henderson
f4a5dce039 Fix a couple of singleton variable warnings by prepending `_'
Estimated hours taken: 0.25

samples/diff/lcss.m:
	Fix a couple of singleton variable warnings by prepending `_'
	to the name of a couple of unused variable.
1997-04-15 05:02:33 +00:00
Fergus Henderson
8235e7af29 Rename all the Mmake' files as Mmakefile'.
Estimated hours taken: 0.5

Rename all the `Mmake' files as `Mmakefile'.  This is necessary to
avoid confusion between `Mmake' and `mmake' on case-insensitive file
systems.
1997-02-13 21:37:32 +00:00
Fergus Henderson
6a7d427f99 Committed the changes sent by Marnix Klooster <marnix@worldonline.nl>.
Estimated hours taken: 0.5

samples/diff:
	Committed the changes sent by Marnix Klooster <marnix@worldonline.nl>.
	His description of the changes:

	The major changes I made were

	* Moved code for manipulating and displaying diffs to a separate
	  module called diffs.m (and changed their calls in diff.m).  The type
	  'lcss,' needed both by the rest of lcss.m and by diffs.m, was moved
	  to a new module lcsstype.m.

	* Made lcss.m independent of files, and allowed it to process any kind
	  of list by adding polymorphism.  (The file processing calls have
	  been moved to diff.m.)

	* Added type synonyms 'pos' and 'segment' in diffs.m to clarify the
	  types.  Renamed 'single_diff' to 'edit'.

	* Added end-of-file match to the generated lcss, thereby allowing the
	  to_diff predicate to be simplified considerably.

	* Numbered lists from 0 internally in the lcss-algorithm.  This made
	  to_diff simpler still, but also forced changes in the diff-printing
	  part.

	* Removed the swapping in find_lcss, because it doesn't seem to help.

	* The array(string) representing a file in file.m was also renumbered
	  to begin with 0.

	* Added and corrected comments.

	Have fun,

	 <><

	Marnix
	--
	Marnix Klooster
	marnix@worldonline.nl
1996-10-29 17:11:56 +00:00
Fergus Henderson
e8f11687cd Add a .cvsignore file to the samples/Diff directory to keep `cvs update' quiet.
Estimated hours taken: 0.05

Add a .cvsignore file to the samples/Diff directory to keep `cvs update' quiet.
1996-01-23 09:31:16 +00:00
Andrew Bromage
e0872a7a4b Some cleanups so that diff works (better) with Prolog. 1995-06-16 06:46:32 +00:00
Andrew Bromage
d6a5cdfb75 General cleanups. 1995-06-02 03:55:39 +00:00
Andrew Bromage
e6c3613121 Final changes to diff, at least until getopt is done. 1995-06-01 06:08:39 +00:00
Andrew Bromage
15f345d18d More documentation added. 1995-05-31 06:07:04 +00:00
Andrew Bromage
37af6ba074 Lcss: the documented version. (Version with references coming soon.) 1995-05-31 05:52:15 +00:00
Fergus Henderson
70ad060033 Add a sample Mmake file.
samples/Diff/Mmake:
	Add a sample Mmake file.
1995-05-30 18:35:54 +00:00
Andrew Bromage
b4c351084f New improved diff! O(n log n) algorithm. 1995-05-25 05:34:41 +00:00
Andrew Bromage
dad6dd3982 Used new algorithm in diff 1995-05-24 04:53:43 +00:00
Andrew Bromage
946f58e744 Removed debug info from lcss 1995-05-23 00:16:41 +00:00
Andrew Bromage
7620375940 Diff sample program 1995-05-23 00:11:21 +00:00