[m-rev.] for review: improve stack usage of list.series/3 and `..`

Ralph Becket rafe at cs.mu.OZ.AU
Mon Apr 4 14:13:20 AEST 2005


Julien Fischer, Monday,  4 April 2005:
> 
> Index: library/list.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/list.m,v
> retrieving revision 1.136
> diff -u -r1.136 list.m
> --- library/list.m	1 Apr 2005 14:29:19 -0000	1.136
> +++ library/list.m	4 Apr 2005 01:04:37 -0000
> @@ -1990,17 +1990,36 @@
> 
>  %-----------------------------------------------------------------------------%
> 
> -list__series(I, OK, Succ) =
> +list__series(I, OK, Succ) = Series :-
> +	list__series_2(I, OK, Succ, [], Series0),
> +	list__reverse(Series0, Series).
> +
> +:- pred list__series_2(T, pred(T), func(T) = T, list(T), list(T)).
> +:- mode list__series_2(in, pred(in) is semidet, func(in) = out is det,
> +	in, out) is det.
> +
> +list__series_2(I, OK, Succ, !Series) :-
>  	( OK(I) ->
> -		[I | list__series(Succ(I), OK, Succ)]
> +		!:Series = [ I | !.Series ],
> +		list__series_2(Succ(I), OK, Succ, !Series)

In this case, I don't think state variables make this more legible.

>  	;
> -	  	[]
> -	).
> +		true
> +	).
> 
>  %-----------------------------------------------------------------------------%
> 
> -Lo `..` Hi =
> -	list__series(Lo, ( pred(I::in) is semidet :- I =< Hi ), plus(1)).
> +Lo `..` Hi = List :- successive_integers(Lo, Hi, [], List).
> +
> +:- pred successive_integers(int::in, int::in, list(int)::in, list(int)::out)
> +	is det.
> +
> +successive_integers(Lo, Hi, !Ints) :-
> +	( Lo =< Hi ->
> +		!:Ints = [ Hi | !.Ints ],
> +		successive_integers(Lo, Hi - 1, !Ints)
> +	;
> +		true
> +	).

Same here.

Otherwise, that's fine.

-- Ralph
--------------------------------------------------------------------------
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