本文整理汇总了C++中Cell::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ Cell::Append方法的具体用法?C++ Cell::Append怎么用?C++ Cell::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cell
的用法示例。
在下文中一共展示了Cell::Append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse_Set
// Check(args == 3)
// Check(setting a symbol)
// Make a list, Parseing the set argument
Cell* Parser::Parse_Set(Cell* pSet)
{
// (set! Symbol n)
THROW_ERROR_IF(pSet->Length() != 3, pSet, "'set' does not take " << pSet->Length() << " arguments" );
THROW_ERROR_IF(!(pSet->Cdr()->Car()->GetType() & Cell::SymbolType), pSet, "Can only set! a symbol");
// Parse the third entry
Cell* pRet = Cell::Pair(pSet->Car());
pRet = pRet->Append(pSet->Cdr()->Car());
return pRet->Append(Parse_Cell(pSet->Cdr()->Cdr()->Car()));
}
示例2: Parse_Begin
// Evaluate all items in a begin
Cell* Parser::Parse_Begin(Cell* cell, bool topLevel)
{
UNUSED(topLevel);
if (cell->Length() == 1)
{
return Cell::Void();
}
Cell* pBegin = Cell::Pair(Cell::Symbol(Sym::Symbol("_begin")));
Cell* pCurrent = cell->Cdr();
while (pCurrent && pCurrent->Car())
{
pBegin = pBegin->Append(Parse_Cell(pCurrent->Car()));
pCurrent = pCurrent->Cdr();
}
return pBegin;
}
示例3: Parse_Define
Cell* Parser::Parse_Define(Cell* cell, bool topLevel)
{
UNUSED(topLevel);
THROW_ERROR_IF(cell->Length() < 3, cell, "'define' does not take " << cell->Length() << " arguments");
// Example: (define (add a b) (+ a b))
// (define add (lambda (a b) (+ a b)))
Cell* pParams = cell->Cdr()->Car();
Cell* pBody = cell->Cdr()->Cdr();
// (define (f args..) body)
// Parse the arguments, if necessary, and call back into the Parse
if (pParams->GetType() & Cell::PairType)
{
// f
Cell* f = pParams->Car();
// (Args)
Cell* args = pParams->Cdr();
// (define)
Cell* pDefine = Cell::Pair(Cell::Symbol(Sym::Symbol("_define")), nullptr);
// (lambda)
Cell* pLambda = Cell::Pair(Cell::Symbol(Sym::Symbol("_lambda")), nullptr);
// (lambda (args)
pLambda = pLambda->Append(args);
// (lambda (args) (body)
// Body is a list of expressions. ((+ a a) ...)
while (pBody && pBody->Car())
{
pLambda = pLambda->Append(pBody->Car());
pBody = pBody->Cdr();
}
// (define f)
pDefine = pDefine->Append(f);
// (define f (lamda ...))
pDefine = pDefine->Append(pLambda);
return Parse_Cell(pDefine);
}
// A parsed define, ready to store
else
{
THROW_ERROR_IF(cell->Length()!= 3, cell, "'define' does not take " << cell->Length() << " arguments");
THROW_ERROR_IF(!(pParams->GetType() & Cell::SymbolType), cell, "Expected Symbol in define");
pBody = Parse_Cell(pBody->Car());
// (define)
Cell* pDefine = Cell::Pair(Cell::Symbol(Sym::Symbol("_define")), nullptr);
// (define (params)
pDefine = pDefine->Append(pParams);
// (define (params) (pBody))
pDefine = pDefine->Append(pBody);
return pDefine;
}
}