C++Lisp is a library of C++ classes that allows for integrating Lisp programming within C++ programs. It provides an easy way to use Lisp functions and expressions within C++ code for efficient programming.
To illustrate this, the software provides an example Lisp function called "isomorphic". The code for this function is shown below in Lisp syntax:
(defun isomorphic (tree1 tree2)
(cond ((atom tree1) (atom tree2))
((atom tree2) NIL)
(t (and (isomorphic (car tree1)
(car tree2))
(isomorphic (cdr tree1)
(cdr tree2))))))
Now, the same code is shown using InteLib's C++ syntax:
(L|DEFUN, ISOMORPHIC, (L|TREE1, TREE2),
(L|COND,
(L|(L|ATOM, TREE1), (L|ATOM, TREE2)),
(L|(L|ATOM, TREE2), NIL),
(L|T, (L|AND,
(L|ISOMORPHIC, (L|CAR, TREE1),
(L|CAR, TREE2)),
(L|ISOMORPHIC, (L|CDR, TREE1),
(L|CDR, TREE2))))))
It may surprise you to know that the above code is actually C++ code. To prove this, the following code is shown:
// File isomorph.cpp
#include "lisp/lisp.hpp"
#include "lisp/lsymbol.hpp"
#include "lfun_std.hpp"
LSymbol ISOMORPHIC("ISOMORPHIC");
static LFunctionalSymbol< LFunctionDefun > DEFUN("DEFUN");
static LFunctionalSymbol< LFunctionCond > COND("COND");
static LFunctionalSymbol< LFunctionAtom > ATOM("ATOM");
static LFunctionalSymbol< LFunctionAnd > AND("AND");
static LFunctionalSymbol< LFunctionCar > CAR("CAR");
static LFunctionalSymbol< LFunctionCdr > CDR("CDR");
LListConstructor L;
void LispInit_isomorphic() {
static LSymbol TREE1("TREE1");
static LSymbol TREE2("TREE2");
(L|DEFUN, ISOMORPHIC, (L|TREE1, TREE2),
(L|COND,
(L|(L|ATOM, TREE1), (L|ATOM, TREE2)),
(L|(L|ATOM, TREE2), NIL),
(L|T, (L|AND,
(L|ISOMORPHIC, (L|CAR, TREE1),
(L|CAR, TREE2)),
(L|ISOMORPHIC, (L|CDR, TREE1),
(L|CDR, TREE2)))))).Evaluate();
}
This code can be compiled with a C++ compiler and demonstrates that InteLib's C++ syntax is legitimate.
One noteworthy aspect of InteLib is that it doesn't rely on macros except for conditional compile directives. Instead, the software uses the comma operator which can be overloaded for user-defined data types. Overall, InteLib is a useful and innovative tool for C++ programmers who want to write
Version 0.6.21: N/A