0:00

Over the last two weeks you've seen several ways to express functions, to

compose them, to use them in your program. In this session we are going to review the

language constructs that you have seen so far in one syntax summary that you can use

as a reference. In fact there's a standard way to describe

elements like that with grammar and one of the most commonly used notations for such

a grammar is called extended backwards now form.

So in that standard backwards now form a vertical bar would denote an alternative.

Brackets would denote an optional element zero or one occurrences of an element and

braces would denote a repartition zero or more occurrences of an element.

Let's start with types. We've seen two form of types, so we would

have a bar here. A type in our language is a simple type or

a function type. A simple type so far is just an

identifier, and the function type is always contains an arrow.

And on the left hand side of this arrow could be either a simple type, or a set of

types in parenthesis. Another way to put it would be the

following. A type can be either a numeric type.

So we've seen int and double. But there's also bite, short, character,

long, and float. That's the same as the primitive types in

Java. Or it could be the boolean types that has

values true and false as we have seen. Or it could be the string type.

Or it could be a function type such as int to int or a pair of ints to ints.

Later, we're going to see more form of types than these.

Let's look at expressions. So here you see the complete syntax of

expressions. I'm not going to go into detail but it's

there for you as reference. Let's look instead at categories of

expressions and some examples. So an expressions can be an identifier,

such as x or, IsGoodEnough, or it can be a literal, such as zero or 1.0, or "abc".

Or it can be a function application, such as square root of x.

Or an operator application, such as y + x. Or a selection.

We've seen math.abs that selected the abs method from the math module.

Or a conditional expression, such as if (x < zero) - x else x.

Or it can be a block, like the one that you see here in braces, or finally an

anonymous function such as x arrow x plus one.

The last syntactic category are definitions.

We have seen so far function definitions and value definitions.

Function definitions start with a def, followed by an identifier, followed by

zero or more parameter lists, followed by an optional result type, followed by an

equal sign and finally an expression. Value definitions are simpler, they

consists of val, then an ident, then an optional type, then equals, then

expressions. Parameters can be by name, or by value.

So a parameter is an identifier, then a colon and then comes a type, but you can

prefix the type with the arrow, and you've seen that means a call by name parameter.

3:38

So that's all the syntax that we've seen so far, that we've needed so far in our

examples. We will add more elements as we need them

over the coming weeks. So those are all the language elements

that we have used so far. You will notice that they're all related

to functions and that we have spoken very, very little about data.

You had only some primitive data types like doubles or ints or booleans.

This is going to change next week where we are going to study new ways to indroduce

data that are centered around classes and