File: src/eMacros/Runtime/Binary/BinaryOr.php

Recommend this page to a friend!
  Classes of Emmanuel Antico  >  eMacros  >  src/eMacros/Runtime/Binary/BinaryOr.php  >  Download  
File: src/eMacros/Runtime/Binary/BinaryOr.php
Role: Class source
Content type: text/plain
Description: Class source
Class: eMacros
PHP LISP language interpreter
Author: By
Last change:
Date: 7 years ago
Size: 750 bytes
 

Contents

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

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

class
BinaryOr implements Applicable {
   
/**
     * Applies the binary OR to a list of operands
     * Usage: (| 5 2)
     * Returns: number
     * (non-PHPdoc)
     * @see \eMacros\Applicable::apply()
     */
   
public function apply(Scope $scope, GenericList $arguments) {
        if (
count($arguments) == 0) {
            throw new \
BadFunctionCallException("BinaryOr: 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;
    }
}
?>

For more information send a message to info at phpclasses dot org.