Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Argument/ArgumentGet.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/Argument/ArgumentGet.php  >  Download  
File: src/eMacros/Runtime/Argument/ArgumentGet.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: 966 bytes
 

Contents

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

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

class 
ArgumentGet implements Applicable {
    
/**
     * Argument index to obtain
     * @var int
     */
    
public $index;
    
    public function 
__construct($index null) {
        
$this->index $index;
    }
    
    
/**
     * Obtains argument at given index
     * Usage: (%0) (% _num)
     * Returns: mixed
     * (non-PHPdoc)
     * @see \eMacros\Applicable::apply()
     */
    
public function apply(Scope $scopeGenericList $arguments) {
        if (
is_null($this->index)) {
            if (
count($arguments) == 0) {
                throw new \
BadFunctionCallException("ArgumentGet: No index specified.");
            }
            
            
$index intval($arguments[0]->evaluate($scope));
        }
        else {
            
$index $this->index;
        }
        
        if (!
array_key_exists($index$scope->arguments)) {
            throw new \
UnexpectedValueException(sprintf("ArgumentGet: No parameter found at index %d."$index));
        }
        
        return 
$scope->arguments[$index];
    }
}
?>