Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rename s/grep/filter/
The name 'grep' is an affectation within the Perl language and
community, caused by such things as being almost the first among
the dynamic languages to have a function like this, and wanting
to harken to Unix names and ways. After that, it's just inertia
that makes it keep this name. The name originally stems from an
'ed' command, and is an acronym for "Globally search a Regular
Expression and Print". Not much of this is relevant for the
modern function of selectively retaining elements from a list.

007 is not bound by tradition, inertia, or nostalgia. Hence we
switch to the Python name 'filter'.
  • Loading branch information
Carl Masak committed Oct 7, 2015
1 parent 404e6b1 commit 9097bab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/_007/Runtime.pm
Expand Up @@ -129,7 +129,7 @@ role Runtime {
index => -> $s, $substr { Val::Int.new(:value($s.value.index($substr.value) // -1)) },
substr => sub ($s, $pos, $chars?) { Val::Str.new(:value($s.value.substr($pos.value, $chars.defined ?? $chars.value !! $s.value.chars))) },
charat => -> $s, $pos { Val::Str.new(:value($s.value.comb[$pos.value] // die X::Subscript::TooLarge.new)) },
grep => -> $fn, $a {
filter => -> $fn, $a {
my $array = Val::Array.new;
for $a.elements {
$array.elements.push($_) if truthy(self.call($fn, [$_]));
Expand Down
4 changes: 2 additions & 2 deletions t/features/builtins.t
Expand Up @@ -195,10 +195,10 @@ use _007::Test;
(statements
(sub (ident "f") (parameters (ident "n")) (statements
(return (== (ident "n") (int 2)))))
(stexpr (call (ident "say") (arguments (call (ident "grep") (arguments (ident "f") (array (int 1) (int 2) (int 3) (int 2))))))))
(stexpr (call (ident "say") (arguments (call (ident "filter") (arguments (ident "f") (array (int 1) (int 2) (int 3) (int 2))))))))
.

is-result $ast, "[2, 2]\n", "grep() works";
is-result $ast, "[2, 2]\n", "filter() works";
}

{
Expand Down
2 changes: 1 addition & 1 deletion tutorial/README.md
Expand Up @@ -224,7 +224,7 @@ subroutines. These should be fairly self-explanatory.
reversed(array)
sorted(array)
join(array, sep)
grep(fn, array)
filter(fn, array)
map(fn, array)

There are also constructor methods for creating program elements.
Expand Down

0 comments on commit 9097bab

Please sign in to comment.