in reply to Perl 6 Junctions and Postgres SQL

How so?

Replies are listed 'Best First'.
Re^2: Perl 6 Junctions and Postgres SQL
by mugwumpjism (Hermit) on Dec 22, 2007 at 00:54 UTC

    Ok, piece by piece:

    (select y from generate_series(18,23) y) (select s from generate_series(1,20) s)

    Is similar to, respectively:

    (18..23) (1..20)

    Then this query:

    select s from (1..20) where s = any( 18..23 )

    Is similar in meaning to this:

    for my $s (1..20) { if ($s == any(18..23) ) { print $s; } }

    Or, more close in expression to the SQL, the Perl 6:

    [1..20].grep:{ $_ == any(18..23) }.say

    Hmm, wouldn't it be useful to have a LINQ to Hyper-operator/Junction cheat-sheet...

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
      Toying with perl 5.10:
      perl -E 'for(1..20) { when([18..23]) { say } }'
      :-)

      I'm slightly puzzled that I couldn't write when(18..23), though.

        I'm slightly puzzled that I couldn't write when(18..23), though.
        If you're used to Perl 6 switches, you're going to notice breakages in Perl 5 switches because Perl 5 doesn't natively support types such as Range or Junction, nor does it automatically promote a list in scalar context to an array. Instead, it tends to throw away information.

        And arguably the Perl 5 behavior with an array is wrong (or would be wrong in Perl 6); in P6 arrays are matched as a whole, and you must use something like any() to match against any element of an array (see the section on Smart Matching in Synopsis 3). Range objects in P6 are matched directly against their endpoints though, so you don't have to convert to a list and then use any(). In essence, P5 smart matching cannot really emulate P6 smart matching because P5 doesn't have the type system to support it transparently.