aboutsummaryrefslogtreecommitdiff
path: root/php/step0_repl.php
blob: eecb0523d4b3d078cbd856c2461c15ff2bb328e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

require_once 'readline.php';

// read
function READ($str) {
    return $str;
}

// eval
function MAL_EVAL($ast, $env) {
    return eval($ast);
}

// print
function MAL_PRINT($exp) {
    return var_export($exp, true) . "\n";
}

// repl
function rep($str) {
    return MAL_PRINT(MAL_EVAL(READ($str), array()));
}

// repl loop
do {
    $line = mal_readline("user> ");
    if ($line === NULL) { break; }
    if (!empty($line)) {
        print(rep($line));
    }
} while (true);

?>