Dist/packaging for most impls. erlang, racket *ARGV* fixes.
[jackhill/mal.git] / php / step1_read_print.php
CommitLineData
31690700
JM
1<?php
2
3require_once 'readline.php';
4require_once 'types.php';
5require_once 'reader.php';
ea81a808 6require_once 'printer.php';
31690700
JM
7
8// read
9function READ($str) {
10 return read_str($str);
11}
12
13// eval
14function MAL_EVAL($ast, $env) {
15 return $ast;
16}
17
18// print
19function MAL_PRINT($exp) {
10b07148 20 return _pr_str($exp, True);
31690700
JM
21}
22
23// repl
24function rep($str) {
25 return MAL_PRINT(MAL_EVAL(READ($str), array()));
26}
27
86b689f3 28// repl loop
31690700
JM
29do {
30 try {
31 $line = mal_readline("user> ");
32 if ($line === NULL) { break; }
33 if ($line !== "") {
10b07148 34 print(rep($line) . "\n");
31690700
JM
35 }
36 } catch (BlankException $e) {
37 continue;
38 } catch (Exception $e) {
39 echo "Error: " . $e->getMessage() . "\n";
40 echo $e->getTraceAsString() . "\n";
41 }
42} while (true);
43
86b689f3 44?>