@@ -203,25 +203,23 @@ drop-nth N Xs Dropped :-
203203% of Ls of length N, and Back is the remaining suffix of
204204% Ls. It is a fatal error if N is a negative number.
205205pred split i:int, i:list A, o:list A, o:list A.
206- split N Ls Front Back :- print "split > " N Ls Front Back, fail.
206+ % split N Ls Front Back :- print "split > " N Ls Front Back, fail.
207207split N _ _ _ :- N < 0, std.fatal-error "split with negative number".
208- % split 0 Xs [] Xs.
209208split 0 Xs _ Xs.
210209split N [X|Xs] [X|Front] Back :- split {calc (N - 1)} Xs Front Back.
211210
212211% 1.18
213212pred slice i:int, i:int, i:list A, o:list A.
214- slice I J Xs Slice :- print "slice > " I J Xs Slice, fail.
213+ % slice I J Xs Slice :- print "slice > " I J Xs Slice, fail.
215214slice I J _ _ :- J < I, std.fatal-error "slice with second index < first".
216215slice I J Xs Slice :- split I Xs _ Xs'
217216 & M is (J - I)
218217 & split M Xs' Slice _
219218 .
220219
221220% 1.19
222- % pred rotate i:list A, i:int, o:list A.
223- % rotate Ls N Ls' :- split N Ls Front Back, std.append Front Back Ls' .
224-
221+ pred rotate i:list A, i:int, o:list A.
222+ rotate Ls N Ls' :- split N Ls Front Back, std.append Back Front Ls' .
225223}
226224
227225
@@ -270,6 +268,6 @@ main :- test (list.last [1, 2, 3, 4] (some 4))
270268 & test (list.drop-nth 3 [1,2,3,4,5,6,7,8] [1,2,4,5,7,8])
271269 & test (list.split 3 [1,2,3,4,5,6,7,8,9,10] [1,2,3] [4,5,6,7,8,9,10])
272270 & test (list.slice 4 8 [1,2,3,4,5,6,7,8,9,10] [5,6,7,8,9])
273- % & test (list.rotate ["a","b","c","d","e","f","g","h" ] 3 ["d","e","f","g","h","a","b","c" ])
271+ & test (list.rotate [1,2,3,4,5,6,7,8 ] 3 [4,5,6,7,8,1,2,3 ])
274272 & print "ALL TESTS PASSED"
275273 .
0 commit comments