OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LambdaLink.cc
Go to the documentation of this file.
1 /*
2  * LambdaLink.cc
3  *
4  * Copyright (C) 2009, 2014, 2015 Linas Vepstas
5  *
6  * Author: Linas Vepstas <linasvepstas@gmail.com> January 2009
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License v3 as
10  * published by the Free Software Foundation and including the
11  * exceptions
12  * at http://opencog.org/wiki/Licenses
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public
20  * License
21  * along with this program; if not, write to:
22  * Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
27 #include <opencog/atoms/TypeNode.h>
28 
29 #include "LambdaLink.h"
30 
31 using namespace opencog;
32 
33 void LambdaLink::init(const HandleSeq& oset)
34 {
35  // Must have variable decls and body
36  if (2 != oset.size())
37  throw InvalidParamException(TRACE_INFO,
38  "Expecting variabe decls and body, got size %d", oset.size());
39 
41  _body = oset[1]; // Body
42 }
43 
46  : VariableList(LAMBDA_LINK, oset, tv, av)
47 {
48  init(oset);
49 }
50 
51 LambdaLink::LambdaLink(const Handle& vars, const Handle& body,
53  : VariableList(LAMBDA_LINK, HandleSeq({vars, body}), tv, av)
54 {
55  init(getOutgoingSet());
56 }
57 
60  : VariableList(t, oset, tv, av)
61 {
62  // Derived classes have a different initialization sequence
63  if (LAMBDA_LINK != t) return;
64  init(oset);
65 }
66 
68  : VariableList(l)
69 {
70  // Type must be as expected
71  Type tscope = l.getType();
72  if (not classserver().isA(tscope, LAMBDA_LINK))
73  {
74  const std::string& tname = classserver().getTypeName(tscope);
75  throw InvalidParamException(TRACE_INFO,
76  "Expecting a LambdaLink, got %s", tname.c_str());
77  }
78 
79  // Dervided types have a different initialization sequence
80  if (LAMBDA_LINK != tscope) return;
81  init(l.getOutgoingSet());
82 }
83 
84 /* ===================== END OF FILE ===================== */
void validate_vardecl(const Handle &)
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::shared_ptr< AttentionValue > AttentionValuePtr
Type getType() const
Definition: Atom.h:197
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
Definition: ClassServer.cc:159
const std::string & getTypeName(Type type)
Definition: ClassServer.cc:148
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40