mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
Estimated hours taken: 0.5 Branches: main Remove a bug workaround in the the thread module. Misc. minor changes to library modules. library/thread.m: Delete the workaround for the bug with foreign_import_module pragmas and sub-modules on the lowlevel backends. library/deconstruct.m: library/sparse_bitset.m: library/varset.m: Delete duplicate imports. library/io.m: library/thread.semaphore.m: s/which/that/ in a spot. library/prolog.m: Convert this module to 4-space indentation. library/dir.m: library/getopt.m: library/getopt_io.m: library/lexer.m: Fix some formatting so that it conforms to our current coding standard.
120 lines
3.6 KiB
Mathematica
120 lines
3.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1997-2003, 2005-2006 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU Library General
|
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: prolog.m.
|
|
% Main author: fjh.
|
|
% Stability: high.
|
|
%
|
|
% This file contains predicates that are intended to help people
|
|
% porting Prolog programs, or writing programs in the intersection
|
|
% of Mercury and Prolog.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module prolog.
|
|
:- interface.
|
|
|
|
:- import_module list.
|
|
:- import_module pair.
|
|
:- import_module univ.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Prolog arithmetic operators
|
|
%
|
|
|
|
:- pred T =:= T. % In Mercury, just use =
|
|
:- mode in =:= in is semidet.
|
|
|
|
:- pred T =\= T. % In Mercury, just use \=
|
|
:- mode in =\= in is semidet.
|
|
|
|
/*******
|
|
is/2 is currently defined in int.m, for historical reasons.
|
|
|
|
:- pred is(T, T) is det. % In Mercury, just use =
|
|
:- mode is(uo, di) is det.
|
|
:- mode is(out, in) is det.
|
|
******/
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Prolog term comparison operators
|
|
%
|
|
|
|
:- pred T == T. % In Mercury, just use =
|
|
:- mode in == in is semidet.
|
|
|
|
:- pred T \== T. % In Mercury, just use \=
|
|
:- mode in \== in is semidet.
|
|
|
|
% Prolog's so-called "univ" operator, `=..'.
|
|
% Note: this is not related to Mercury's "univ" type!
|
|
% In Mercury, use `deconstruct.deconstruct' instead.
|
|
|
|
:- pred T =.. univ_result.
|
|
:- mode in =.. out is det.
|
|
%
|
|
% Note that the Mercury =.. is a bit different to the Prolog
|
|
% one. We could make it slightly more similar by overloading '.'/2,
|
|
% but that would cause ambiguities that might prevent type
|
|
% inference in a lot of cases.
|
|
%
|
|
% :- type univ_result ---> '.'(string, list(univ)).
|
|
:- type univ_result == pair(string, list(univ)).
|
|
|
|
% arg/3. In Mercury, use argument/3 (defined in module std_util)
|
|
% instead:
|
|
% arg(ArgNum, Term, Data) :- argument(Term, ArgNum - 1, Data).
|
|
%
|
|
:- pred arg(int::in, T::in, univ::out) is semidet.
|
|
|
|
% det_arg/3: like arg/3, but calls error/1 rather than failing
|
|
% if the index is out of range.
|
|
%
|
|
:- pred det_arg(int::in, T::in, univ::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module deconstruct.
|
|
:- import_module int.
|
|
:- import_module require.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% we use module qualifiers here to avoid
|
|
% overriding the builtin Prolog versions
|
|
|
|
'=='(X, X).
|
|
'\\=='(X, Y) :- X \= Y.
|
|
|
|
'=:='(X, X).
|
|
'=\\='(X, Y) :- X \= Y.
|
|
|
|
'=..'(Term, Functor - Args) :-
|
|
deconstruct(Term, canonicalize, Functor, _Arity, Args).
|
|
|
|
% we use a module qualifier here to avoid
|
|
% overriding the builtin Prolog version
|
|
prolog.arg(ArgumentIndex, Type, Univ) :-
|
|
deconstruct.arg(Type, canonicalize, ArgumentIndex - 1, Arg),
|
|
type_to_univ(Arg, Univ).
|
|
|
|
det_arg(ArgumentIndex, Type, Argument) :-
|
|
( arg(ArgumentIndex, Type, Arg) ->
|
|
Argument = Arg
|
|
;
|
|
error("det_arg: arg failed")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|