Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • Wrong Rosettacode link, it should point to http://rosettacode.org/wiki/Pascal's_triangle#Perl_6 [rosettacode.org].
  • by soulchild (8747) on 2010.08.27 3:23 (#72352)
    You seriously consider this "idiomatic" solution more elegant? If that is what idiomatic Perl 6 looks like, it will never take off ... Sorry, but that is as unreadable as it could possibly get and just fuels the unstoppable line-noise argument even more. Good languages _can_ be descriptive, self-documenting and to a degree self-explanatory. I always thought that one of Perl's philosophies was to be more like a human language. Guess I was wrong, it's math after all ...
    • Re:Fugly! by pmichaud (Score:2) 2010.08.27 7:24
  • by pstuifzand (8790) on 2010.08.27 6:20 (#72354)
    It's nice to see that Perl6 will be on par with Haskell for these kinds of examples. This Haskell example is from Rosseta code page (but rewritten for similarity).

    pascal = iterate (\row -> zipWith (+) ([0]++row) (row++[0])) [1]

    The essential complexity of this example is the same. Only it contains more words than operators.

  • my @pascal := do [1], -> @p { [0, @p Z+ @p, 0] } ... *;
    ...

    (The extra do required because of a shortcoming in Rakudo.)

    FWIW, I think parentheses will work here also.

    my @pascal := ([1], -> @p { [0, @p Z+ @p, 0] } ... *);

    Pm

  • by Ovid (2709) on 2010.08.30 2:47 (#72359) Homepage Journal

    I really like this. I liked it even more as I worked through all of the examples to better understand them. One thing I would change:

    say $_.perl for @pascal;

    The output is much clearer that way (at least to me). I actually tried to get it a touch more "triangly":

    my @pascal := do [1], -> @p { [0,@p Z+ @p,0] } ... *;
    say ' ' x 2 * (10 - $_.elems), $_.perl for @pascal[^10];

    But wound up with this:

                      [1]
                    [1, 1]
                  [1, 2, 1]
                [1, 3, 3, 1]
              [1, 4, 6, 4, 1]
            [1, 5, 10, 10, 5, 1]
          [1, 6, 15, 20, 15, 6, 1]
        [1, 7, 21, 35, 35, 21, 7, 1]
      [1, 8, 28, 56, 70, 56, 28, 8, 1]
    [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

    Ah well :)