Next: Hybrid Domains
Up: Predicates and Functions
Previous: Internal Functions and Predicates
If a predicate or function is not internally implemented in Alchemy, but you wish to use it,
then you can define this as a piece of C++ code. The file ALCHDIR/exdata/functions.cpp
serves as a template for building linked-in functions and predicates. Here are some basic
guidelines:
0in
- C++ functions implementing predicates must take only arguments of type string
and return type bool.
- C++ functions implementing functions must take only arguments of and return type string.
- All functions and predicates must be between extern "C" { and }
(see functions.cpp. Otherwise, the function names will be mangled by the C++ compiler
and a dynamic look-up is not possible.
- g++ 4.0.2 and the glibc library are necessary (other versions have not been tested).
In order to use linked-in functions in an MLN, the functions have to be declared and the
location of the C++ file has to be disclosed. The location of the file is arbitrary; however,
it must be made available to Alchemy. Here are the steps:
0in
- Include the C++ file in your .mln file, i.e. #include "functions.cpp" (use the
absolute path).
- Declare the predicate or function just as you usually would, i.e.
number max(number, number).
- Declare an interval or enumeration of constants for the types used, i.e.
number={1,...5}.
The name of the types is arbitrary; however, the user is responsible for ensuring they can be
converted to integers, etc. in the function itself, if needed. When the include statement
is encountered, the C++ file is compiled and a shared object file functions.so is put in
the current directory. This file is used to dynamically call the linked-in functions and predicates.
Next: Hybrid Domains
Up: Predicates and Functions
Previous: Internal Functions and Predicates
Marc Sumner
2008-12-01