YouSub
Untitled

en English

Untitled English subtitles

0 downloads · 1,452 lines · added Sep 1, 2015

Report a problem
What's wrong?
Advertisement

English transcript

RUSSELL HARMON: My name's Russ Harmon.
I'm a full-time software engineer here at Google
like, I think, most of you as well.
And thank you for coming.
This is Morten Kromberg.
He's the CTO of Dyalog, which is an implementation
of a programming language.
And let's get started.
MORTEN KROMBERG: OK.
Well, thank you for coming.
And thank you, Russ, for believing that they would come,
and inviting me to come and give this talk about something which
is definitely not mainstream.
In fact, Dyalog is an implementation
of an ancient programming language called APL, which
I think is now 52 years old.
And I have been using it for about 36 of those years.
I remember, I did a similar talk previously
where a guy came up to me afterwards.
And he said, you've been using the same programming
language for 35 years, and you're still happy?
As if that was completely impossible and unthinkable.
So, I started off as a young man should.
I spent the money I'd made selling newspapers,
or delivering newspapers, and buying this do-it-yourself kit.
I soldered all those integrated circuits onto a board.
And I got this thing to work, programed it in Z80 Bytecode.
I'd never soldered anything before,
so it would only run for about three
or four minutes before crashing.
Then things got a little bit better.
I found Commodore started making these really nice machines.
So I learned BASIC.
And so things we're going fairly normally
until a friend of the family one day
brought me down to the place where he was working,
and he said, we're using this thing called APL.
And he typed this expression here, 1 2 3 + 4 5 6,
and the computer spat out three numbers.
And I thought well, that's the end of that.
And so I've been using this technology now
for 35 years-ish.
I started out in 1979 a time-- well, Timesharing in those days
was when you were sharing a computer, not
a condo in Mexico.
The customers were paying about $1
per CPU second on this machine, which
was around the other side of the world in Toronto.
I was using it from Oslo, Norway.
And $1 per 1,000 characters of output
that they received over the network.
It's not as bad as it sounds, because it actually
took several seconds for that to print out.
So you were still getting some value for money.
And now if we get to the recent end of my experience with APL,
the last couple of things we've done
is we've put out a Raspberry Pi version, which
I think is significantly more powerful computer than the 360.
Maybe doesn't have the same I/O capacity,
but certainly things have changed a bit in this time.
And last week, we also released a version for the Mac.
I see there are a few Macs here.
So you can now get this, and play with it on your Macs.
So for me, it's been a love affair
lasting a very long time.
But of course not everybody was keen
on APL when they saw it for the first time.
This is perhaps one.
If you search on the internet, there's
still a lot of very old stuff you'll find about APL.
This is perhaps one of the most famous statements about APL.
If you actually read up on it, you
will find that Dijkstra wasn't that uniformly negative on APL.
And anyway, I think there was a proposal that
was arrogance should be measured on a scale called the Dijkstra
scale.
But anyway, as you grow up, and you
learn to receive feedback from people,
you learn how to read what people say.
And there's part of this that I really like.
You may be surprised, I like this last line here.
I think being a coding bum is actually something
that's a positive statement.
You want to conserve your energy when you're writing code.
Now the history of APL is very long,
and the language is quite different from
other programming languages.
And I think it's important to spend just a little bit of time
looking at the man who invented it, who is passed away.
I guess one of the few programming language creators,
there's still only a handful, who
lived-- he lived until he was 84 and passed away.
It's not because he passed away young.
So he was originally on a farm, and he
went to a one-room school.
He did nine years of schooling, and went back to the farm.
And that could have been the end of it,
if it hadn't been for being drafted by the army.
So, whatever you think of the army, at least in this case,
turned out to be a very good thing that they drafted Ken.
And he almost finished high school in the service.
And he found that he really enjoyed
mathematics and teaching it to his fellow soldiers.
And they told him that if he didn't go back to university
after the war, they were going to come and beat him up.
So he had to do that.
So he embarked on an academic career, which became
quite an interesting one.
He did doctoral work at Harvard with Aiken and Leontief,
who later won the Nobel Prize in economics
for his input-output matrices.
Which, I think, also recognizes a very early precursor
of some of the algorithms in Google
page ranking, from what I was able to read yesterday
when I was researching that.
But he taught at Harvard.
He was teaching mathematics after doing this work.
And he was really getting frustrated
with what he felt was the inadequacy
of mathematical notation.
And he developed his own notation,
wrote a book about it in 1962.
But the people at Harvard said, well, all you've done
is publish that little book, and they didn't grant him tenure.
And he moved off to IBM to work with people there,
who then, after APL had been used to teach mathematics
and matrix algebra for some years,
implemented the first interpreter for the language.
So the language was initially designed as a communication
tool for humans, and used in that way on blackboards
for some years before the first interpreter was created.
And of course for that little book,
Iverson did later receive the Turing award
for his pioneering work in education,
in Timesharing, and so on.
So, here's what was really winding Ken up,
especially when he was doing the work on mathematics.
He found that mathematics had all these strange forms.
There was a very wide variety of syntactical forms.
There were very strange and inconsistent
precedence rules-- what order you do the suffixes, and so on.
And particularly when he was working with matrices,
it was pretty frustrating.
And so he came up with this language,
which has a very small amount of different syntaxes.
But rather than look at the PowerPoint,
I'm going to do some live coding.
Most of the interesting part of this presentation
will hopefully be the live coding.
So those of you who can't read this,
it may be worth coming over here.
Because I think at least half of the time
is going to be me typing expressions.
Is that wrapping?
We had a bit of fun with the resolution here.
Am I on?
I'm in now.
OK.
So, the first syntax you need is to be able to create a matrix,
arrays are fundamental to the language.
And just by juxtaposing things, you create lists.
So here we have a bunch of numbers, three scalars,
and a vector.
And you can see the structure.
The system, if you don't assign it to a variable,
it just outputs the result of whatever expression
you've typed.
You'll see me use this lamp symbol quite a lot.
This is the lamp, it illuminates code.
There's a lot of that kind of fun in the choice of symbols
in APL.
So, this is an array of two, we call them character vectors;
you might call them strings.
Arrays can be named.
And of course you can assign another name to something.
And then we'll make a change to b here,
and this is just to demonstrate that all the arrays in APL
are value types.
These are not reference arrays.
But they are immutable, and they are all value types.
So here is an array called FormProps.
And this is really just to show you, very briefly,
that we can do other things in calculations.
We can create a form with those properties.
And then you have an object model
where the properties can be arrays,
and I can set the caption.
And I'm creating a list box inside,
which I will set to have a background color.
And I'm just going to do that so I can maintain
a list of the different syntaxes as we go along here,
since we're not looking at the PowerPoint.
So after the array, the next form
we have is a function followed by an array.
So, for example, iota 6, the index generator
generates an array of the numbers up to 6.
This little thing pointing down with a little step
at the bottom is floor.
The font size is just a little bit too big.
Is it OK if I bring the font size down just a little bit?
Yes, we have lost a bit of real estate here.
OK, so itemwise map is implicit for all
of what we call scalar functions, which
is about half-- at least half of the functions.
So if you have an array, it just applies the function
to every element of the array without you
having to say, map, or for each, or anything like that.
So the exclamation mark standing before an array is factorial.
And then we'll move on to the next syntax.
There's only six or seven of these.
The next one is a function with an array on both sides.
We call that a dyadic, or infix, function.
The first one we would call a monadic function.
Unfortunately, we started using that terminology
before monads were invented in functional programming.
And it's a bit hard.
But I'm trying to use prefix and infix here,
to make it a little bit more palatable.
So, the thing that would have been ceiling,
if you give it two arguments, it takes the largest
of the two arguments.
If you have the exclamation mark with something on both sides,
it's related to the factorial.
It's the binomial, or the gamma, function.
If they're a floating point, we have division,
and so on and so forth.
And of course, not everything works.
We have errors.
And the same if you try and divide a number by a character.
That doesn't work.
But here is this expression that made me fall in love with APL.
Two arrays, one function in the middle,
and it just maps without you having to say anything.
And it applies in the same way to virtually
all of these functions, and also any functions
that you might write yourself, typically will just apply.
Now, if there is not the same number on both sides,
you get what we call a length error.
But if there's exactly one number on the one side
and an array on the other, we do something
called scalar extension, and the single number
is applied to all of the items.
So far, we've only used lists.
Here is a matrix.
So this is the 2 by 4 reshape of iota 12.
So that gives us-- iota 8 would have been enough.
I think I had a different example in mind when
I started writing that line.
And I can do matrix plus matrix, any rank.
It all works exactly the same way.
There's no different rules to learn as the rank increases.
Writing rank in variant code is trivial.
Right.
So I'm just changing the print precision,
because I'm going to take the base 2 logarithm.
So again, for a matrix on the right,
and a single number on the left, we
can take the base 2 logarithm of all of these numbers.
Now, not all of the functions are these scalar functions.
So all the mathematical and logical functions are scalar.
But the iota, if you give it two arguments, is a look-up.
So it returns something with the same shape
as the right argument.
But it's looking each of the items up in the left.
So it's still array-oriented, but it's not doing
things a scalar at a time.
Not everything is a scalar function.
And then we have, again, slightly different terminology
in APL.
We distinguish between what we call functions and operators.
An operator is something which typically takes
a function as its operand.
And the syntax there is you have a function preceding
an operator.
For example, plus reduce, the operator is on the right,
and it's acting on the plus.
Again, I can name functions the same way I can name variables.
So that gives me a function that does
the plus reduction of an array.
So plus reduce is the same as putting the plus function
in between all the items of the arrays.
For some of you who are doing functional programming,
these concepts will be familiar.
And they mostly came out of APL originally.
A lot of the terminology was invented back
in the late '50s and '60s.
And all scalar functions apply in the same way.
So anything that takes two arguments,
you can do a reduction, and it's going to just do the work.
There's also, if you turn the slash the other way,
you get a scan, where it takes a prefix of a vector
with one item, then two items, three items, four items,
and does the reduction.
So we have the accumulating sum if you use it with plus.
And then the reduction also can take
a left argument, which is the window
size that you want to use.
So you can say, I'd like to do the plus reduction of length
three vectors.
If we do a catenate reduction with a length three,
you can see that just catenates the items together and doesn't
do an operation on them.
And you can see the windows that were processed one by one.
And then finally, we have the function, operator function.
A dyadic operator that works on two functions,
where the one that you will all be familiar with
is the vector product.
So plus dot times inner product.
So plus dot times is equivalent to the plus reduction
of the map of times, which is how you do a vector product,
of course.
But in APL that's a completely general construct,
so it's not just plus and times.
In many tools like MATLAB or R, you
will have this thing extracted and presented
as a matrix product, or vector product, a named function.
But in APL-- this is just restating it the same way.
In APL, it's completely general.
So you could do an or dot equals, which says,
are any of the items equals?
So it maps the equals, and then it does an or reduction.
OK?
But that's nearly all the syntax there is.
The only thing you need to remember when you're
trying to parse the syntax is that there
are no precedence rules.
Iverson was wound up about all the
different-- when you do sine squared of x, what order are
the operations done?
So he picked this one, which he felt
was perhaps most representative of the general precedence.
Or this one was nice and easy, anyway.
And he said the argument to the function
is the result of executing everything that's on the right.
So this is the factorial of iota six.
So there are no precedence rules.
You just apply the function to the result of computing
what's on the right.
And if it's a dyadic function, then it essentially works
in the same way, but the left arguments are also included.
So, if you were coming from another programming language,
and you looked at something like this,
you might assume that it's going to do-- that's 10 divided by 5,
minus 1.
But in APL, of course, it's 10, divided by 5 minus 1.
And it doesn't give you the result you were thinking of.
So remember that as you read the rest of this, if you can.
And the final piece of syntax is an array, the square bracket
indexing, which you would be familiar with from most
languages.
The thing that's slightly different about APL
is that you can index with an array.
So the indices can be arrays.
I think you do see that in some other languages.
So the shape of the result has the same shape
as the index array, rather than the data that's being indexed.
Of course, once functional programming
became better understood-- most of APL
predates really an understanding of what
functional programming was.
So in 1984, it was decided that there
should be a function, comprised by over-striking the two
square brackets, the squad indexing,
so that you could do indexing in a functional style.
OK.
So if this has whetted your appetite at all,
there is a website called TryAPL.org where you
can type your APL expressions.
And there's an APL keyboard that pops up if you need it.
And there's a primer page, where you can hover over each one.
I mean, this list here is all that there
is to learn about the language.
It may look a bit intimidating with the squiggles,
but there's not that much to learn.
You can hover over these in TryAPL,
and you can see the definition of each one.
And in the Windows product, and on the Mac,
we have this language bar where you can hover over the symbols,
and you can get the definitions.
We run a programming competition for students each year.
And we had the winner one year say, he would read the problem
description, and then he would just hover with the mouse
slowly from left to right until he
saw how to solve the problem.
And that was all the documentation he needed.
So if your brain clicks when you see this array notation,
there's these six rules, and there's 40 functions,
and off you go.
Of course, there's more to building applications
than that.
So, briefly back to PowerPoint, unfortunately.
So, we've looked at that.
So just to recap the fundamentals.
There's only one data type in APL, the immutable array.
There's a little star there that we'll get to
at the bottom of the slide.
Each item is either a number, or a character, or another array.
For example, a single number is a zero-dimensional array,
but it's still considered an array.
It's not different type.
There isn't different syntax to deal with it.
For most primitive functions, map is implicit.
The functions are either prefix or infix,
but the operators are either postfix or infix.
And I don't know how Iverson and his compatriots,
when they were designing the language, came up with that.
But there's something magical about this interplay
between the functions being prefix and the operators
postfix when you're designing a DSL.
So writing an embedded DSL is typically
how a lot of APL application development
is done, with the end user synthesizing
their own functions from these building blocks.
The order of execution we looked at, and here's the little star.
We added-- at least in Dyalog APL,
we added the ability to have objects; so like these forms,
like dot net objects, or other types of external objects.
And of course once you have an item
in an array which is an object, you lose the immutability.
Because that thing is a reference type.
And we're not going to copy them when we copy the arrays.
So, how did this work then in the end?
He had this list, and he came up with the new notation.
And let's organize them and see.
OK.
So, that's a times b.
That's the e to the power x, no left argument, and the power
function means e to the power.
x divided by y.
The base b logarithm of a.
Notice the symbol is a log seen edgewise, at the same time
as it's clearly related to this one, right?
So there's a lot of that kind of mnemonic stuff
to help you learn the language.
The nth root is a to the power reciprocal of n.
Matrix multiplication is like vector multiplication.
If you have two matrices, it just
does the vector product on the columns on the one side,
and the row on the other.
fgx is f g x.
The third trigonometric function squared.
Sigmas and pis are easily expressed
using plus reduce something times iota something.
And OK, there isn't going to be room to the right of this one.
But it still maps.
I mean, if you are accustomed to mathematical notation,
the translation of this into that
is not a very difficult thing.
And once you have experience with the language,
although it clearly executes from right to left,
we would say you read it from left to right.
So to read that statement there, you would say,
well, it's two times a divided into minus b plus or minus
the square root of b squared minus 4ac,
which is probably how you would read the math as well.
And if you're writing good APL code, at least in my group,
if you can't read it from left to right,
you should probably split the function up.
But that's something that they're different opinions
about that, of course.
So, APL was instrumental in discovering
functional programming.
And John Backus, the inventor, I think, of FORTRAN.
And Backus [INAUDIBLE] in his Turing Award lecture,
recognized Ken's work.
But he did go on to say-- he wasn't quite as
unhappy as Dijkstra, of course.
But he was still unhappy with the fact
that there were the world of expressions and statements,
and there were only these three functional
…

Need subtitles from another video?