mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 21:03:53 +00:00
Estimated hours taken: 5 [This change was by Ralph Becket. I'm just the person who reviewed it and committed it. -fjh.] Add functions for the single output det predicates in a number of modules in the standard library. Basically, for each :- pred f(in, ..., in, out) is det. I have added the declaration :- func f(in, ..., in) = out. and definition f(X1, ..., Xn) = Y :- f(X1, ..., Xn, Y). library/char.m: library/dir.m: library/map.m: library/string.m: library/list.m: library/set.m: Make the changes described above. library/array.m: As above, except array input modes are all array_ui or array_di as appropriate and array output modes are array_uo. library/int.m: Added forward versions of +/2, */2 and -/2 as plus/2, times/2 and minus/2 respectively, to make it easier to pass these as arguments to higher-order predicates. Also added func constants for max_int, min_int and bits_per_int. library/integer.m: Replaced local functions for list head, tail and length with calls to equivalent functions now defined in list.m. library/io.m: Added func for error_message/2. library/list.m: Add functions det_head/1 and det_tail/1 which abort on null lists. library/set.m: Add functions map/2, filter_map/2 and fold/3. library/std_util.m: Added utility function to construct a pair object from its arguments and general purpose higher order functions for partial functions and for function composition, exponentiation and exchanging the arguments of a binary function.
111 lines
3.0 KiB
Mathematica
111 lines
3.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1994-1995, 1997, 1999 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: dir.m.
|
|
% Main author: fjh.
|
|
|
|
% Filename and directory handling.
|
|
% Stability: high.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module dir.
|
|
:- interface.
|
|
|
|
% predicates to isolate system dependencies
|
|
|
|
:- pred dir__directory_separator(character).
|
|
:- mode dir__directory_separator(out) is det.
|
|
:- mode dir__directory_separator(in) is semidet.
|
|
% Returns '/'.
|
|
|
|
:- pred dir__this_directory(string).
|
|
:- mode dir__this_directory(out) is det.
|
|
:- mode dir__this_directory(in) is semidet. % Implied
|
|
% Returns ".".
|
|
|
|
% predicates for splitting filenames into a directory part and
|
|
% a filename part.
|
|
|
|
:- pred dir__split_name(string::in, string::out, string::out) is det.
|
|
:- pred dir__basename(string::in, string::out) is det.
|
|
:- pred dir__dirname(string::in, string::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
:- import_module int, require, string.
|
|
|
|
dir__directory_separator('/').
|
|
|
|
dir__this_directory(".").
|
|
|
|
dir__split_name(FileName, DirName, BaseName) :-
|
|
string__length(FileName, Length),
|
|
dir__split_name_2(FileName, Length, DirName, BaseName).
|
|
|
|
:- pred dir__split_name_2(string::in, int::in, string::out, string::out) is det.
|
|
|
|
dir__split_name_2(FileName, N, DirName, BaseName) :-
|
|
N1 is N - 1,
|
|
(
|
|
N1 < 0
|
|
->
|
|
dir__this_directory(DirName),
|
|
BaseName = FileName
|
|
;
|
|
string__index_det(FileName, N1, Separator),
|
|
dir__directory_separator(Separator)
|
|
->
|
|
string__split(FileName, N1, DirName, Rest),
|
|
( string__first_char(Rest, _Sep, BaseName0) ->
|
|
BaseName = BaseName0
|
|
;
|
|
error("dir__split_name_2")
|
|
)
|
|
;
|
|
dir__split_name_2(FileName, N1, DirName, BaseName)
|
|
).
|
|
|
|
dir__basename(FileName, BaseName) :-
|
|
dir__split_name(FileName, _, BaseName).
|
|
|
|
dir__dirname(FileName, DirName) :-
|
|
dir__split_name(FileName, DirName, _).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
% Ralph Becket <rwab1@cl.cam.ac.uk> 27/04/99
|
|
% Functional forms added.
|
|
|
|
:- interface.
|
|
|
|
:- func dir__directory_separator = character.
|
|
|
|
:- func dir__this_directory = string.
|
|
|
|
:- func dir__basename(string) = string.
|
|
|
|
:- func dir__dirname(string) = string.
|
|
|
|
% ---------------------------------------------------------------------------- %
|
|
% ---------------------------------------------------------------------------- %
|
|
|
|
:- implementation.
|
|
|
|
dir__directory_separator = C :-
|
|
dir__directory_separator(C).
|
|
|
|
dir__this_directory = S :-
|
|
dir__this_directory(S).
|
|
|
|
dir__basename(S1) = S2 :-
|
|
dir__basename(S1, S2).
|
|
|
|
dir__dirname(S1) = S2 :-
|
|
dir__dirname(S1, S2).
|
|
|