Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

lisp.hpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00024 #ifndef INTELIB_LISP_HPP_SENTRY
00025 #define INTELIB_LISP_HPP_SENTRY
00026 
00027 
00028 #include "../sexpress/sexpress.hpp"
00029 #include "../sexpress/iexcept.hpp"
00030 
00031 
00032 class LReference;
00033 
00035 typedef LReference (*UserLispFunction)(int, const SReference *);
00036 
00038 
00046 class LReference : public SReference {
00047 public:
00049     LReference() {}
00051     LReference(const LReference& ref) : SReference(ref) {}
00053     LReference(const SReference& ref) : SReference(ref) {}
00055     LReference(SExpression* p) : SReference(p) {}
00057     LReference(UserLispFunction fun);
00058  
00059     template <class X> LReference(X &x) : SReference(x) {}
00060     template <class X> LReference(const X &x) : SReference(x) {}
00061 
00062     ~LReference() {}
00063 
00065 
00069     LReference Evaluate() const;
00070 
00072 
00081     LReference Evaluate(class LispContinuation &within) const; 
00082 
00084 
00088     bool IsTrue() const; 
00089 
00091     LReference& operator,(const SReference& ref)
00092         { SReference::operator,(ref); return *this; }
00093 
00095     LReference& operator||(const SReference& ref)
00096         { SReference::operator||(ref); return *this; }
00097 
00099     LReference operator~() const;
00100 
00102     bool IsEql(const SReference& other) const;
00104     bool IsEqual(const SReference& other) const;
00105 
00106 #if INTELIB_TEXT_REPRESENTATIONS == 1
00107 
00108 
00111     SString TextRepresentation() const;
00112 #endif
00113 };
00114 
00115 
00117 extern SReference *PTheLispSymbolLambda;
00119 extern SReference *PTheLispSymbolQuote;
00121 extern SReference *PTheLispSymbolFunction;
00123 extern SReference *PTheLispBooleanTrue;
00125 extern SReference *PTheLispBooleanFalse;
00126 
00127 
00128 inline bool LReference::IsTrue() const 
00129 { return GetPtr() != PTheLispBooleanFalse->GetPtr(); } 
00130 
00131 inline LReference LReference::operator~() const 
00132 { 
00133     return 
00134         LReference(
00135             new SExpressionCons(*PTheLispSymbolQuote, 
00136                                 SReference(
00137                                     new SExpressionCons(*this, 
00138                                                         *PTheEmptyList)
00139                                ))
00140        ); 
00141 } 
00142 
00143 
00144 
00146 
00158 class LListConstructor : public SListConstructor {
00159 public:
00160     LListConstructor() {}
00161     ~LListConstructor() {}
00162     
00163     LReference operator |(const LReference &t) const
00164         { return LReference(new SExpressionCons(t, *PTheEmptyList)); } 
00165     LReference operator ^(const LReference &other) const
00166         { return LReference(new SExpressionCons(*PTheEmptyList, other)); }
00167 
00168     LReference operator ~() const { return *PTheEmptyList; }
00169 };
00170 
00171 
00173 
00180 class LFunctionConstructor {
00181 public:
00182     LFunctionConstructor() {}
00183     ~LFunctionConstructor() {}
00184     
00185     LReference operator ^(const LReference &op) const
00186         { return SReference(*PTheLispSymbolFunction, 
00187                             SReference(op, *PTheEmptyList)); }
00188 };
00189 
00191 
00195 inline LReference operator~(const SReference& r) { return ~LReference(r); }
00196 
00197 
00198 #endif

Generated on Tue Dec 18 00:39:43 2007 for InteLib by  doxygen 1.4.1