[m-rev.] for review: document and test deconstruct_functor with infinity

Julien Fischer jfischer at opturion.com
Fri Jun 8 16:27:53 AEST 2018


For review by anyone.

The diff below documents the implementation's current behaviour.
Should the functor be returned as <<infinity>> or something like that?

(Not that for NaN, the functor will currently be returned as "nan";
I'll addresss NaNs separately.)

-------------

Document and test deconstruct_functor with infinity.

library/deconstruct.m:
     Document what deconstruct_functor/4 returns with infinite floating point
     values.  Also, the functor returned will only be a floating point base 10
     number for finite float values.

test/hard_coded/deconstruct_arg.{m,exp}:
     Extend this test to cover infinity and -infinity.

Julien.

diff --git a/library/deconstruct.m b/library/deconstruct.m
index 6cdeb18..d95a7cf 100644
--- a/library/deconstruct.m
+++ b/library/deconstruct.m
@@ -74,8 +74,9 @@
      %     handled as if it had standard equality.
      %   - for integers, the string is a base 10 number;
      %     positive integers have no sign.
-    %   - for floats, the string is a floating point, base 10 number;
+    %   - for finite floats, the string is a floating point, base 10 number;
      %     positive floating point numbers have no sign.
+    %   - for infinite floats, the string "infinity" or "-infinity";
      %   - for strings, the string, inside double quotation marks
      %   - for characters, the character inside single quotation marks
      %   - for predicates, the string <<predicate>>, and for functions,
diff --git a/tests/hard_coded/deconstruct_arg.exp b/tests/hard_coded/deconstruct_arg.exp
index 05813c3..9a5af4e 100644
--- a/tests/hard_coded/deconstruct_arg.exp
+++ b/tests/hard_coded/deconstruct_arg.exp
@@ -138,6 +138,34 @@ deconstruct deconstruct: functor 0.12345678901234566 arity 0
  deconstruct limited deconstruct 3 of 0.12345678901234566
  functor 0.12345678901234566 arity 0 []

+deconstruct functor: infinity/0
+deconstruct argument 0 of infinity doesn't exist
+deconstruct argument 1 of infinity doesn't exist
+deconstruct argument 2 of infinity doesn't exist
+deconstruct argument 'moo' doesn't exist
+deconstruct argument 'mooo!' doesn't exist
+deconstruct argument 'packed1' doesn't exist
+deconstruct argument 'packed2' doesn't exist
+deconstruct argument 'packed3' doesn't exist
+deconstruct deconstruct: functor infinity arity 0
+[]
+deconstruct limited deconstruct 3 of infinity
+functor infinity arity 0 []
+
+deconstruct functor: -infinity/0
+deconstruct argument 0 of -infinity doesn't exist
+deconstruct argument 1 of -infinity doesn't exist
+deconstruct argument 2 of -infinity doesn't exist
+deconstruct argument 'moo' doesn't exist
+deconstruct argument 'mooo!' doesn't exist
+deconstruct argument 'packed1' doesn't exist
+deconstruct argument 'packed2' doesn't exist
+deconstruct argument 'packed3' doesn't exist
+deconstruct deconstruct: functor -infinity arity 0
+[]
+deconstruct limited deconstruct 3 of -infinity
+functor -infinity arity 0 []
+
  deconstruct functor: 4/0
  deconstruct argument 0 of 4 doesn't exist
  deconstruct argument 1 of 4 doesn't exist
@@ -320,7 +348,7 @@ deconstruct deconstruct: functor newline arity 0
  deconstruct limited deconstruct 3 of '<<predicate>>'
  functor newline arity 0 []

-deconstruct functor: lambda_deconstruct_arg_m_149/1
+deconstruct functor: lambda_deconstruct_arg_m_155/1
  deconstruct argument 0 of '<<predicate>>' is [1, 2]
  deconstruct argument 1 of '<<predicate>>' doesn't exist
  deconstruct argument 2 of '<<predicate>>' doesn't exist
@@ -329,10 +357,10 @@ deconstruct argument 'mooo!' doesn't exist
  deconstruct argument 'packed1' doesn't exist
  deconstruct argument 'packed2' doesn't exist
  deconstruct argument 'packed3' doesn't exist
-deconstruct deconstruct: functor lambda_deconstruct_arg_m_149 arity 1
+deconstruct deconstruct: functor lambda_deconstruct_arg_m_155 arity 1
  [[1, 2]]
  deconstruct limited deconstruct 3 of '<<predicate>>'
-functor lambda_deconstruct_arg_m_149 arity 1 [[1, 2]]
+functor lambda_deconstruct_arg_m_155 arity 1 [[1, 2]]

  deconstruct functor: p/3
  deconstruct argument 0 of '<<predicate>>' is 1
diff --git a/tests/hard_coded/deconstruct_arg.m b/tests/hard_coded/deconstruct_arg.m
index d2be062..286e66d 100644
--- a/tests/hard_coded/deconstruct_arg.m
+++ b/tests/hard_coded/deconstruct_arg.m
@@ -18,6 +18,7 @@
  %---------------------------------------------------------------------------%

  :- import_module array.
+:- import_module float.
  :- import_module list.
  :- import_module string.
  :- import_module deconstruct.
@@ -121,6 +122,11 @@ main(!IO) :-
      % test a float which requires 17 digits of precision
      test_all(0.12345678901234566, !IO),

+    % test infinite floats
+    test_all(float.infinity, !IO),
+    NegInf : float = -float.infinity,
+    test_all(NegInf, !IO),
+
      % test integers
      test_all(4, !IO),



More information about the reviews mailing list