Skip to content

Commit 3aeeb9d

Browse files
committed
fix strict/warning hygiene (mostly)
1 parent e3fed1a commit 3aeeb9d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

‎lisp.pl‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
sub Num($) {
1414
my ($n) = @_;
15-
return bless \$n, Num;
15+
return bless \$n, "Num";
1616
}
1717

1818
sub Sym($) {
1919
my ($s) = @_;
20-
return bless \$s, Sym;
20+
return bless \$s, "Sym";
2121
}
2222

23-
our %global_env = {};
23+
our %global_env = ();
2424

2525
sub to_string($) {
2626
my ($e) = @_;
@@ -51,7 +51,7 @@ ($$)
5151
sub env_has($$) {
5252
my ($ctx, $key) = @_;
5353
if (ref $key ne "Sym") { fail("Bad key: ", $key); }
54-
$k = $$key;
54+
my $k = $$key;
5555

5656
if (scalar @$ctx == 0) { return 0; }
5757
if (exists $ctx->[0]{$k}) { return 1; }
@@ -63,7 +63,7 @@ ($$)
6363
sub env_get($$) {
6464
my ($ctx, $key) = @_;
6565
if (ref $key ne "Sym") { fail("Bad key: ", $key); }
66-
$k = $$key;
66+
my $k = $$key;
6767

6868
if (scalar @$ctx == 0) { fail("Not found in environment: ", $key); }
6969
if (exists $ctx->[0]{$k}) { return $ctx->[0]{$k}; }
@@ -75,7 +75,7 @@ ($$)
7575
sub env_set($$$) {
7676
my ($ctx, $key, $value) = @_;
7777
if (ref $key ne "Sym") { fail("Bad key: ", $key); }
78-
$k = $$key;
78+
my $k = $$key;
7979

8080
if (scalar @$ctx == 0) { fail("Not found in environment: ", $key); }
8181
if (exists $ctx->[0]{$k}) { $ctx->[0]{$k} = $value; return; }
@@ -124,20 +124,20 @@ ($$)
124124
if (ref $clause ne "ARRAY" || scalar @$clause == 0) {
125125
fail("Clause of cond must be list: ", $clause);
126126
}
127-
my $truth = eval($ctx, $clause->[0]);
127+
my $truth = do_eval($ctx, $clause->[0]);
128128
if (ref $truth eq "ARRAY" && scalar @$truth == 0) {
129129
return do_cond($ctx, \@rest);
130130
}
131131
if (scalar @$clause == 1) { return $truth; }
132132
my @results = @$clause;
133133
$results[0] = Sym("progn");
134-
return eval($ctx, \@results);
134+
return do_eval($ctx, \@results);
135135
die("Unimplemented");
136136
}
137137

138138
sub do_eval($$) {
139139
my ($ctx, $e) = @_;
140-
print "Evaluating " . (to_string $e) . " in ctx " . (to_string $ctx) . "; " . (to_string $global_env) . "\n";
140+
print "Evaluating " . (to_string $e) . " in ctx " . (to_string $ctx) . "; " . (to_string \%global_env) . "\n";
141141

142142
if (ref $e eq "Num") { return $e; }
143143
if (ref $e eq "Sym") { return env_lookup($ctx, $e); }
@@ -160,8 +160,8 @@ ($$)
160160
my @body = @tl;
161161
$body[0] = Sym("progn");
162162
return sub(@) {
163-
$newctx = extend_ctx($ctx, \@params, \@_);
164-
return do_eval($newctx, $body);
163+
my $newctx = extend_ctx($ctx, \@params, \@_);
164+
return do_eval($newctx, \@body);
165165
};
166166
}
167167
if ($hd eq "define") {
@@ -178,25 +178,25 @@ ($$)
178178
my @body = @tl;
179179
$body[0] = Sym("progn");
180180
$value = sub(@) {
181-
$newctx = extend_ctx($ctx, \@params, \@_);
182-
return do_eval($newctx, $body);
181+
my $newctx = extend_ctx($ctx, \@params, \@_);
182+
return do_eval($newctx, \@body);
183183
};
184184
} else { fail("Bad define: ", $e); }
185185
global_env{$name} = $value;
186-
return value;
186+
return $value;
187187
}
188188
if ($hd eq "setq") {
189189
if (scalar @tl != 2) { fail("Setq applied to wrong number of args in exp: ", $e); }
190-
my $val = do_eval($ctx, $tail[1]);
191-
ctx_mutate($ctx, $tail[0], $val);
190+
my $val = do_eval($ctx, $tl[1]);
191+
ctx_mutate($ctx, $tl[0], $val);
192192
return $val;
193193
}
194194
if ($hd eq "cond") {
195-
return do_cond($ctx, \@tail);
195+
return do_cond($ctx, \@tl);
196196
}
197197
# Function application
198198
my $f = do_eval($ctx, $hd);
199-
my @args = map { do_eval($ctx, $_) } @tail;
199+
my @args = map { do_eval($ctx, $_) } @tl;
200200
return $f->(@args);
201201
}
202202
fail("No case in eval for: ", $e);
@@ -227,14 +227,14 @@ (@)
227227
sub do_eq(@) {
228228
scalar @_ == 2 or fail("Eq applied to wrong number of args: ", \@_);
229229
if (ref $_[0] eq "Num" && ref $_[1] eq "Num") {
230-
return ${$_[0]} == ${$_[1]} or [];
230+
return ${$_[0]} == ${$_[1]} || [];
231231
}
232232
if (ref $_[0] eq "Sym" && ref $_[1] eq "Sym") {
233-
return ${$_[0]} eq ${$_[1]} or [];
233+
return ${$_[0]} eq ${$_[1]} || [];
234234
}
235235
if (ref $_[0] eq "ARRAY" && ref $_[1] eq "ARRAY") {
236236
return (scalar @{$_[0]} == 0 &&
237-
scalar @{$_[1]} == 0) or [];
237+
scalar @{$_[1]} == 0) || [];
238238
}
239239
return []; # No deep comparison.
240240
}
@@ -278,7 +278,7 @@ (@)
278278
$global_env{"-"} = \&do_minus;
279279
$global_env{"*"} = \&do_times;
280280

281-
$fact_test =
281+
my $fact_test =
282282
[Sym "progn",
283283
[Sym "define", [Sym "fact", Sym "n"],
284284
[Sym "cond",

0 commit comments

Comments
 (0)