From Pure to Mutable

So far we have been dealing with Pure languages, no modification possible.

We will use a program to count, in Java:

Untitled

Where using classes is important, as we can create multiple independent instances of this.

We want to recreate this functionality in Paret, but adding the least functionality possible. Hence, we will avoid using classes, as adding this will make our language too complex (we’ll do that later in the course).

We can implement this by using functions. Functions encapsulate State:

Untitled

Problems with our function “objects”:

Going back to the JavaScript snippet:

Untitled

We can use it like:

Untitled

Can we mimic classes, i.e., create independent classes?

Untitled

Yes we can!

Now that we have the desired code written in JavaScript, let’s convert it into Paret!