
On 11/27/2010 6:36 AM, Paul Mensonides wrote: [...]
===== Lambdas/Binding =====
Chaos has a pretty heavyweight lambda engine. For example (contrived),
#include<chaos/preprocessor.h>
CHAOS_PP_EXPR(CHAOS_PP_ENUM( 5, CHAOS_PP_PRIMITIVE_CAT_(class T, CHAOS_PP_ARG(1)) CHAOS_PP_WHEN_(CHAOS_PP_ARG(1))( CHAOS_PP_CAT_(= T, CHAOS_PP_DEC_(CHAOS_PP_ARG(1))) ) ))
...results in:
class T0, class T1 = T0, class T2 = T1, class T3 = T2, class T4 = T3
However, the problem with lambdas (with the preprocessor) is that they are considerably more expensive. No matter how you do it, it requires some sort of interpretation--which is slower--and simply having a macro is usually clearer. I've actually been considering their removal from Chaos for several years.
#define _(s, n) \ class T ## n \ CHAOS_PP_WHEN(n)(= CHAOS_PP_CAT(T, CHAOS_PP_DEC(n))) \ /**/
CHAOS_PP_EXPR(CHAOS_PP_ENUM(5, _))
#undef _
I believe the now-impossible-to-find "Avalanche Preprocessor library" that that a user posted a link to some time back used a somewhat different syntax for lambdas. Recalling strictly from memory, it would look something like CHAOS_PP_EXPR( CHAOS_PP_ENUM( 5, CHAOS_PP_BIND( CHAOS_PP_PRIMITIVE_CAT_, ( class T ), 1 ) CHAOS_PP_BIND( CHAOS_PP_WHEN_, 1, CHAOS_PP_BIND( CHAOS_PP_CAT_, ( = T ), CHAOS_PP_BIND( CHAOS_PP_DEC_, 1 ) ) ) In other words, there was some very heavily-used CHAOS_PP_BIND-like macro that essentially initiated a lambda sequence, which accepted the macro to bind followed by the arguments to bind. Arguments appearing as numerals (1, 2, etc.) were placeholders, while arguments appearing in parantheses were literals. I don't remember much of the syntax, semantics, or mechanics past that. What I wrote above is probably not considered preferable to using the existing Chaos lambda syntax, but maybe some combination of these ideas could be massaged into a better syntax with faster compile times, given willing investigative souls. - Jeff