-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval-lisp
53 lines (45 loc) · 1.05 KB
/
eval-lisp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use strict;
use warnings;
use Lisp::Interpreter;
use Data::Dumper;
use Getopt::Std;
use vars qw($opt_v $opt_f);
unless (getopts("vf:")) {
$0 =~ s,.*/,,;
die "Usage: $0 [-v] [-f <file>] <forms>...\n";
}
my $interp = Lisp::Interpreter->new;
$interp->debug(1) if $opt_v;
if ($opt_f || @ARGV) {
my $text = "";
$text = `cat $opt_f` if $opt_f;
if (@ARGV) {
$text .= "@ARGV";
}
print $interp->read_eval_print($text), "\n";
} else {
#local($/) = ".";
$interp->read_eval_print(<<'EOT');
;; Set up some helper functions
(defun q () (write "Goodbye!") (exit))
(fset 'quit (symbol-function 'q))
EOT
my $bold = `tput bold 2>/dev/null`;
my $norm = `tput rmso 2>/dev/null`;
my $prompt = "${bold}p-lisp>$norm ";
print $prompt;
while (<STDIN>) {
next if /^\s*$/;
eval {
print $interp->read_eval_print($_), "\n";
};
if ($@) {
$@ =~ s/ at \S+ line \d+// unless $opt_v;
print "\aException: $@";
}
} continue {
print $prompt;
}
print "\n";
}