8 ms·
I'm not sure. Maybe it does look fancy compared to perl 5 but is it really that compared to modern languages? If I look at the examples on this page https://en
by bhaak 11y ago
I'm not sure. Maybe it does look fancy compared to perl 5 but is it really that compared to modern languages?
If I look at the examples on this page https://en.wikibooks.org/wiki/Perl_6_Programming/Junctions https://en.wikibooks.org/wiki/Perl_6_Programming/Junctions
it doesn't seem to be.
For example "if ($x == 2 || $x == 4 || $x == 5 || $x == "hello"
|| $x == 42 || $x == 3.14)" can be done in Perl6 as "if ($x == (2|4|5|"hello"|42|3.14))" but in Ruby this would equally easy been done with "if [2,4,5,"hello",42,3.14].include?(x)".
Ruby also has set operations defined on its container classes (e.g. [1,2,3]&[2,3,4] => [2,3]) and any?, all?, none? methods that take blocks.
Perl6 looks like a language that might have been great if it had been released in the 90s but nowadays I wonder if it will gain enough traction from non perl programmers.
- hahainternet 11y ago> but in Ruby this would equally easy been done with "if [2,4,5,"hello",42,3.14].include?(x)". But that isn't the same is it. That's only a related feature because Ruby doesn't have first class Junctions. > I wonder if it will gain enough traction from non perl programmers. These days people have been taught to be arrogant. To assume their language is the best. This is what makes things a tough challenge.
- bhaak 11y ago>> but in Ruby this would equally easy been done with "if [2,4,5,"hello",42,3.14].include?(x)". > But that isn't the same is it. That's only a related feature because Ruby doesn't have first class Junctions. At least in this case, the only difference I see is that this is a language feature in Perl6 and a method from the standard lib in Ruby. And it has to be a language feature in Perl 6 as there you don't have open classes as in Ruby or an equivalent feature for overriding operators or adding functionality to standard lib types.
- hahainternet 11y ago> And it has to be a language feature in Perl 6 as there you don't have open classes as in Ruby or an equivalent feature for overriding operators or adding functionality to standard lib types. I'm not sure what makes you think this. I'm not very familiar with Ruby's internals but Perl 6's MOP certainly supports modifying classes, you can add your own operators etc. Could you provide a more explicit example?
- deleted 11y ago[deleted]
- raiph 11y agoa includes b is trivial in any language and is not a justification for Junctions. Please take another open minded look at the examples others have posted here. Post again if you still don't see what they do that's useful and not trivially doable in any language and I'll have a go at explaining them to you.
- bhaak 11y agoOf course the include operation on a set is a trivial operation but that's been the first example for junction I found when googling. It's not a problem with an open mind but rather with understanding what data type a junction is trying to be. If I go to the official specification (my fault, should have gone there from the beginning), I read the definition "A junction is a superposition of data values pretending to be a single data value". But that's a fuzzy definition and it is absolutely not clear what that's supposed to mean. The given examples don't help either. Especially when I look at this discussion and see that several people including you are not sure what "all(@ar1) < any(@ar2)" is supposed to mean. That's not a complicated expression and that's already puzzling to people who know the language? The autothreading feature is cool but also nothing too special. Every pure functional language can implement map/reduce/filter in parallel. tl;dr I don't see what junctions bring to the table that's not expressed easier to understand with set operations or map/reduce/filter.
- raiph 11y ago> what "all(@ar1) < any(@ar2)" is supposed to mean. That's not a complicated expression and that's already puzzling to people who know the language? Afaik junctions are simple and have an obvious intuitive read. But I'm not yet 100% confident of expressing that view without qualification. Given Estragon's "no idea" comment I allowed that my intuitive read might be bogus. In fact the intuitive read is correct: if all(ar1) < any(ar2) # if all in ar1 are numerically less than any in ar2 > The autothreading feature is cool To be clear, the whole point of junctions is autothreading; passing junctions to any code that does not have an overload for junctional arguments is automatically (semantically, at least) data parallelized and that's the win that makes them significant. > Every pure functional language can implement map/reduce/filter in parallel. I note "can implement" and your choice of just three functions. Which languages provide a mechanism equivalent to junctions and their most significant use-case -- automatically generating data parallelized versions of any sequential functionally pure code? > I don't see what junctions bring to the table that's not expressed easier to understand with set operations or map/reduce/filter. What equivalent of "all(ar1) < any(ar2)" -- all ar1 less than any ar2 -- is "expressed easier to understand"?
- awwaiid 11y agoI think a good idea would be to look through Ruby Enumerable (which is most excellent!) and see how things correspond to P6, or where they are missing. Like in this case you can do: [2,3,5,"hello",42,3.14].any ~~ $x But that's not really the same, since it converts the entire array to a junction and then does the match. Really this is a lot closer: [2,3,5,"hello",42,3.14].first($x):p Which returns the first match (as a pair (hence the :p adverb) so it won't be false even if it is a false value)... but it isn't right either because it gets mad at comparing numbers and strings (I'm asking about this in #perl6 now on irc). Ultimately: it would be trivial to port ALL Enumerable methods to Perl 6 List (or some role to cover all iterables or such), and do it in a library even if it wasn't in the core standard lib. I'm always fascinated by how much of Ruby (and lots of other languages) are more about their Standard Lib than about their language. In the Ruby world, lots of people end up with ActiveSupport, which sprinkles in all sorts of cool stuff into the standard lib -- and I've ever seen a native 'for' loop rather than a .each in pragmatic Ruby.