Commit Graph

273 Commits

Author SHA1 Message Date
Julien Fischer
7fa1d3df5c Use io.write_prefixed_lines in more places.
samples/muz/muz.m:
    As above.
2023-09-04 20:04:32 +10:00
Julien Fischer
4f9ecf65b1 Use io.write_prefixed_lines in more places.
profiler/options.m:
    Use io.write_prefixed_lines for writing the usage message.

    Add -? as a synonym for --help.

samples/diff/options.m:
samples/mcowsay.m:
    Use io.write_prefixed_lines for writing the usage messages.
2023-09-03 23:28:29 +10:00
Zoltan Somogyi
e7498d6e0a s/classs/classes/ 2023-08-18 15:53:35 +02:00
Zoltan Somogyi
f4e24a37d0 s/classs/classes/ 2023-08-18 15:52:49 +02:00
Julien Fischer
13f01c98bd Ignore .obj files.
extras/.gitignore:
samples/.gitignore:
    As above.
2023-07-02 02:41:56 +10:00
Zoltan Somogyi
a5f9cb6851 Reduce differences between interpreter.m versions.
extras/trailed_update/samples/interpreter.m:
samples/interpreter.m:
    We have these two different versions of a pure Prolog interpreter
    as examples of Mercury code. Reduce the number of unneeded points
    of difference between them, by copying the better code at each such point
    to the other file.

tests/debugger/interpreter.m:
    This file is automatically copied from samples/interpreter.m.

tests/debugger/interpreter.exp:
    Expect the changes caused by the update to the source file.
2023-06-22 14:54:59 +02:00
Julien Fischer
df8455f76c Replace calls to an obsolete predicate.
samples/interpreter.m:
    As above.
2023-06-20 12:28:03 +10:00
Julien Fischer
4d854c3fe6 Replace calls to obsolete predicates.
samples/muz/ztoken_io.m:
    Replace the use of the I/O globals with a mutable.
2023-06-20 12:01:22 +10:00
Julien Fischer
8eefa09561 Replace a call to an obsolete predicate.
samples/muz/muz.m:
    As above.
2023-06-19 23:00:34 +10:00
Julien Fischer
dce2882f66 Replace calls to obsolete predicates.
samples/mcowsay.m:
    As above.
2023-06-19 22:55:39 +10:00
Julien Fischer
5f6981c7de Delete ancient workaround for g++ 2.7.
samples/c_interface/cplusplus_calls_mercury/Mmakefile:
samples/c_interface/mercury_calls_cplusplus/Mmakefile:
samples/c_interface/simpler_cplusplus_calls_mercury/Mmakefile:
     As above.
2023-03-11 14:21:10 +11:00
Julien Fischer
0cd62edc7c Clean-ups and fixes for the C interface examples.
samples/c_interface/*:
    Replace left over references to the old c_header_code pragma.

    Replace some uses of '__' as a module qualifier.

    Replace tabs with spaces.

    Add some missing words.
2023-02-25 12:53:26 +11:00
Julien Fischer
51745bee09 Remove execute bit from a Makefile.
samples/c_interface/standalone_c/Makefile:
     As above.
2022-12-14 01:36:29 +11:00
Zoltan Somogyi
d481a42f59 Give each op class (infix, prefix etc) its own slot.
library/ops.m:
    Instead of an op_table mapping a string to a list of one or more op_infos,
    make it map the string to a single structure, the op_infos, which has
    four slots, one each for infix, binary prefix, prefix and postfix
    op information. This allows parsers and unparsers to go directly to
    the kind of operator (e.g. infix or prefix) that they are interested in.

NEWS:
    Announce the change.

compiler/parse_tree_out_term.m:
library/mercury_term_parser.m:
library/pretty_printer.m:
library/stream.string_writer.m:
library/string.to_string.m:
samples/calculator2.m:
tests/hard_coded/bug383.m:
    Conform to the change. In several places, the new operator representation
    allows the replacement of loops with direct lookups, and the replacement
    of if-then-else chains with switches.

    Add reminders about keeping two predicates in sync.
2022-11-14 13:46:22 +11:00
Zoltan Somogyi
c6d857cb6b Cleanups of ops-related code.
library/io.m:
    Delete the set_io_table predicate, which did nothing and was never
    called from anywhere, and the get_io_table predicate, which always
    returned the same op_table. They were in io.m's interface, but in the
    not-publicly-visible part of the interface.

library/ops.m:
    Rename the lookup_op method to is_op.

    Delete references to the predicates deleted from io.m.

NEWS:
    Announce the lookup_op->is_op rename.

compiler/parse_tree_out_term.m:
library/mercury_term_parser.m:
library/string.to_string.m:
library/term_io.m:
samples/calculator2.m:
tests/hard_coded/bug383.m:
    Conform to the lookup_op->is_op rename.

    Replace calls to get_io_table with code that directly gets
    the Mercury op table.

    In parse_tree_out_term.m, call the predicates operating on the
    Mercury op table directly, not through the op_table type class.

    In mercury_term_parser.m, update some comments.

    In term_io.m, use OpTable to refer to op_tables.

tests/hard_coded/stdlib_init.{m,exp}:
    Don't test get_io_table.
2022-11-12 12:53:07 +11:00
Zoltan Somogyi
4d15588c8b Address review comments.
NEWS:
    Mention that we do no longer accept : as module name separator.
    Improve wording.

extras/README.md:
    Document the new old_library_modules directory.

library/ops.m:
    Fix wording, and a dangling reference.

samples/calculator2.m:
    Update to use the new ops.m.
2022-11-12 01:36:32 +11:00
Zoltan Somogyi
de75b98b18 Make higher operator priorities bind tighter.
Mercury inherited its original system of operator priorities from Prolog,
because during its initial development, we wanted to be able execute
the Mercury compiler using NU-Prolog and later SICStus Prolog.
That consideration has long been obsolete, and now we may fix the
design error that gifted Prolog with its counter-intuitive system
of operator priorities, in which higher *numerical* operator priorities
mean lower *actual* priorities. This diff does that.

library/ops.m:
    Change the meaning of operator priorities, to make higher numerical
    priorities mean also higher actual priorities.

    This semantic change requires corresponding changes in any other module
    that uses ops.m. To force this change to occur, change the type
    representing priorities from being a synonym for a bare int to being
    a notag wrapper around an uint.

    The old "assoc" type had a misleading name, since it is related to
    associativity but is not itself a representation of associativity.
    Its two function symbols, which used to be just "x" and "y", meant that
    the priority of an argument must be (respectively) greater than,
    or greater than equal to, the priority of the operator. So rename
    x to arg_gt, y to arg_ge, and assoc to arg_prio_gt_or_ge.

    Rename the old adjust_priority_for_assoc predicate to min_priority_for_arg,
    which better expresses its semantics. Turn it into a function, since
    some of its users want it that way, and move its declaration to the
    public part of the interface.

    Add a method named tightest_op_priority to replace the use of 0
    as a priority.

    Rename the max_priority method as the loosest_op_priority method.

    Add a method named universal_priority to replace the use of
    max_priority + 1 as a priority.

    Add a function to return the priority of the comma operator,
    to allow other modules to stop hardcoding it.

    Add operations for comparing priorities and for incrementing/decrementing
    priorities.

    Change the prefix on the names of the predicates that take op_infos
    as inputs from "mercury_op_table_" to "op_infos_", since the old prefix
    was misleading.

    Add a note on an significant old problem with an exported type synonym.

library/mercury_term_parser.m:
    Conform to the changes above.

    Delete unnecessary module qualifiers, since they were just clutter.

    Add "XXX OPS" to note further opportunities for improvement.

library/pprint.m:
    Conform to the changes above.

    Rename a function to avoid ambiguity.

library/pretty_printer.m:
library/stream.string_writer.m:
library/string.to_string.m:
library/term_io.m:
    Conform to the changes above.

library/string.m:
    Add a note on an significant old problem.

NEWS:
    Announce the user-visible changes.

tests/hard_coded/bug383.m:
    Update this test case to use the new system of operator priorities.

tests/hard_coded/term_io_test.{m,inp}:
    Fix white space.

extras/old_library_modules/old_mercury_term_parser.m:
extras/old_library_modules/old_ops.m:
    The old contents of the mercury_term_parser and ops modules,
    in case anyone wants to continue using them instead of updating
    their code to use their updated equivalents.

samples/calculator2.m:
    Import the old versions of mercury_term_parser and ops.
2022-11-11 00:11:44 +11:00
Julien Fischer
78150cddd2 Minor fix for a sample.
samples/mcowsay.m:
   Print an empty speech / though bubble if there is nothing to be
   read on the standard input.
2022-06-16 20:50:56 +10:00
Julien Fischer
56946aa88a Simplify some code.
samples/mcowsay.m:
    Use io.read_file_as_string/4 in a spot instead of
    reading a file using the stream interface.
2022-06-16 13:41:42 +10:00
Julien Fischer
4c6c430c34 Add another sample: mcowsay.
samples/mcowsay.m:
    A Mercury version of the cowsay program. It serves an more extended
    example (but still small) example of how to write command line
    utilities in Mercury.

samples/README.md:
    Include the new sample.

samples/Mmakefile:
    Include the new sample.

    Put the list of sample programs in alphabetical order.
2022-06-16 13:33:53 +10:00
Julien Fischer
8ef9073be2 Delete remaining references to --use-trail-segments.
doc/user_guide.texi:
extras/trailed_update/samples/Mmakefile:
extras/trailed_update/tests/Mmakefile:
samples/solver_types/Mercury.options:
scripts/init_grade_options.sh-subr:
    As above.

RELEASE_NOTES_NEXT:
    Delete item concerning the above.
2022-04-18 21:45:15 +10:00
Julien Fischer
f3a34e4651 Replace uses of __ as a module qualifier.
samples/muz.zbstract.m:
tests/*/*.m:
    As above.
2022-04-14 20:25:10 +10:00
Julien Fischer
66c1448fb0 Fix spelling.
samples/interpreter.m:
    As above.
2022-03-30 18:02:08 +11:00
Julien Fischer
dd0a15409d Update the Mercury-Fortran interface example.
samples/c_interface/mercury_calls_fortran/Mmakefile:
    g77 was replaced by gfortran in GCC 4.0, use the latter in
    this example.

samples/c_interface/mercury_calls_fortran/fortran_main_int.m:
     Replace a ':- pragma import' with an equivalent foreign_proc.

     Describe the current gfortran name mangling scheme and delete
     references to g77 command line options not supported by gfortran.

samples/c_interface/mercury_calls_fortran/mercury_main.m:
     Replace tabs with spaces.
2022-03-28 15:24:16 +11:00
Julien Fischer
5f2aac88c3 Replaces calls to deleted predicates.
samples/concurrency/midimon/midimon.m:
     As above.
2022-03-25 23:32:50 +11:00
Julien Fischer
39ef38ad27 Replace call to io.see/4 in a sample.
samples/solver_types/sudoku.m:
    As above.
2022-03-25 12:34:12 +11:00
Julien Fischer
90ceef4065 Add missing interface declarations.
samples/c_interface/simpler_c_calls_mercury/c_main.m:
samples/c_interface/simpler_cplusplus_calls_mercury/cpp_main.m:
    As above.
2022-03-25 12:24:00 +11:00
Julien Fischer
a8eddabbf1 Fix description in samples README.
samples/REAMDE.md:
    Fix the description of the 'sort' sample, which hasn't actually
    reflected what that sample did since the description was added.
2022-03-06 14:42:36 +11:00
Julien Fischer
41d2622092 Fix compilation of samples/sort.m.
samples/sort.m:
   Replace use of io.see and io.tell with explicit streams.

   Use state variable notation in more spots.

   Simplify some code.
2022-03-06 02:49:37 +11:00
Julien Fischer
86825c0e0e Fix compilation of samples/expand_terms.
samples/expand_terms.m:
     Replace calls to the now deleted term_io.read_term/3.
2022-03-06 02:30:24 +11:00
Zoltan Somogyi
84223268a0 Delete the tests/general/interpreter test case.
tests/general/interpreter.{m,inp,exp}:
tests/general/Mmakefile:
    As above: delete this test case.

samples/interpreter.m:
    Delete reference to the deleted test case.

tests/debugger/interpreter.m:
    Delete reference to the deleted test case in this copy of
    samples/interpreter.m.

tests/debugger/interpreter.exp:
tests/debugger/interpreter.exp2:
    The last update of interpreter.exp was in 2003. The command we invoke
    this test case with has changed several times since then, but none
    of them have been reflected in interpreter.exp, so now there is no way
    for it to be matched. This diff deletes interpreter.exp, and renames
    the old interpreter.exp2 to become the new interpreter.exp.

tests/general/arithmetic.nl:
tests/general/interpreter.nl:
tests/general/string_test.nl:
    Delete these relics of the time when we compared output generated
    by Mercury to output generated by NU-Prolog, since NU-Prolog is long dead.

tests/general/arithmetic.m:
tests/general/string_test.m:
    Update programming style, and factor out common code.
2022-03-04 17:25:20 +11:00
Zoltan Somogyi
92f60e5c70 Standardize on one interpreter.m.
samples/interpreter.m:
    Make this the primary copy of interpreter.m. Incorporate the improvements
    from the other two versions in tests, and generalize them to be suitable
    as a sample program.

tests/debugger/interpreter.m:
tests/general/interpreter.m:
    Make these copies of the primary version.

tests/debugger/Mmakefile:
tests/general/Mmakefile:
    Keep the tests copies of the primary version.

tests/general/interpreter.exp:
    Expect an output now generated for parameter-less invocations.
2022-03-04 14:45:01 +11:00
Julien Fischer
01061532ab Add short example of Java interface.
samples/java_interface/short_example.m:
    A Java version of the short example.

samples/java_interface/README.md:
    Add an entry for the new example.

samples/c_interface/README.md:
samples/csharp_interface/README.md:
    Fix wording.
2022-01-20 03:42:56 +11:00
Julien Fischer
f23b80613a Adjust a C# interface example.
samples/csharp_interface/standalone_csharp/CSharpMain.cs:
    As above.
2022-01-16 02:50:17 +11:00
Julien Fischer
d8c0de2f38 More samples READMEs.
samples/csharp_interface/README.md:
    Add a README file for this subdirectory.

samples/java_interface/README:
    Rename this file to README.md; convert its contents
    to Markdown.
2022-01-15 23:54:35 +11:00
Julien Fischer
e40a502004 Fix casing of a heading.
samples/c_interface/README.md:
    Not sure why I made the heading all uppercase.
2022-01-15 23:35:49 +11:00
Julien Fischer
aa2380ff3f Convert another README to Markdown.
samples/c_interface/README:
    Rename to README.md and convert the contents to Markdown.
2022-01-15 23:32:42 +11:00
Julien Fischer
1702444cb1 Style and formatting fixes for Java interface samples.
samples/java_interface/java_calls_mercury/mercury_main.m:
samples/java_interface/mercury_calls_java/java_main_int.m:
samples/java_interface/standalone_java/JavaMain.java:
samples/java_interface/standalone_java/Makefile:
samples/java_interface/standalone_java/mercury_lib.m:
    As above.
2022-01-15 17:04:46 +11:00
Julien Fischer
6f5993dd1b Update samples/README.md.
samples/README.md:
     Include the recently C# interface subdirectory.
2022-01-15 16:23:42 +11:00
Julien Fischer
67112aef2b Add short example of C# interface.
samples/csharp_interface/short_example.m:
    A C# version of the C interface short example.
2022-01-15 03:38:14 +11:00
Julien Fischer
2c8675135a Add a standalone C# example.
samples/csharp_interface/standalone_csharp/CSharpMain.cs:
samples/csharp_interface/standalone_csharp/Makefile:
samples/csharp_interface/standalone_csharp/mercury_lib.m:
samples/csharp_interface/standalone_csharp/README.md:
     As above.
2022-01-15 03:28:09 +11:00
Julien Fischer
f417f4b21a Reword an entry in the samples README.
samples/README.md:
    As above.
2022-01-14 14:31:43 +11:00
Zoltan Somogyi
818d69a861 Minor improvements to .md files.
Convert extras/README to .md.
2022-01-07 14:54:00 +11:00
Julien Fischer
b4f3b65293 Update appengine example README file.
samples/appengine/README:
    The sample is no longer deployed on Ian's test instance
    (and probably hasn't been for many years).
2022-01-03 00:17:37 +11:00
Julien Fischer
8eef5d4088 Further work on samples directory README.
samples/README.md:
    Make the top-level heading a level 1 heading.

    Add eliza.m and beer.m to the list of sample programs.

    Fix spelling.
2022-01-03 00:13:08 +11:00
Julien Fischer
6495a31648 Fix a typo.
samples/README.md:
    As above.

samples/calculator.m:
    s/parser.m/mercury_term_parser.m/ in a comment.
2022-01-02 20:55:29 +11:00
Julien Fischer
4cebf83b6d Rename samples/README -> samples/README.md
samples/README:
    As above.
2022-01-02 17:02:14 +11:00
Julien Fischer
c3ef75d4d3 Convert samples/README to Markdown.
Convert the samples README file to Markdown.  The aim is to improve the way
this file appears when viewed in GitHub.

Fix a number of small errors.

samples/README:
    As above.
2022-01-02 17:00:59 +11:00
Julien Fischer
028637c95f Update a sample.
samples/calculator2.m:
   Conform to the parser -> mercury_term_parser renaming.
2021-12-31 12:39:12 +11:00
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