Files
mercury/samples/solutions/n_solutions.m
Sebastian Godelet 59ce15323f Fix samples/rot13_concise + libxml compilation error
boehm_gc/.gitignore:
    Ignore .obj files

extras/xml/xml.dtd.m:
extras/xml/xml.parse.m:
    Change the name of functor ('1') in the multiplicity/0 type
    to one. The former name does not (yet) work with the C# grade.

samples/.gitignore:
    Ignore library output and sample executables.

samples/c_interface/standalone_c/.gitignore:
    Ignore mercury_lib_int output files.

samples/c_interface/standalone_c/Makefile:
    chmod 0644.

samples/c_interface/.gitignore:
    Ignore object files and executables.

samples/java_interface/.gitignore:
    Ignore Java class files and executables.

samples/lazy_list/.gitignore:
samples/muz/.gitignore:
samples/rot13/.gitignore:
    Ignore executables.

samples/rot13/rot13_concise.m:
    Update call to index_det to use string.det_index.
    Added comments to clarify type inference.

samples/solutions/.gitignore:
    Ignore executables.

samples/solutions/all_solutions.m:
samples/solutions/n_solutions.m:
samples/solutions/one_solution.m:
samples/solutions/some_solutions.m:
    chmod 0644.

samples/solver_types/.gitignore:
    Ignore executables.

samples/solver_types/sudoku.m:
    Output the solution in a 3x3 grid.
2014-03-11 11:30:00 +11:00

43 lines
1.2 KiB
Mathematica

% An example program to illustrate the use of the `do_while'
% predicate in Mercury. This program calls a nondeterministic
% predicate hello/1, and prints the first N solutions it finds
% (in this case for N = 2).
%
% Note that in the standard "commutative" semantics, the order of
% solutions is unspecified. If you want to force the order of
% evaluation, then you would need to use the "strict sequential semantics"
% (enabled by the `--strict-sequential' option to the Mercury compiler).
% This source file is hereby placed in the public domain. -fjh (the author).
:- module n_solutions.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module bool.
:- import_module int.
:- import_module solutions.
main(!IO) :-
N = 2,
do_while(hello, get_next, {!.IO, N}, {!:IO, _}),
print("Done\n", !IO).
:- pred hello(string::out) is multi.
hello("Hello, world\n").
hello("Good day, world\n").
hello("Greetings, world\n").
:- pred get_next(string::in, bool::out, {io, int}::di, {io, int}::uo)
is det.
get_next(String, More, {IO0, Max0}, {IO, Max}) :-
print(String, IO0, IO),
More = (Max0 > 1 -> yes ; no),
Max = Max0 - 1.