<<< Scalar interface | Lambda Home | Lambda composite >>> |
Common Text Transformation Library http://cttl.sourceforge.net/
Lambda primitives that represent integer constants are instantiated by helper macro
const_scalar_type( C )
where C is either a const int expression, or a type, convertible to const int, such as enumerated type:
enum { zero, one, two }; const_scalar_type( zero ) ZERO; const_scalar_type( one ) ONE; const_scalar_type( two ) TWO; const_scalar_type( 3 ) THREE; const_scalar_type( -5 ) MINUS_FIVE;
Each of the above declaration statements creates a constant scalar. The constant scalar is a lambda primitive that represents immutable integer value in various subsets of lambda library. As a true constant, it must be initialized by a literal value or constant expression. The value of the constant scalar cannot change.
Besides standalone declarations by const_scalar_type(C), constant integer scalars can also be instantiated in-line by helper macro const_scalar(C), where C is either a const int expression, or a type, convertible to const int, such as the enumerated constant:
#include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { int var = 456; ( CTTL_LAMBDA_ASSERT( scalar( &var ) == const_scalar( 456 ) ) ).evaluate(); return 0; }
Constant scalars play important role in subscript-based access to lambda composite trees.
// const_scalar.cpp // Program demonstrates helper macro const_scalar(T), which // yields in-line C++ -like constants. // T is either an integer constant, or a type, convertible // to integer constant, such as enumerated constant. #define CTTL_TRACE_RULES // automatically turns lambda tracing on #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; int main(/*int argc, char* argv[]*/) { lambda< int >::stack Stack; // instantiate std::stack< int > ( Stack = const_scalar( 2 )^const_scalar( 3 ), CTTL_LAMBDA_ASSERT( +Stack == 2u ), CTTL_LAMBDA_ASSERT( *Stack == 3 ), Stack--, CTTL_LAMBDA_ASSERT( +Stack == 1u ), CTTL_LAMBDA_ASSERT( *Stack == 2 ) ).evaluate(); return 0; }
// const_scalar_type.cpp // Program demonstrates macro const_scalar_type(T), // which instantiates stand-alone C++ -like constants. // T is either int, or type, convertible to integer, // such as enumerated type. #define CTTL_TRACE_RULES // automatically turns lambda tracing on #include "cttl/cttl.h" #include "lambda/lambda.h" using namespace cttl; enum { zero, one, two }; const_scalar_type( zero ) ZERO; const_scalar_type( one ) ONE; const_scalar_type( two ) TWO; const_scalar_type( 3 ) THREE; const_scalar_type( -5 ) MINUS_FIVE; int main(/*int argc, char* argv[]*/) { lambda< int >::stack Stack; // instantiate std::stack< int > ( //Stack = const_scalar( 2 )^const_scalar( 3 ), Stack = TWO^THREE, CTTL_LAMBDA_ASSERT( +Stack == scalar( size_t( TWO.const_value_ ) ) ), CTTL_LAMBDA_ASSERT( *Stack == THREE ), Stack--, CTTL_LAMBDA_ASSERT( +Stack == scalar( size_t( ONE.const_value_ ) ) ), CTTL_LAMBDA_ASSERT( *Stack == TWO ) ).evaluate(); return 0; }
Copyright © 1997-2009 Igor Kholodov mailto:cttl@users.sourceforge.net.
Permission to copy and distribute this document is granted provided this copyright notice appears in all copies. This document is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
<<< Scalar interface | Lambda Home | Lambda composite >>> |