2020-05-28 04:55:58 +00:00
|
|
|
<?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");
|
|
|
|
}
|
|
|
|
|
2020-05-30 11:47:54 +00:00
|
|
|
public function set(string $key, $value)
|
2020-05-28 04:55:58 +00:00
|
|
|
{
|
|
|
|
$this->data[$key] = $value;
|
2020-05-30 11:47:54 +00:00
|
|
|
return $value;
|
2020-05-28 04:55:58 +00:00
|
|
|
}
|
|
|
|
}
|