@@ -10,6 +10,8 @@ Welcome to the Amy project! This semester you will learn how to compile a simple
This document is the specification of Amy. Its purpose is to help you clearly and unambiguously understand what an Amy program means, and to be the Amy language reference, along with the reference compiler. It does not deal with how you will actually implement the compiler; this will be described to you as assignments are released.
**Note**: The language might change along the way, so check this specification before starting each lab, to make sure you have the latest version in mind.
### 1.1 Features of Amy
Let us demonstrate the basic features of Amy through some examples:
...
...
@@ -19,7 +21,7 @@ Let us demonstrate the basic features of Amy through some examples:
```scala
objectFactorial
fnfact(i:Int(32)):Int(32)={
deffact(i:Int(32)):Int(32)={
if(i<2){1}
else{i*fact(i-1)}
}
...
...
@@ -76,7 +78,7 @@ end L
#### 1.1.5 Constructing ADT values
```scala
fnrange(from:Int(32),to:Int(32)):List={
defrange(from:Int(32),to:Int(32)):List={
if(to<from){Nil()}
else{
Cons(from,range(from+1,to))
...
...
@@ -89,7 +91,7 @@ We can create a `List` by calling one of its two constructors like a function, a
#### 1.1.6 Pattern matching
```scala
fnlength(l:List):Int(32)={
deflength(l:List):Int(32)={
lmatch{
caseNil()=>0
caseCons(h,t)=>1+length(t)
...
...
@@ -108,7 +110,7 @@ The `error` keyword takes a string as argument, prints `Error:` and its argument
Notice that in the second case, we don’t really care what the tail of the list is. Therefore, we use a wildcard pattern (`_`), which matches any value without binding it to a name.