1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/perl/step1_read_print.pl
Joel Martin b8ee29b22f All: add keywords.
Also, fix nth and count to match cloure.
2015-01-09 16:16:50 -06:00

63 lines
1.2 KiB
Perl

use strict;
use warnings FATAL => qw(all);
no if $] >= 5.018, warnings => "experimental::smartmatch";
use File::Basename;
use lib dirname (__FILE__);
use readline qw(mal_readline set_rl_mode);
use feature qw(switch);
use reader;
use printer;
# read
sub READ {
my $str = shift;
return reader::read_str($str);
}
# eval
sub EVAL {
my($ast, $env) = @_;
return $ast;
}
# print
sub PRINT {
my $exp = shift;
return printer::_pr_str($exp);
}
# repl
sub REP {
my $str = shift;
return PRINT(EVAL(READ($str), {}));
}
if (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") {
set_rl_mode("raw");
}
while (1) {
my $line = mal_readline("user> ");
if (! defined $line) { last; }
do {
local $@;
my $ret;
eval {
use autodie; # always "throw" errors
print(REP($line), "\n");
1;
} or do {
my $err = $@;
given (ref $err) {
when (/^BlankException/) {
# ignore and continue
}
default {
chomp $err;
print "Error: $err\n";
}
}
};
};
}