# Re: The game of life

```On Thu, May 28, 2009 at 5:58 PM, John M. Dlugosz
<2nb81l...@sneakemail.com> wrote:
> I came upon a copy of "A Programming Language" in a similar way.  My Dad
> passed it on from a co-worker.  I don't recall how young I was, but it was a
> very interesting read.  Perhaps this attracts youngsters because of the
> strange letters?```
```
That was a big part of it... I'm glad Mark posted the APL snippet
because it got me to finally read up on the language that's been at
the back of my mind. Plus it's useful for p6 language discussion. APL
(and a successor, J) may still have a few tricks to lend.

One APL feature already supported in p6 is the ability to use
operations on vectors of any dimension, even mixing dimensions.
Hyperoperators let us add two arrays easily, or multiply every element
in one array by a scalar, etc. (I haven't yet figured out
multi-dimensional arrays in Rakudo, are they implemented?)

Though I'm not quite sure that S03 covers some of the different-dimension cases.
my @table=
(1,2,3;
4,5,6); # is this the syntax to create 2d array?
my @row=4,0,1;
my @column=
(2;
-1);

my @added_to_each_row = @row <<+>> @table; # is that (4,3,4 ; 8,5,7) ?
my @col_products = @column <<*>> @table; # is that (2,4,6 ; -4,-5,-6) ?

Which also brings up a small point in S09, is it OK to declare an
array with 0 elements in some directions, eg
my @month_calendar[7;5]; # seven days across, five weeks down
my @week[7;0];# one line across in the calendar. Same as @week[7]
my @Sundays[0;5]; # one line down. Different from @Sundays[5]

Another concept mentioned in the APL wiki page are reduction operators
that reduce the dimensionality of an array by one. For a
one-dimensional array, APLs and Perl6's reductions are the same- [+]
1,2,3 = 6 - run the op through all values, return a single value.

But in APL, you can reduce the addition operator on a 2-dimensional
array either by columns or by rows and get a 1-dimensional column or
row of sums. Or take a 3D array and get a rectangle of sums.
Presumably APL also lets you reduce a multi-dimensional vector down to
a grand total as well. I'm not very far in the p6 synopsis so I don't
know if that's a built-in possibility, but I didn't see it mentioned
in S03.

Less general is an APL operator (actually different ops for different
directions, IMO should be a single operator) that rotates vectors, eg
"rotate left 2" transforms 1,2,3,4,5 => 3,4,5,1,2- and it also works
for arrays of any dimension. For some reason APL has 2 (or more?)
operators for rotating vectors, depending on which direction, eg
left-right vs up-down. I'd expect that a rotate operator would take a
vector saying the direction & magnitude of the rotation. Maybe APL
does do that, maybe perl6 does too, I'm not very far in the synopses.

- install fonts as needed, they're also referenced from there. Then
move on to the links posted earlier about the game of life, they do a
great job of explaining the one-liners.
http://aplwiki.com/GameOfLife - short version, one generation, more
descriptive variable names
using a loop, makes a string copy of the short version N times and
'eval's that.

The wiki page for J, Iverson's APL successor
(http://en.wikipedia.org/wiki/J_programming_language ) has an
educational quicksort 1-liner:
quicksort=: ((\$:@(<#[) , (=#[) , \$:@(>#[)) ({~ ?...@#)) ^: (1<#)
which I think can be transformed into a more readable perl6 one-liner.
May try it out sometime...

J's wiki has a page of examples that makes me think, if I want to get
started in that language, there's a ton of good examples:
http://www.jsoftware.com/jwiki/Essays - enviable! One of the
programmer virtues... I'd like to see the better perl6 code collected
in a wiki too.
```