31 using namespace opencog;
35 for (
const Handle& h: oset)
37 Type t = h->getType();
38 if (VARIABLE_NODE == t)
43 else if (TYPED_VARIABLE_LINK == t)
48 throw InvalidParamException(TRACE_INFO,
49 "Expected a VariableNode or a TypedVariableLink, got: %s",
57 :
Link(VARIABLE_LIST, oset, tv, av)
64 :
Link(t, oset, tv, av)
67 if (VARIABLE_LIST != t)
return;
79 throw InvalidParamException(TRACE_INFO,
80 "Expecting a VariableList, got %s", tname.c_str());
84 if (VARIABLE_LIST != tscope)
return;
89 typedef std::pair<Handle, const std::set<Type> >
ATPair;
116 const std::vector<Handle>& oset =
LinkCast(htypelink)->getOutgoingSet();
117 if (2 != oset.size())
119 throw InvalidParamException(TRACE_INFO,
120 "TypedVariableLink has wrong size, got %lu", oset.size());
131 std::set<Type> ts = {vt};
136 else if (TYPE_CHOICE == t)
140 const std::vector<Handle>& tset =
LinkCast(vartype)->getOutgoingSet();
141 size_t tss = tset.size();
142 for (
size_t i=0; i<tss; i++)
146 if (TYPE_NODE != var_type)
148 throw InvalidParamException(TRACE_INFO,
149 "VariableChoice has unexpected content:\n"
150 "Expected TypeNode, got %s",
163 throw InvalidParamException(TRACE_INFO,
164 "Unexpected contents in TypedVariableLink\n"
165 "Expected TypeNode or TypeChoice, got %s",
197 if ((VARIABLE_NODE == tdecls) or
203 else if (TYPED_VARIABLE_LINK == tdecls)
207 else if (VARIABLE_LIST == tdecls or LIST_LINK == tdecls)
211 const std::vector<Handle>& dset =
LinkCast(hdecls)->getOutgoingSet();
216 throw InvalidParamException(TRACE_INFO,
217 "Expected a VariableList holding variable declarations");
242 VariableTypeMap::const_iterator it =
244 const std::set<Type> &tchoice = it->second;
247 std::set<Type>::const_iterator allow = tchoice.find(htype);
248 return allow != tchoice.end();
265 size_t len = hseq.size();
271 for (
size_t i=0; i<len; i++)
273 VariableTypeMap::const_iterator it =
277 const std::set<Type> &tchoice = it->second;
278 Type htype = hseq[i]->getType();
279 std::set<Type>::const_iterator allow = tchoice.find(htype);
280 if (allow == tchoice.end())
return false;
296 for (
size_t i=0; i<sz; i++)
355 throw InvalidParamException(TRACE_INFO,
356 "Incorrect numer of arguments specified, expecting %lu got %lu",
360 throw InvalidParamException(TRACE_INFO,
361 "Arguments fail to match variable declarations");
370 std::map<Handle, unsigned int>::const_iterator idx;
373 return args.at(idx->second);
378 if (NULL == lterm)
return term;
381 if (QUOTE_LINK == term->
getType())
return term;
385 for (
const Handle& h : lterm->getOutgoingSet())
static TypeNodePtr TypeNodeCast(const Handle &h)
Variables _varlist
Unbundled variables and types for them.
void validate_vardecl(const Handle &)
std::vector< Handle > HandleSeq
a list of handles
std::set< Handle > varset
bool is_type(const Handle &) const
std::shared_ptr< TruthValue > TruthValuePtr
std::shared_ptr< AttentionValue > AttentionValuePtr
std::shared_ptr< Link > LinkPtr
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
void get_vartype(const Handle &)
static NodePtr NodeCast(const Handle &h)
std::map< Handle, unsigned int > index
Handle substitute_nocheck(const Handle &, const HandleSeq &) const
const std::string & getTypeName(Type type)
static LinkPtr LinkCast(const Handle &h)
Handle substitute(const Handle &tree, const HandleSeq &vals) const
VariableList(Type, const HandleSeq &, TruthValuePtr tv=TruthValue::DEFAULT_TV(), AttentionValuePtr av=AttentionValue::DEFAULT_AV())
unsigned short Type
type of Atoms, represented as short integer (16 bits)
std::pair< Handle, const std::set< Type > > ATPair