SYMBOLISM library |
||
Symbolism libraryComplex data structures, algebraic types, pattern matching, automatic memory management - it all makes symbolic languages (Lisp, Prolog, etc) something very attractive to programmers, especially to those thinking abstractly, mathematically. Unfortunately, these languages are not in widespread use. But there do exist ways to embed mechanisms borrowed from the logic languages into C++ program. One can do this by defining rather simple set of classes with some overloaded operators and smart destructors with some resource management. The SYMBOLISM library is an attempt to define good API suitable for this goal.
Here is a short sample of code utilising the library, without explanation, only illustrating the idea:
double eval( term Fun, term Arglist )
{
variable Head, Tail, Fun2;
if ( Fun == sum ) {
if ( Arglist == list( Head, Tail ))
return Head.getDouble() + eval( Fun, Tail );
else
return 0;
}
if ( Fun == neg( Fun2 ) )
return -eval( Fun2, Arglist );
if ( Fun == mul ) {
if ( Arglist == list( Head, Tail ))
return Head.getDouble() * eval( Fun, Tail );
else
return 1;
}
return 0;
}
If You are interested read the introduction .... |
||