Files
mercury/tests/general/string_foldl_substring.m
Zoltan Somogyi ecb5e4a9e6 Update the style of many test cases.
tests/declarative_debugger/*.m:
tests/exceptions/*.m:
tests/general/*.m:
tests/grade_subdirs/*.m:
tests/purity/*.m:
tests/submodules/*.m:
tests/typeclasses/*.m:
    Update programming style.

tests/declarative_debugger/*.inp:
    Update line numbers in breakpoint commands.
tests/declarative_debugger/*.exp:
    Update expected line numbers.

tests/exceptions/Mercury.options:
tests/general/Mercury.options:
    Disable some warnings that are irrelevant to the test.
2021-07-25 23:26:17 +10:00

57 lines
1.9 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% string_foldl_substring.m
% Ralph Becket <rafe@cs.mu.oz.au>
% Mon Oct 28 16:32:19 EST 2002
%---------------------------------------------------------------------------%
:- module string_foldl_substring.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module char.
:- import_module int.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
io.write_strings([
"rev(\"Hello, World!\", 0, 5) = \"",
rev("Hello, World!", 0, 5),
"\"\nrev(\"Hello, World!\", 0, 50) = \"",
rev("Hello, World!", 0, 50),
"\"\nrev(\"Hello, World!\", 0, -5) = \"",
rev("Hello, World!", 0, -5),
"\"\nrev(\"Hello, World!\", -5, 12) = \"",
rev("Hello, World!", -5, 12),
"\"\nrev(\"Hello, World!\", -5, 50) = \"",
rev("Hello, World!", -5, 50),
"\"\nrev(\"Hello, World!\", 7, 0) = \"",
rev("Hello, World!", 7, 0),
"\"\nrev(\"Hello, World!\", 7, 12) = \"",
rev("Hello, World!", 7, 12),
"\"\nrev(\"Hello, World!\", 50, 10) = \"",
rev("Hello, World!", 50, 10),
"\"\n"
], !IO).
:- func rev(string, int, int) = string.
rev(S, I, N) =
from_char_list(foldl_between(func(X, Xs) = [X | Xs], S, I, N, [])).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%