aboutsummaryrefslogtreecommitdiff
path: root/php/step9_try.php
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /php/step9_try.php
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'php/step9_try.php')
-rw-r--r--php/step9_try.php22
1 files changed, 10 insertions, 12 deletions
diff --git a/php/step9_try.php b/php/step9_try.php
index 9343dea..0470763 100644
--- a/php/step9_try.php
+++ b/php/step9_try.php
@@ -35,13 +35,13 @@ function quasiquote($ast) {
function is_macro_call($ast, $env) {
return is_pair($ast) &&
_symbol_Q($ast[0]) &&
- $env->find($ast[0]->value) &&
- $env->get($ast[0]->value)->ismacro;
+ $env->find($ast[0]) &&
+ $env->get($ast[0])->ismacro;
}
function macroexpand($ast, $env) {
while (is_macro_call($ast, $env)) {
- $mac = $env->get($ast[0]->value);
+ $mac = $env->get($ast[0]);
$args = array_slice($ast->getArrayCopy(),1);
$ast = $mac->apply($args);
}
@@ -50,7 +50,7 @@ function macroexpand($ast, $env) {
function eval_ast($ast, $env) {
if (_symbol_Q($ast)) {
- return $env->get($ast->value);
+ return $env->get($ast);
} elseif (_sequential_Q($ast)) {
if (_list_Q($ast)) {
$el = _list();
@@ -87,12 +87,12 @@ function MAL_EVAL($ast, $env) {
switch ($a0v) {
case "def!":
$res = MAL_EVAL($ast[2], $env);
- return $env->set($ast[1]->value, $res);
+ return $env->set($ast[1], $res);
case "let*":
$a1 = $ast[1];
$let_env = new Env($env);
for ($i=0; $i < count($a1); $i+=2) {
- $let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env));
+ $let_env->set($a1[$i], MAL_EVAL($a1[$i+1], $let_env));
}
$ast = $ast[2];
$env = $let_env;
@@ -105,7 +105,7 @@ function MAL_EVAL($ast, $env) {
case "defmacro!":
$func = MAL_EVAL($ast[2], $env);
$func->ismacro = true;
- return $env->set($ast[1]->value, $func);
+ return $env->set($ast[1], $func);
case "macroexpand":
return macroexpand($ast[1], $env);
case "try*":
@@ -172,19 +172,18 @@ function rep($str) {
// core.php: defined using PHP
foreach ($core_ns as $k=>$v) {
- $repl_env->set($k, _function($v));
+ $repl_env->set(_symbol($k), _function($v));
}
-$repl_env->set('eval', _function(function($ast) {
+$repl_env->set(_symbol('eval'), _function(function($ast) {
global $repl_env; return MAL_EVAL($ast, $repl_env);
}));
$_argv = _list();
for ($i=2; $i < count($argv); $i++) {
$_argv->append($argv[$i]);
}
-$repl_env->set('*ARGV*', $_argv);
+$repl_env->set(_symbol('*ARGV*'), $_argv);
// core.mal: defined using the language itself
-rep("(def! *host-language* \"php\")");
rep("(def! not (fn* (a) (if a false true)))");
rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
@@ -196,7 +195,6 @@ if (count($argv) > 1) {
}
// repl loop
-rep("(println (str \"Mal [\" *host-language* \"]\"))");
do {
try {
$line = mal_readline("user> ");