本文整理汇总了C++中Cell::Cdr方法的典型用法代码示例。如果您正苦于以下问题:C++ Cell::Cdr方法的具体用法?C++ Cell::Cdr怎么用?C++ Cell::Cdr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cell
的用法示例。
在下文中一共展示了Cell::Cdr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: Parse_Lambda
// (lambda (x) e1 e2) => (lamba (a) (begin e1 e2))
Cell* Parser::Parse_Lambda(Cell* cell)
{
THROW_ERROR_IF(cell->Length() < 3, cell, "'lambda' does not take " << cell->Length() << " arguments");
Cell* pArgs = cell->Cdr()->Car();
if (pArgs->IsPair())
{
Cell* pCurrent = pArgs;
while(pCurrent && pCurrent->Car())
{
THROW_ERROR_IF(!(pCurrent->Car()->GetType() & Cell::SymbolType), cell, "'lambda' arg is not a symbol: " << pCurrent);
pCurrent = pCurrent->Cdr();
}
}
else
{
THROW_ERROR_IF(!(pArgs->GetType() & Cell::SymbolType), cell, "'lambda' arg is not a symbol or list: " << pArgs);
}
// (_lambda (args) ... (body) / (begin (body) (body))
Cell* pLambda(Cell::Pair(Cell::Symbol(Sym::Symbol("_lambda")), nullptr));
pLambda->Append(pArgs);
Cell* pBody = cell->Cdr()->Cdr();
if (pBody->Length() == 1)
{
// Parse the single body argument, no need for a begin
pLambda->Append(Parse_Cell(pBody->Car()));
}
else
{
// Append all the body arguments as a begin
Cell* pBegin = Cell::Pair(Cell::Symbol(Sym::Symbol("_begin")));
pBegin = AppendCells(pBody, pBegin);
pBegin = Parse_Cell(pBegin);
pLambda->Append(pBegin);
}
return pLambda;
}
示例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;
}
}