OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LambdaLink.h
Go to the documentation of this file.
1 /*
2  * opencog/atoms/LambdaLink.h
3  *
4  * Copyright (C) 2015 Linas Vepstas
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License v3 as
9  * published by the Free Software Foundation and including the exceptions
10  * at http://opencog.org/wiki/Licenses
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program; if not, write to:
19  * Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef _OPENCOG_LAMBDA_LINK_H
24 #define _OPENCOG_LAMBDA_LINK_H
25 
26 #include <map>
27 
29 
30 namespace opencog
31 {
36 class LambdaLink : public VariableList
48 {
49 protected:
52 
53  LambdaLink(Type, const HandleSeq&,
56 
57  void init(const HandleSeq&);
58 
59  // utility debug print
60  static void prt(const Handle& h)
61  {
62  printf("%s\n", h->toShortString().c_str());
63  }
64 public:
65  LambdaLink(const HandleSeq&,
68 
69  LambdaLink(const Handle& varcdecls, const Handle& body,
72 
73  LambdaLink(Link &l);
74 
75  // Take the list of values `vals`, and substitute them in for the
76  // variables in the body of this lambda. The values must satisfy all
77  // type restrictions, else an exception will be thrown.
78  Handle substitute (const HandleSeq& vals) const
79  {
80  return VariableList::substitute(_body, vals);
81  }
82 };
83 
84 typedef std::shared_ptr<LambdaLink> LambdaLinkPtr;
85 static inline LambdaLinkPtr LambdaLinkCast(const Handle& h)
86  { AtomPtr a(h); return std::dynamic_pointer_cast<LambdaLink>(a); }
88  { return std::dynamic_pointer_cast<LambdaLink>(a); }
89 
90 // XXX temporary hack ...
91 #define createLambdaLink std::make_shared<LambdaLink>
92 
94 }
95 
96 #endif // _OPENCOG_LAMBDA_LINK_H
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
std::shared_ptr< Atom > AtomPtr
Definition: Handle.h:48
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
std::shared_ptr< AttentionValue > AttentionValuePtr
virtual std::string toShortString(std::string indent="")=0
static TruthValuePtr DEFAULT_TV()
Definition: TruthValue.cc:52
Handle substitute(const Handle &tree, const HandleSeq &vals) const
static AttentionValuePtr DEFAULT_AV()
to be used as default attention value
static LambdaLinkPtr LambdaLinkCast(const Handle &h)
Definition: LambdaLink.h:85
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
std::shared_ptr< LambdaLink > LambdaLinkPtr
Definition: LambdaLink.h:84