PHP Classes

File: src/eMacros/Runtime/Logical/Cond.php

Recommend this page to a friend!
  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: 10 years ago
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 $scope, GenericList $arguments) {
        foreach (
$arguments as $pair) {
            list(
$condition, $body) = $pair;
           
            if (
$condition->evaluate($scope)) {
                return
$body->evaluate($scope);
            }
        }
    }
}
?>