Re:Simplicity Made Easy
by blondin on Wednesday June 26, 2019 @01:25AM
(#20282125)
oh wow, the "say" keyword is quite nifty. also, straightforward iterative solutions often lead to inefficient implementations. which is why most of us fall prey to complicated implementations that use all the tricks in the book... i don't know much about perl anymore, but in some languages, creating a new date object every time through that loop might not be space efficient.
[ Parent
| on HN ]
The magic isn't really in say. say is just print with an automatic linefeed at the end (and, two fewer keystrokes for the keyword). Perl's print (even in very old versions of Perl, dating long before say arrived) also accepts expressions as arguments, so you can write: `print join "\n", @array;`
Obviously, the Date (and other) type stuff is new to Perl 6, and is quite lovely.
>Perl's print (even in very old versions of Perl, dating long before say arrived) also accepts expressions as arguments, so you can write: `print join "\n", @array;`
How's that different from any other language? Isn't the expression argument evaluated before being passed to print, so at that point it's just a string anyway?
>>> print ", ".join(["a","b","c"])
a, b, c
Or, if the point is about omitting the automatic newline, comma in python suppresses it: >>> print "\n".join(["a","b","c"]),
a
b
cIt's not (at least most modern languages have it). I was just saying that `say` isn't the interesting thing in the examples given.
>print ... also accepts expressions as arguments
It's true for all perl functions. Unusual part, if I got you right, is that parenthesis are optional in perl. So, this:
foo bar "\n", @baz;
is equivalent to: foo(bar("\n", @baz));
(unless bar has ($) prototype, anyway; but then it all gets ambiguous)Mostly I was just saying that `say` isn't the interesting bit of the examples given. But, sure, Perl is nice in how flexible/expressive it is (and Perl 6 takes that even further). I think maybe that's even the most interesting thing about the article. I mean, the date math is super cool and impressive and elegant, but the various paradigm examples is maybe more fun for me, since munging dates is rarely a thing I do.
TIMTOWTDI can get out of hand, at times, but it's really nice to have such beautiful concise ways to solve a problem in OO, functional, parallel, etc. styles all of which are very readable and quite concise.