From f576081d22974bd906f24a82a0f6f0f746e9d8bc Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Sat, 10 Apr 2021 00:17:54 +0200 Subject: [PATCH] Implement apply and rudimentary read-line --- lib/Minilisp.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index a83d491..1d5dc1e 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -409,6 +409,23 @@ my %stdctx = ( 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 {