News for hackers. Stuff that matters.
Re:Why Would Anyone Use Perl 6? by josteink on Wednesday January 13, 2016 @08:37AM (#10894122)
So basically == is overloaded to also be an operator which means "intersects".

I mean, it's nice that this sort of functionality has nice and concise operators, but I'm coming from a school of thought where overloading the equality operator should not be done lightly :)

Re:Why Would Anyone Use Perl 6? by raiph on Wednesday January 13, 2016 @10:42AM (#10895066)
I'm very much not sure of the following but I'm going to say it anyway and let folk explain how I'm wrong. :)

Each operator and its overloads -- certainly built ins, users are recommended to follow suit -- conceptually maintains its own single high level semantics. Thus, while some langs have a `+` op that does numeric addition or string concat based on operand types, in Perl 6 a `+` will always mean numeric addition (unless a user breaks this convention).

`==` is always numeric value equality.

`==` does what most folk would expect between any pair of values that are a subclass of Any (the root of the type hierarchy for most purposes).

Junction is a direct subclass of Mu (the ultimate root of the type hierarchy), outside the Any hierarchy.

When a scalar operation is applied to one or more Junction values, the relevant operation is "autothreaded" over the superposed values inside the Junctions and returns a new Junction value.

If a Junction is treated as a boolean the Junction collapses to a regular single boolean value.

Re:Why Would Anyone Use Perl 6? by masklinn on Wednesday January 13, 2016 @08:54AM (#10894212)
> So basically == is overloaded to also be an operator which means "intersects".

Junctions seem way more complex than that, first there are 4 different junction contains (any, all, one and none), second they overload 12 comparison operators each and third the other operand doesn't have to be a junction.

So e.g. any(@ar1) == any(@ar2) is an intersection but any(@ar1) == $val is a containment, and I've no idea what all(@ar1) < any(@ar2) would be, I guess it would check that max(ar1) < max(ar2)?

Re:Why Would Anyone Use Perl 6? by hahainternet on Wednesday January 13, 2016 @09:26AM (#10894440)
> I've no idea what all(@ar1) < any(@ar2) would be, I guess it would check that max(ar1) < max(ar2)?

It seems that it just expands the lists using the operator. The output from junctions is quite nice:

    > my @a = <1 2 3 4>;
    > my @b = <2 3>;
    > say all(@a) < any(@b);
    all(any(True, True), any(False, True), any(False, False), any(False, False))
    > say so all(@a) < any(@b);
    False
Re:Why Would Anyone Use Perl 6? by senekerim on Wednesday January 13, 2016 @09:11AM (#10894328)
This looks awful to my (mathematically trained) eyes. What is the rationale behind introducing this language feature?
Re:Why Would Anyone Use Perl 6? by awwaiid on Wednesday January 13, 2016 @11:10AM (#10895304)
* Seems kinda cool

* Makes $x == 5|6 look kinda cool

* $string ~~ /<first>/ & /<second>/ & /<third>/ # matches all three regexes. huh. kinda cool

* (5|6).foo maybe we can do that in cpu-parallel (it doesn't now)? That might be kinda cool

* sub is-prime($n where $n > 2) { $n % none(2..sqrt($n)) == 0 } # Logical O(1) prime test if only you had that quantum-coprocessor? That... would be kinda cool

* ... you might notice a pattern to the motivation for this feature :)

Re:Why Would Anyone Use Perl 6? by masklinn on Wednesday January 13, 2016 @09:15AM (#10894353)
I really couldn't tell you. I guess "it's perl, we can"?
Re:Why Would Anyone Use Perl 6? by raiph on Wednesday January 13, 2016 @10:55AM (#10895188)
One that I recall that I'm hoping still applies is having a syntactically and conceptually lightweight way to express semantically parallel computation logic. Given the code:

  junction1 = val1 | val2 | val3;
  junction2 = val4 & val5;
  if junction1 op junction2 { ... };
the compiler is free to fire off several threads, or set up a lower level SIMD parallel process, with short-circuiting, to compute the conditional result.
Re:Why Would Anyone Use Perl 6? by hahainternet on Wednesday January 13, 2016 @09:27AM (#10894449)
Could you explain why you think this is awful? Perl 6 has proper sets, bags and the appropriate operators for 'normal' set operations too.
Re:Why Would Anyone Use Perl 6? by Estragon on Wednesday January 13, 2016 @09:21AM (#10894398)

  no idea what all(@ar1) < any(@ar2) would be
Subset?
Re:Why Would Anyone Use Perl 6? by raiph on Wednesday January 13, 2016 @11:02AM (#10895247)
I think that means something like all the individual values in the @ar1 list of values are less than at least one of the individual values in @ar2.
Re:Why Would Anyone Use Perl 6? by awwaiid on Wednesday January 13, 2016 @11:19AM (#10895376)
Yes exactly. To take the code snippet a cousin-reply mentioned one step further, swaping @a and @b:

    > my @a = <1 2 3 4>;
    [1 2 3 4]
    > my @b = <2 3>;
    [2 3]
    > say so all(@a) < any(@b);
    False
    > say so all(@b) < any(@a);
    True
Re:Why Would Anyone Use Perl 6? by mst on Wednesday January 13, 2016 @10:57AM (#10895206)
If operator overloading in perl6 was like operator overloading in most languages, that would be a very valid school of thought.

Thing is, operators in perl6 are basically multimethods under the hood, as is pretty much everything else - so it's a much saner, more predictable thing than, say, the bag of razorblades that is perl5 overloading (which I've used to good effect, but, still, razorblades ;).