Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Binary/BinaryAnd.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/Binary/BinaryAnd.php  >  Download  
File: src/eMacros/Runtime/Binary/BinaryAnd.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: 756 bytes
 

Contents

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

use 
eMacros\Applicable;
use 
eMacros\Scope;
use 
eMacros\GenericList;

class 
BinaryAnd implements Applicable {
    
/**
     * Applies the binary AND to a list of operands
     * Usage: (& 11 5 1)
     * Returns: number
     * (non-PHPdoc)
     * @see \eMacros\Applicable::apply()
     */
    
public function apply(Scope $scopeGenericList $arguments) {
        if (
count($arguments) == 0) {
            throw new \
BadFunctionCallException("BinaryAnd: No parameters found.");
        }
        
        
$it $arguments->getIterator();
        
$it->rewind();
        
        if (!
$it->valid()) {
            return 
0;
        }
        
        
$value $it->current()->evaluate($scope);
        
        for (
$it->next(); $it->valid(); $it->next()) {
            
$value &= $it->current()->evaluate($scope);
        }
        
        return 
$value;
    }
}
?>