aboutsummaryrefslogtreecommitdiff
path: root/php/step1_read_print.php
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
committerJoel Martin <github@martintribe.org>2014-03-24 16:32:24 -0500
commit3169070063b2cb877200117ebb384269d73bcb93 (patch)
tree23de3db1ea5c37afd21a45b6ed7771f56a08c0c4 /php/step1_read_print.php
downloadmal-3169070063b2cb877200117ebb384269d73bcb93.tar.gz
mal-3169070063b2cb877200117ebb384269d73bcb93.zip
Current state of mal for Clojure West lighting talk.
Diffstat (limited to 'php/step1_read_print.php')
-rw-r--r--php/step1_read_print.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/php/step1_read_print.php b/php/step1_read_print.php
new file mode 100644
index 0000000..01334e0
--- /dev/null
+++ b/php/step1_read_print.php
@@ -0,0 +1,42 @@
+<?php
+
+require_once 'readline.php';
+require_once 'types.php';
+require_once 'reader.php';
+
+// read
+function READ($str) {
+ return read_str($str);
+}
+
+// eval
+function MAL_EVAL($ast, $env) {
+ return $ast;
+}
+
+// print
+function MAL_PRINT($exp) {
+ return _pr_str($exp, True) . "\n";
+}
+
+// repl
+function rep($str) {
+ return MAL_PRINT(MAL_EVAL(READ($str), array()));
+}
+
+do {
+ try {
+ $line = mal_readline("user> ");
+ if ($line === NULL) { break; }
+ if ($line !== "") {
+ print(rep($line));
+ }
+ } catch (BlankException $e) {
+ continue;
+ } catch (Exception $e) {
+ echo "Error: " . $e->getMessage() . "\n";
+ echo $e->getTraceAsString() . "\n";
+ }
+} while (true);
+
+?>