[m-rev.] diff: list__split_last
Zoltan Somogyi
zs at cs.mu.OZ.AU
Sat Dec 29 15:39:34 AEDT 2001
library/list.m:
Add three new predicates. list__split_last is like list__last but also
returns the rest of the list. list__last_det and list__split_last_det
are deterministic versions of list__last and list__split_last
respectively, which abort instead of failing if the input list is
non-empty.
NEWS:
Mention the new predicates, and consolidate all the announcements
about list.m in a single group.
Zoltan.
cvs diff: Diffing .
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.233
diff -u -b -r1.233 NEWS
--- NEWS 2001/12/19 06:44:43 1.233
+++ NEWS 2001/12/29 04:38:07
@@ -64,12 +64,13 @@
extensions which are unlikely to be implemented.
Changes to the Mercury standard library:
-* We've added two new list functions to list.m, namely
- list__filter_map_corresponding/3 and list__filter_map_corresponding3/4.
-* We've added a func version of error/1, called func_error/1, to require.m.
-* We've added two functions to list.m for mapping functions over
- corresponding members of lists (list__map_corresponding/3 and
- list__map_corresponding3/4).
+
+* We've added four functions to list.m for mapping functions over
+ corresponding members of lists: list__map_corresponding/3,
+ list__map_corresponding3/4, list__filter_map_corresponding/3
+ and list__filter_map_corresponding3/4.
+* We've added some other new functions to list.m, namely
+ list__last_det/2, list__split_last/3 and list__split_last_det/3.
* We've added cc_multi modes to list__foldl/4 and list__foldr/4.
* As mentioned above, the constructor for lists has changed from './2'
to `[|]/2'. This change affects the behaviour of the term manipulation
@@ -80,6 +81,8 @@
Also beware that std_util__functor and std_util__deconstruct now
return `[|]' rather than `.' for lists, and calls to std_util__construct
which construct lists may need to be updated.
+
+* We've added a func version of error/1, called func_error/1, to require.m.
* ops.m now defines a typeclass which can be used to define operator
precedence tables for use by parser.m and term_io.m. See
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing library
Index: library/list.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/list.m,v
retrieving revision 1.102
diff -u -b -r1.102 list.m
--- library/list.m 2001/12/17 00:28:05 1.102
+++ library/list.m 2001/12/29 04:32:49
@@ -401,6 +401,22 @@
:- pred list__last(list(T), T).
:- mode list__last(in, out) is semidet.
+ % A deterministic version of list__last, which aborts instead of
+ % failing if the input list is empty.
+:- pred list__last_det(list(T), T).
+:- mode list__last_det(in, out) is det.
+
+ % list__split_last(List, AllButLast, Last) is true
+ % if Last is the last element of List and AllButLast is the list
+ % of elements before it.
+:- pred list__split_last(list(T), list(T), T).
+:- mode list__split_last(in, out, out) is semidet.
+
+ % A deterministic version of list__split_last, which aborts instead of
+ % failing if the input list is empty.
+:- pred list__split_last_det(list(T), list(T), T).
+:- mode list__split_last_det(in, out, out) is det.
+
%-----------------------------------------------------------------------------%
%
% The following group of predicates use higher-order terms to simplify
@@ -1186,6 +1202,32 @@
;
T = [_|_],
list__last(T, Last)
+ ).
+
+list__last_det(List, Last) :-
+ ( list__last(List, LastPrime) ->
+ Last = LastPrime
+ ;
+ error("list__last_det: empty list")
+ ).
+
+list__split_last([H | T], AllButLast, Last) :-
+ (
+ T = [],
+ AllButLast = [],
+ Last = H
+ ;
+ T = [_ | _],
+ list__split_last(T, AllButLast1, Last),
+ AllButLast = [H | AllButLast1]
+ ).
+
+list__split_last_det(List, AllButLast, Last) :-
+ ( list__split_last(List, AllButLastPrime, LastPrime) ->
+ AllButLast = AllButLastPrime,
+ Last = LastPrime
+ ;
+ error("list__split_last_det: empty list")
).
%-----------------------------------------------------------------------------%
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list