News for hackers. Stuff that matters.
Re:Which Programming Languages Are Functional? by tripa on Wednesday December 30, 2015 @10:19AM (#10812348)
> [Perl] has a magic argument, $_, which means something like, "the return value of the previous call".

What?!

Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @10:21AM (#10812365)
I don't know whether you recognize this as wrong, or are surprised at the thought of such a thing (which doesn't actually exist like that).

In any case, i've suggested a correction here: http://blog.jenkster.com/2015/12/which-programming-languages...

Re:Which Programming Languages Are Functional? by __david__ on Wednesday December 30, 2015 @01:55PM (#10813580)
$_ isn't really global though:

    perl -e 'for (1,2,3,4) { for (5,6) { print "  $_\n" } print "$_\n" }'
Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @06:02PM (#10814970)
It may look like it is not in loop constructs, but it is. `for` and friends just apply `local` scoping to `$_` internally.
Re:Which Programming Languages Are Functional? by tripa on Wednesday December 30, 2015 @10:38AM (#10812436)
I recognize this as wrong, and am surprised by how he could have gotten that idea. Good job with the correction.
Re:Which Programming Languages Are Functional? by jerf on Wednesday December 30, 2015 @10:45AM (#10812477)
Well, try to explain $_ in a short sentence without being wrong. "It's the perl equivalent of the pronoun 'it'." OK, now try explaining it in proper engineering terms that describes exactly what it is, how to use it, and in some sense, how to implement it, in about that many words.

At the very least, I suspect honesty will compel you to admit that either A: that took you longer than you expected or B: you left out a lot of corner cases, especially when modifying $_ does or does not change the thing it does or does not reference, and how it interacts with local, and, and, and....

Re:Which Programming Languages Are Functional? by dozzie on Wednesday December 30, 2015 @10:57AM (#10812529)
Here you go: default variable to pass string argument to many built-in functions and operators, which typically return their result in the same variable.

Yes, it took a little longer. No, it didn't took that much longer to leave out plainly invalid and misleading description. No, I didn't need to put corner cases there, exactly the same way as you wouldn't specify corner cases for Yacc to describe what it does.

Re:Which Programming Languages Are Functional? by tripa on Friday January 01, 2016 @07:08PM (#10824255)
Ok. $_ isn't trivial to understand, let alone explain. But nobody's claiming that. Well not me at least.

What irked me is that's just about all the author's got to say about Perl in the article. Other languages inherited this "feature" (Ruby anyone?) or equivalents, but no mention of that. Why even mention Perl if he's got nothing (solid) to say about it?

Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @10:54AM (#10812515)
I did in the linked comment in roughly the same space as the original description. The only thing that could maybe have been included is the scope restriction afforded by local, but that's a feature available to all variables and not necessary to mention.

I also did not take longer than expected, nor did i leave out any corner cases that affect day-to-day work and am not aware of many of them existing in the first palce.

Re:Which Programming Languages Are Functional? by typon on Wednesday December 30, 2015 @10:23AM (#10812375)
Oh lord... I envy your innocence. This isn't even the whole story. There are like ten more of these (good luck remember which one does what). They are all something like $., $/, $" etc. and they're all global.
Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @10:31AM (#10812411)
They're all documented and explained in https://metacpan.org/pod/distribution/perl/pod/perlvar.pod and all have english names available and all but a small hand-full only exist for backwards compatibility at this point.
Re:Which Programming Languages Are Functional? by typon on Wednesday December 30, 2015 @10:34AM (#10812423)
I would never use them in my code. The problem is when I'm debugging 5 year old code it becomes such a headache.
Re:Which Programming Languages Are Functional? by arethuza on Wednesday December 30, 2015 @10:41AM (#10812450)
I thought that the point of $_ was that you don't reference it directly in your code?
Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @10:44AM (#10812472)
It is!

But sometimes you end up using it to make code more reliable, as in:

    do_thing($_) for @things;
Where $_ is passed in as an argument, as opposed to:

    do_thing for @things;
Where $_ is (due to its global nature) set by `for`, and read in sub do_thing { ... }
Re:Which Programming Languages Are Functional? by Mithaldu on Wednesday December 30, 2015 @10:42AM (#10812456)
> I would never use them in my code.

Most people don't. The only one that is used a lot is @_. :)

As for debugging old code, that's why i pointed out perlvar. It's never far and it's always easy to look up what a specific var does.

Re:Which Programming Languages Are Functional? by typon on Wednesday December 30, 2015 @11:03AM (#10812566)
Well I end up doing that of course, but I'm just complaining that it gets really annoying really fast seeing all these dollar signs peppered in the code, making it super unreadable.