Implement apply and rudimentary read-line

This commit is contained in:
madmaurice 2021-04-10 00:17:54 +02:00
parent ba0915f384
commit f576081d22

View file

@ -409,6 +409,23 @@ my %stdctx = (
return length($a); return length($a);
} }
}, },
'apply' => sub {
my ($fn, $lst) = @_;
die "apply: First operand must be a function"
unless ref($fn) eq "CODE";
die "apply: Second operand must be a list"
unless ref($lst) eq "ARRAY";
return $fn->(@$lst);
},
# Input/output
'read-line' => sub {
my $fh = shift;
my $val = defined($fh) ? <$fh> : <>;
chomp $val;
return $val;
}
); );
sub parser { sub parser {