[m-rev.] trivial diff: use new fli in impurity example

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Feb 13 23:34:05 AEDT 2007


Estimated hours taken: 0.1
Branches: main

doc/reference_manual.texi:
 	Rewrite the reference manual's impurity example to use the
 	new foreign language interface.

Julien.

Index: reference_manual.texi
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.382
diff -u -r1.382 reference_manual.texi
--- reference_manual.texi	11 Feb 2007 03:28:01 -0000	1.382
+++ reference_manual.texi	13 Feb 2007 12:13:18 -0000
@@ -9142,35 +9142,48 @@
  and so is not useful as is.  It is meant only as an example.

  @example
-:- pragma c_header_code("#include <limits.h>").
-:- pragma c_header_code("MR_Integer max;").
+:- pragma foreign_decl("C", "#include <limits.h>").
+:- pragma foreign_decl("C", "extern MR_Integer max;").
+
+:- pragma foreign_code("C", "MR_Integer max;").

  :- impure pred init_max is det.
-:- pragma c_code(init_max,
-        [will_not_call_mercury],
-        "max = INT_MIN;").
+:- pragma foreign_proc("C",
+    init_max,
+    [will_not_call_mercury],
+"
+    max = INT_MIN;
+").

  :- impure pred set_max(int::in) is det.
-:- pragma c_code(set_max(X::in),
-        [will_not_call_mercury],
-        "if (X > max) max = X;").
+:- pragma foreign_proc("C",
+   set_max(X::in),
+   [will_not_call_mercury],
+"
+    if (X > max) max = X;
+").

  :- semipure func get_max = (int::out) is det.
-:- pragma c_code(get_max = (X::out),
-        [will_not_call_mercury],
-        "X = max;").
+:- pragma foreign_proc("C",
+    get_max = (X::out),
+    [promise_semipure, will_not_call_mercury],
+"
+    X = max;
+").

  :- pragma promise_pure(max_solution/2).
  :- pred max_solution(pred(int), int).
  :- mode max_solution(pred(out) is multi, out) is det.

  max_solution(Generator, Max) :-
-        impure init_max,
-        (   Generator(X),
-            impure set_max(X),
-            fail
-        ;   semipure Max = get_max
-        ).
+    impure init_max,
+    (
+        Generator(X),
+        impure set_max(X),
+        fail
+    ;
+        semipure Max = get_max
+    ).
  @end example

  @node Higher-order impurity

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list