Files
mercury/tests/hard_coded/field_syntax.m
Zoltan Somogyi 33eb3028f5 Clean up the tests in half the test directories.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
    Make these tests use four-space indentation, and ensure that
    each module is imported on its own line. (I intend to use the latter
    to figure out which subdirectories' tests can be executed in parallel.)

    These changes usually move code to different lines. For the debugger tests,
    specify the new line numbers in .inp files and expect them in .exp files.
2015-02-14 20:14:03 +11:00

69 lines
2.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% field_syntax.m
% Ralph Becket <rafe@cs.mu.oz.au>
% Tue Dec 17 14:13:23 EST 2002
%---------------------------------------------------------------------------%
:- module field_syntax.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module array.
:- import_module int.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
:- func array(T) ^ elem_from_end(int) = T.
:- mode array_ui ^ elem_from_end(in) = out is det.
A ^ elem_from_end(I) = A ^ elem(max(A) - I).
%---------------------------------------------------------------------------%
:- func (array(T) ^ elem_from_end(int) := T) = array(T).
:- mode (array_di ^ elem_from_end(in) := in) = array_uo is det.
% This formatting gives each part of the term a different context.
% This is a regression test for a bug in which the code that recognized
% field accesses insisted on the same context for parts of the term.
(A
^
elem_from_end(I)
:=
X)
=
(A
^
elem(max(A) - I)
:=
X).
%---------------------------------------------------------------------------%
main(!IO) :-
A = array([1, 2, 3]),
io.format("A = ", [], !IO),
io.print(A, !IO),
io.nl(!IO),
io.format("A ^ elem(0) = %d\n",
[i(A ^ elem(0))], !IO),
io.format("A ^ elem_from_end(0) = %d\n",
[i(A ^ elem_from_end(0))], !IO),
io.format("(A ^ elem_from_end(2) := 4) = ", [], !IO),
io.print(A ^ elem_from_end(2) := 4, !IO),
io.nl(!IO).
%---------------------------------------------------------------------------%