0%

Coursera-Programming Language Week2

This is a blog for reflection on Programming Language part 1 at coursera produced by UW(Universit Washington). The design for this course is to help developer better understand what is the programming language and how does functional programming differs from object-oriented programming. And in the first part, we will use a language called SML(Standard ML).

For the first two weeks, the course mainly covers the basic of SML(synatx, list...). I have to say at the first look, this language is quite like Javascript mix with rust. While, if we dive into this language, we can find some interesting points. Like the variable is immutable, such immutable is not like mut in rust. It just doesn't have the concept of assignment on value. Instead, it introduces another concept called shadowing and binding. In this case, binding works for binding a specific value to a variable and shadowing is for re-binding a value on a existed variable(such process is quite like assignment). And due to this feature, the = can perform the role of binding value(if the right is a value) and the role of judging value equality(if the right is variable). And this is quite confusing when I first time touched this language.

In addition, this week, it also introduces some basic thinking in the functional programming and let ... in ... done syntax. The let ... in ... done may look familiar if you have tried pascal. Basically, it allow you to introduce some local variable and function into the current scope. The most important thing this week, is the recursive way of solving problem. This might be the most trick part, since recursion might be abstract in some cases. And in such a language that does not have any loop feature(so far from what I know), it forces you to rethink all the patterns you have built in the past coding life. Like, we all know we can step through an array using recursion by passing its sub-array. Such operation seems to go against the OOP(Object-oriented programming) thinking.

On more thing, is the list operations. In the first week, it introduces operations:

  • hd that will return the first element in the list.
  • tl it will return a new list with every element but the first
  • e1::a1 that can add one element e1 to the head of a1
  • a1@a2 that can append a2 to the tail of a1. Note: we can use this operation to achieve append in python. If we want to append e1 to the tail of a1, we can use a1@[e1].

At the end, about the first assignment, it is not so hard once we can the sense of recursion. Here is the link for the first assignment.