Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Logical/Cond.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/Logical/Cond.php  >  Download  
File: src/eMacros/Runtime/Logical/Cond.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: 606 bytes
 

Contents

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

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

class 
Cond implements Applicable {
    
/**
     * Returns a value depending on a condition
     * Usage: (cond ((is-integer? (%0)) 'Integer') ((is-string? (%0)) 'String') (true 'Unexpected type'))
     * Returns: mixed
     * (non-PHPdoc)
     * @see \eMacros\Applicable::apply()
     */
    
public function apply(Scope $scopeGenericList $arguments) {
        foreach (
$arguments as $pair) {
            list(
$condition$body) = $pair;
            
            if (
$condition->evaluate($scope)) {
                return 
$body->evaluate($scope);
            }
        }
    }
}
?>