aboutsummaryrefslogtreecommitdiff
path: root/perl/step0.5_repl.pl
blob: d8a9d9fd93415499b56907e5f37bc2f1517dc035 (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
use strict;
use warnings FATAL => qw(all);
use readline qw(readline);

# read
sub READ {
    my $str = shift;
    return $str;
}

# eval
sub EVAL {
    my($ast, $env) = @_;
    return eval($ast);
}

# print
sub PRINT {
    my $exp = shift;
    return $exp;
}

# repl
sub REP {
    my $str = shift;
    return PRINT(EVAL(READ($str), {}));
}

while (1) {
    my $line = readline("user> ");
    if (! defined $line) { last; }
    print(REP($line), "\n");
}