[m-rev.] For review: State Variables
Simon Taylor
stayl at cs.mu.OZ.AU
Thu Jun 27 04:45:08 AEST 2002
On 25-Jun-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> diff -u make_hlds.m make_hlds.m
> --- make_hlds.m 7 Jun 2002 07:39:12 -0000
> +++ make_hlds.m 25 Jun 2002 06:45:05 -0000
> @@ -16,9 +16,6 @@
> % super-homogenous form, and introduce implicit quantification.
> %
> % XXX we should record each error using module_info_incr_errors.
> -%
> -% XXX For state variables, we should allow quantifiers around if-then-else
> -% expressions.
You still haven't handled quantification for if-then-else goals.
It's fine to do that as a separate change immediately after you commit.
> + % We implement a special purpose comparison for state variable
> + % names that compares the numbers appended at the right hand
> + % ends of the name strings.
> + %
> + % NOTE state variable names are either "..._X" or "..._X_N"
> + % where X is the name of the program variable used for the
> + % state variable and N is a decimal number with no leading
> + % zeroes.
> + %
> +:- pred compare_svar_names(comparison_result, string, string).
> +:- mode compare_svar_names(out, in, in) is det.
> +
> +compare_svar_names(R, A, B) :-
> + csvns_1(R, 1, A, length(A), B, length(B)).
> + % First find the start of the numbers at the right hand end, if
> + % present.
> + %
> +:- pred csvns_1(comparison_result, int, string, int, string, int).
> +:- mode csvns_1(out, in, in, in, in, in) is det.
Please don't abbreviate like that.
> +csvns_1(R, I, A, MaxA, B, MaxB) :-
> + ( if I < MaxA, I < MaxB then
> + X = A `unsafe_index` (MaxA - I),
> + Y = B `unsafe_index` (MaxB - I),
> + ( if is_digit(X), is_digit(Y) then
> + csvns_1(R, I + 1, A, MaxA, B, MaxB)
> + else if X = ('_'), is_digit(Y) then
> + R = (<)
> + else if is_digit(X), Y = ('_') then
> + R = (>)
> + else if X = ('_'), Y = ('_') then
> + csvns_2(R, I - 1, A, MaxA, B, MaxB)
> + else if X = Y then
> + R = (=)
> + else
> + error("make_hlds__compare_svar_names: \
> +names are not in expected format")
> + )
> + else
> + error("make_hlds__compare_svar_names: \
> +names are not in expected format")
> + ).
> +
> +
> + % Decide the greater of the two numbers at the right hand end
> + % (both numbers will have the same number of digits.)
> + %
> +:- pred csvns_2(comparison_result, int, string, int, string, int).
> +:- mode csvns_2(out, in, in, in, in, in) is det.
> +
> +csvns_2(R, I, A, MaxA, B, MaxB) :-
> + ( if 0 < I then
> + X = A `unsafe_index` (MaxA - I) `with_type` char,
> + Y = B `unsafe_index` (MaxB - I) `with_type` char,
> + compare(RXY, X, Y),
> + ( RXY = (<), R = (<)
> + ; RXY = (=), csvns_2(R, I - 1, A, MaxA, B, MaxB)
> + ; RXY = (>), R = (>)
> + )
> + else
> + R = (=)
> + ).
This looks over-complicated to me. Wouldn't it be simpler to
write a predicate to parse the trailing integer of a string,
and then just compare the results.
Simon.
--------------------------------------------------------------------------
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