Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on How Ruby Borrowed a Decades Old Idea From Lisp. Parent comment
# ruby double = [1..10].map { |x| x * 2 } # perl my @double = map { $_ * 2 } 1..10;
And it's easy create new ones as well:
sub loop (&) { my $block = shift; $block->() while 1; } loop { say "Nuts" };
sub ifTrue (&@) { my ($block, $cond) = @_; $block->() if $cond; $cond; } sub ifFalse (&@) { my ($block, $cond) = @_; $block->() unless $cond; $cond; } ifTrue { say "True" } ifFalse { say "False" } 1 == 1;
[1] - Not sure what the proper name for this syntax is!
There are no comments on this comment yet.
And it's easy create new ones as well:
And you can also chain them together to build more complex constructs: I once wrote a lazy functional syntax in Perl using this approach :)[1] - Not sure what the proper name for this syntax is!