Login   Register  
PHP Classes
elePHPant
Icontem

File: src/eMacros/Runtime/Symbol/SymbolSet.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/Symbol/SymbolSet.php  >  Download  
File: src/eMacros/Runtime/Symbol/SymbolSet.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: 882 bytes
 

Contents

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

use 
eMacros\Applicable;
use 
eMacros\Scope;
use 
eMacros\GenericList;
use 
eMacros\Environment\Environment;
use 
eMacros\Symbol;

class 
SymbolSet implements Applicable {
    
/**
     * Defines a symbol value
     * Usage: (sym "value") (sym "counter" 0)
     * Returns: NULL
     * (non-PHPdoc)
     * @see \eMacros\Applicable::apply()
     */
    
public function apply(Scope $scopeGenericList $arguments) {
        if (
count($arguments) == 0) {
            throw new \
BadFunctionCallException("SymbolSet: No parameters found.");
        }
        
        
$ref $arguments[0]->evaluate($scope);
        
        if (!
is_string($ref) || empty($ref)) {
            throw new \
InvalidArgumentException("SymbolSet: Symbol must be specified as a non-empty string.");
        }
        
        
Symbol::validateSymbol($ref);
        
$value = (count($arguments) > 1) ? $arguments[1]->evaluate($scope) : null;
        
$scope->symbols[$ref] = $value;
    }
}
?>