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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Wrong Rosettacode link, it should point to http://rosettacode.org/wiki/Pascal's_triangle#Perl_6 [rosettacode.org].
  • 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 ...
    • 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 ...

      In some sense, I think it's entirely appropriate that solving a problem from (arguably) a mathematical domain ends up with a solution that looks mathematical. Just because this particular problem ends up with a mathematical-looking answer in Perl 6 doesn't mean that all Perl 6 programs will look like mathematics. Answers to problems in other domains will tend to look like the

  • 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

    • Aye. I considered both forms, and went with the do form.

      When binding has list precedence, neither parentheses nor the do will be needed.

  • 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]
               

    • my $n = 10;
      my @pascal := do [1], -> @p { [0,@p Z+ @p,0] } ... *;
      my $m = @pascal[$n - 1].perl.chars;
      say (my $r = $_.perl).fmt("%{($m + $r.chars) div 2}s") for @pascal[^$n];

      Produces this:

                       [1]
                      [1, 1]
                    [1, 2, 1]