/
symbol.php
43 lines (40 loc) · 1.01 KB
/
symbol.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class Symbol {
static $table = array();
private $name = null;
public $symbol = true;
public $macro = false;
static function init () {}
static function pull ($name) {
if (array_key_exists ($name, self :: $table))
return self :: $table [$name];
else {
$x = new Symbol ($name);
self :: $table [$name] = $x;
return $x;}}
private function __construct ($name) {
$this -> name = $name;}
function __toString () {
return $this -> name;}
function lookup_in ($environment) {
$x = array_reverse ($environment);
foreach ($x as $env)
if (array_key_exists ($this."", $env))
return $env [$this.""];
if (array_key_exists ($this."", Lisp :: $root))
return Lisp :: $root [$this.""];
if (function_exists ($this.""))
return $this."";
die ("Symbol lookup failed ".$this);}}
function symbol($name)
{
return Symbol::pull($name);
}
function is_symbol($x) {
return ($x instanceof Symbol);
}
function symbol_str($symbol)
{
return $symbol."";
}
?>