CVS difference for ai12s/ai12-0190-1.txt

Differences between 1.2 and version 1.3
Log of other versions for file ai12s/ai12-0190-1.txt

--- ai12s/ai12-0190-1.txt	2016/06/08 02:40:09	1.2
+++ ai12s/ai12-0190-1.txt	2016/10/06 01:22:47	1.3
@@ -1,21 +1,32 @@
-!standard 5.5.2(2/3)                                  16-06-02  AI12-0190-1/01
+!standard 5.5.2(2/3)                                  16-10-04  AI12-0190-1/02
 !class Amendment 16-06-02
 !status work item 16-06-02
 !status received 16-05-06
 !priority Low
 !difficulty Medium
-!subject Lambda functions
+!subject Anonymous functions
 !summary
 
-** TBD.
+Provide an ability to construct a local anonymous function at the point
+of a call on a subprogram that has an access-to-function parameter.
 
 !problem
-
-"others at AdaCore feel that lambdas are critically important".
 
-[Editor's note: I can find no problem statement anywhere, and I don't know
-of any problem, either. If this had been an Ada Comment posting, we'd have
-tossed it directly into the trash because of a lack of a problem statement...]
+We added anonymous access-to-subprogram parameters to allow
+locally-declared subprograms to be passed to other programs which might
+iterate over some data structure, applying the passed subprogram
+multiple times, perhaps as part of a search, or an update, or a
+transformation of some sort.  Being able to pass local subprograms to
+other subprograms is a fundamental part of "functional" programming, but
+also appears in other programming paradigms, including old fashioned
+numeric integration packages, etc.
+
+To enhance the utility of this feature, it is convenient if the
+subprogram being passed can be constructed at the point of call, rather
+than requiring a separate declaration.  AI12-0189 addresses the case
+where a procedure (as opposed to a function) is to be passed as the
+actual parameter.  We would like to provide something similar for
+passing a locally-constructed function as a parameter.
 
 !proposal
 
@@ -29,23 +40,50 @@
 
     primary ::= lambda_function
 
-    lambda_function ::= ( LAMBDA [ lambda_parameter_list ] expression )
+    lambda_function ::= ( [ lambda_parameter_list ] RETURN expression )
 
-    lambda_parameter_list ::= ( identifier { , identifier } )
+    lambda_parameter_list ::= ( identifier { , identifier } ) | formal_part
 
+We allow only a single expression as the body of the lambda function.  Given
+that we now have "if" expressions and "case" expressions, this is not a
+serious limitation.  (The possible addition of "declare expressions" would
+be a welcome enhancement.)
+
 !wording
 
 ** TBD.
 
 !discussion
 
-** TBD.
+We are using the reserved word RETURN rather than defining a new reserved word
+such as LAMBDA.  We put it after the (optional) parameter list, immediately
+next to the returned expression, as that is its normal place in the syntax. We
+considered using FUNCTION instead of RETURN, but that left us with potentially
+two parenthesized constructs in a row, which looks somewhat strange (e.g.
+"(function (X) (X**2))").  We could use both FUNCTION and RETURN, as in
+"(function (X) return (X**2))" though that might be considered a bit verbose
+(or maybe not?).
+
+We could call these "return expressions" (although that term would be confusing
+compared to very similar terms used in Return Statements), or we could call
+them "anonymous functions," given that we have dropped the reserved word
+LAMBDA from the syntax.
+
+We are only supporting defining anonymous functions using this proposed
+construct.  Anonymous procedures are nicely handled with the loop-body proposal
+(AI12-0189).  In any case, mixing statements inside expressions seems like a
+bad idea.
+
+We allow, but do not require, a full formal part as part of the lambda
+function definition. Requiring a full formal part seems unnecessary and
+verbose, since the parameter types are always provided by the profile of
+the formal access-to-function parameter.
 
 !example
 
     --  Replace control chars with '?'
     Ada.Strings.Fixed.Translate
-      (Str, (lambda (C) (if C < ' ' then '?' else C)));
+      (Str, ((C) return (if C < ' ' then '?' else C)));
 
     --  Procedure for plotting a function
     procedure Plot_Graph
@@ -55,7 +93,15 @@
     ...
 
     --  Plot a graph of X-squared from 1 to 20
-    Plot_Graph (Fun => (lambda (Z) Z**2), Start => 1.0, Stop => 20.0);
+    Plot_Graph (Fun => ((Z) return Z**2), Start => 1.0, Stop => 20.0);
+
+Using both "function" and "return" this would be:
+
+    --  Plot a graph of X-squared from 1 to 20
+    Plot_Graph (Fun => (function (Z) return Z**2),
+                Start => 1.0, Stop => 20.0);
+
+That doesn't look too bad, and is certainly very clear to the reader.
 
 !ASIS
 
@@ -918,3 +964,24 @@
 
 [Editor's note: This thread continues in AI12-0189-1, since it is turning back
 to loops.]
+
+****************************************************************
+
+From: Tucker Taft
+Sent: Tuesday, October 4, 2016  11:02 PM
+
+Here is an update. [This is version /02 of the AI - Editor.] I have shifted
+the syntax so it doesn't rely on a new reserved word "lambda" any more. Might
+want to change the name of the construct as well if we go this direction.
+I have provided !problem and !discussion sections.
+
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Wednesday, October 5, 2016  7:58 PM
+
+The alternative with both "function" and "return" looks the best to me. The
+others look like something is missing.
+
+****************************************************************

Questions? Ask the ACAA Technical Agent