Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Collection/Cdr.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Emmanuel Antico  >  eMacros  >  src/eMacros/Runtime/Collection/Cdr.php  >  Download  
File: src/eMacros/Runtime/Collection/Cdr.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 2014-01-13 05:23
Size: 1,047 bytes
 

Contents

Class file image Download
<?php
namespace eMacros\Runtime\Collection;

use 
eMacros\Runtime\GenericFunction;

class 
Cdr extends GenericFunction {
    
/**
     * Returns a list without its first element
     * Usage: (Array::cdr (array 1 2 3))
     * Returns: array
     * (non-PHPdoc)
     * @see \eMacros\Runtime\GenericFunction::execute()
     */
    
public function execute(array $arguments) {
        if (empty(
$arguments)) {
            throw new \
BadFunctionCallException("Cdr: No parameters found.");
        }
        
        list(
$list) = $arguments;
        
        if (
is_array($list)) {
            if (empty(
$list)) {
                return 
null;
            }
            
            return 
array_slice($list1);
        }
        
        if (
$list instanceof \Iterator || $list instanceof \IteratorAggregate) {
            
$it $list instanceof \Iterator $list $list->getIterator();
            
$it->rewind();
            
            
//empty list?
            
if (!$it->valid()) {
                return 
null;
            }
            
            
$result = array();
            
            for (
$it->next(); $it->valid(); $it->next()) {
                
$result[] = $it->current();
            }
        
            return 
$result;
        }
        
        throw new \
InvalidArgumentException('Cdr: Parameter is not a list.');
    }
}
?>