Topic: lambda limitations


Author: Gene Bushuyev <publicfilter@gbresearch.com>
Date: Wed, 8 Jun 2011 13:14:32 CST
Raw View
Using lambda functions in AXE recursive descent parser generator
library, I immediately found two current lambda limitations, which
diminish their usefullnes, and for which I can't find justification.
It would be really useful to have 1) template lambdas, because parser
rules are generally iterator agnostic and templatized on iterator
type; and 2) recursive lambdas, because parser rules are often
recursive.

For example,

1) parser to match any value requires template lambda:

auto r_any = template<class Iterator>[](Iterator i1, Iterator i2)
{
  return axe::make_result(i1 != i2, i1 + 1, i2);
}

2) parser to match nested c-style comment requires recursion:

auto c_comment = template<class Iterator>[](Iterator i1, Iterator i2)
{
  // operators are overloaded for parser rules
  return ("/*" & *(*(r_any - "/*" - "*/") | c_comment) & "*/")(i1,
i2);
};

<side-note>
It would have been even better if recursion was allowed for auto
declaration in general:
auto c_comment = "/*" & *(*(r_any - "/*" - "*/") | c_comment) & "*/";
</side-note>

It can be done with hand-written functors, why not lambdas? Were those
features considered including in the c++0x? If they were rejected,
what was the reason?


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Thu, 9 Jun 2011 13:09:57 CST
Raw View
On 08/06/2011 20:14, Gene Bushuyev wrote:
>
> Using lambda functions in AXE recursive descent parser generator
> library, I immediately found two current lambda limitations, which
> diminish their usefullnes, and for which I can't find justification.
> It would be really useful to have 1) template lambdas, because parser
> rules are generally iterator agnostic and templatized on iterator
> type; and 2) recursive lambdas, because parser rules are often
> recursive.
>
When we remember :) we are conservative with new features. Once you have
put something in it is hard to take it out later. If you would find
those things useful encourage an implementer to provide them as an
extension. If they work without problems then it will be relatively easy
to add them into the next Standard.


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Martin B."<0xCDCDCDCD@gmx.at>
Date: Fri, 10 Jun 2011 17:11:27 CST
Raw View
On 08.06.2011 21:14, Gene Bushuyev wrote:
>
>  Using lambda functions in AXE recursive descent parser generator
>  library, I immediately found two current lambda limitations, which
>  diminish their usefullnes, and for which I can't find justification.
>  It would be really useful to have 1) template lambdas, because parser
>  rules are generally iterator agnostic and templatized on iterator
>  type; and 2) recursive lambdas, because parser rules are often
>  recursive.
>

Herb Sutter commented on polymorphic lamdas in the lates C9 interview:

   http://herbsutter.com/2011/06/07/c9-ama/
   ->

http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answers
   ->
   "Polymorphic lambdas - why did they fail and what work is being done
to bring something like them back?"

http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answers#time=0h20m40s

cheers,
Martin

--
Stop Software Patents
http://petition.stopsoftwarepatents.eu/841006602158/
http://www.ffii.org/


[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]