Commit 033a95aa authored by Juergen Nickelsen's avatar Juergen Nickelsen
Browse files

slight revision of Benvironment, Benv_vars, Benv_ref

parent 4049ceb2
......@@ -21,13 +21,14 @@ use Interp;
# beginning with 'B', and are defined here (except for, well, exceptions)
sub Benvironment {
my ($env) = checkargs($_[0], ':E');
my ($env, $noparents) = checkargs($_[0], ':Ee');
my %vars = ();
$env = $Env if is_nil($env);
while (defined($env)) {
while (my ($key, $value) = each(%$env)) {
$vars{$key} //= $value;
}
last if $noparents;
$env = $env->{$n_parentenv};
}
my $result = $Nil;
......@@ -74,22 +75,22 @@ sub Bpop {
}
sub Bsubstr {
my ($str, $start, $end) = checkargs($_[0], 'sn:n');
$start = 0 if $start < 0;
my $len = length($str);
$start = $len if $start > $len;
if (is_nil($end)) {
return substr($str, $start);
} else {
$end = $start if $end < $start;
$end = $len if $end > $len;
return substr($str, $start, $end - $start);
}
my ($str, $start, $end) = checkargs($_[0], 'sn:n');
$start = 0 if $start < 0;
my $len = length($str);
$start = $len if $start > $len;
if (is_nil($end)) {
return substr($str, $start);
} else {
$end = $start if $end < $start;
$end = $len if $end > $len;
return substr($str, $start, $end - $start);
}
}
sub Bsublist {
my ($list, $start, $end) = checkargs($_[0], 'ln:n');
return sublist($list, $start, $end);
my ($list, $start, $end) = checkargs($_[0], 'ln:n');
return sublist($list, $start, $end);
}
sub sublist {
......@@ -214,14 +215,14 @@ sub Bfunction_environment {
}
sub Benv_vars {
my ($environment, $noparent) = checkargs($_[0], ':Et');
my ($environment, $noparent) = checkargs($_[0], ':Ee');
$environment = $Env if is_nil($environment);
return array2list(env_vars($environment, !is_nil($noparent)));
}
sub Benv_ref {
my ($environment, $symbol, $noparents) = checkargs($_[0], 'Ey:e');
return symbol_value_in_env($symbol, $environment, !is_nil($noparents));
return symbol_value($symbol, $environment, !is_nil($noparents));
}
sub Bdefvar {
......@@ -1172,7 +1173,7 @@ my @builtins = # [name, func, is_special, doc]
["unless", \&Bunless, 1,
"if COND yields nil, eval BODYFORMS and return the result of the last"],
["environment", \&Benvironment, 0,
"return bindings of ENVIRONMENT (or the current) as list of pairs"],
"bindings of ENVIRON (or current) as list of pairs, &optional NOPARENTS"],
["substr", \&Bsubstr, 0,
"return the substring of STRING from START to &optional END"],
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment