mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 23:25:19 +00:00
29 lines
561 B
PHP
29 lines
561 B
PHP
|
<?php
|
||
|
namespace MadLisp;
|
||
|
|
||
|
class Env extends Hash
|
||
|
{
|
||
|
protected ?Env $parent;
|
||
|
|
||
|
public function __construct(?Env $parent = null)
|
||
|
{
|
||
|
$this->parent = $parent;
|
||
|
}
|
||
|
|
||
|
public function get(string $key)
|
||
|
{
|
||
|
if ($this->has($key)) {
|
||
|
return $this->data[$key];
|
||
|
} elseif ($this->parent) {
|
||
|
return $this->parent->get($key);
|
||
|
}
|
||
|
|
||
|
throw new MadLispException("symbol $key not defined in env");
|
||
|
}
|
||
|
|
||
|
public function set(string $key, $value): void
|
||
|
{
|
||
|
$this->data[$key] = $value;
|
||
|
}
|
||
|
}
|