OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
Classes | |
class | opencog::SchemeEval |
class | opencog::PrimitiveEnviron |
class | opencog::SchemePrimitive< T > |
class | opencog::SchemeSmob |
Macros | |
#define | DECLARE_DECLARE_1(RET, ARG) |
#define | DECLARE_DECLARE_2(RET, ARG1, ARG2) |
#define | DECLARE_DECLARE_3(RET, ARG1, ARG2, ARG3) |
#define | DECLARE_DECLARE_4(RET, ARG1, ARG2, ARG3, ARG4) |
Functions | |
int | opencog::load_scm_file (AtomSpace &as, const std::string &filename) |
int | opencog::load_scm_file_relative (AtomSpace &as, const std::string &filename, std::vector< std::string > search_paths) |
void | opencog::load_scm_files_from_config (AtomSpace &atomSpace, std::vector< std::string > search_paths) |
opencog::DECLARE_DECLARE_3 (const std::string &, const std::string &, const std::string &, const std::string &) DECLARE_DECLARE_3(void | |
This library (opencog/smob) implements Scheme extensions using guile. To build it type:
To read a high level overview of this library head to dedicated page.
The evaluator provides two modes of usage: synchronous and asynchronous. The synchronous API is provided by the following methods: eval(), eval_h(), apply(), and apply_generic(). The last three are special-purpose wrappers around the first, returning handles, and applying functions to argument lists.
The eval() method returns a string, holding any output that was printed during evaluation. e.g. output printed using the scheme 'display' function. If the code to be evaluated is long-running, then nothing can be returned until the evaluation completes. This presents a problem when the thing to be evaluated is perhaps an infinite loop.
Thus, the asynchronous interface is provided. This is implemented with three methods: begin_eval(), eval_expr(), and poll_result(). If the expression that needs to be evaluated is long-running, or even if it is an infinite loop, yet which periodically prints, then it can be run in one thread, and the print output can be collected in another thread, with poll_result(). The poll_result() method will block until there is printed output. It can be called repeatedly. When evaluation is completed, it will return any pending printed output, and subsequent calls will return the empty string immediately, without any further blocking. Be sure to call begin_eval() first, to set things up.
The synchronous implementation is built on top of the async one, and runs entirely within the same thread; see the code below; it should show that:
std::string eval(const std::string& expr) { begin_eval(); eval_expr(expr); return poll_result(); }
#define DECLARE_DECLARE_1 | ( | RET, | |
ARG | |||
) |
Definition at line 639 of file SchemePrimitive.h.
#define DECLARE_DECLARE_2 | ( | RET, | |
ARG1, | |||
ARG2 | |||
) |
Definition at line 648 of file SchemePrimitive.h.
#define DECLARE_DECLARE_3 | ( | RET, | |
ARG1, | |||
ARG2, | |||
ARG3 | |||
) |
Definition at line 657 of file SchemePrimitive.h.
#define DECLARE_DECLARE_4 | ( | RET, | |
ARG1, | |||
ARG2, | |||
ARG3, | |||
ARG4 | |||
) |
Definition at line 665 of file SchemePrimitive.h.
opencog::DECLARE_DECLARE_3 | ( | const std::string & | , |
const std::string & | , | ||
const std::string & | , | ||
const std::string & | |||
) |
int opencog::load_scm_file | ( | AtomSpace & | as, |
const std::string & | filename | ||
) |
Load scheme code from a file. The code will be loaded into a running instance of the evaluator. Parsing errors will be printed to stderr.
Return errno if file cannot be opened.
Definition at line 46 of file load-file.cc.
References opencog::SchemeEval::begin_eval(), opencog::GenericEval::eval_error(), opencog::SchemeEval::eval_expr(), and opencog::SchemeEval::poll_result().
int opencog::load_scm_file_relative | ( | AtomSpace & | as, |
const std::string & | filename, | ||
std::vector< std::string > | search_paths | ||
) |
Load scheme file, with the filename specified as a relative path, and the search paths prepended to the relative path. If the search paths are null, a list of defaults search paths are used.
Definition at line 70 of file load-file.cc.
References opencog::load_scm_file().
void opencog::load_scm_files_from_config | ( | AtomSpace & | atomSpace, |
std::vector< std::string > | search_paths | ||
) |
Pull the names of scm files out of the config file, the SCM_PRELOAD key, and try to load those, relative to the search paths.
Definition at line 112 of file load-file.cc.
References opencog::load_scm_file_relative().