### Sample Exam 2011

**19. Jul 2013 19:46**

I tried to solve the tasks to check my skills in COPL.

My solutions are truly not correct but I hope that someone else got other (better) solutions. Just post them, I try to update this post to correct answers.

**Task 1.1**

Code: Alles auswählen

```
Interpreter: Takes the interpreted language and returns a evaluation of the expression
Compiler: Takes Src-Code and returns Object-Code
Preprocessor: Takes code in language A and returns a tranfomated code of A
```

**Task 1.2**

Code: Alles auswählen

```
def subst( expr: Exrp, substId: Symbol, value: Value){
...
case With(id, idExpr, bodyExpr) => {
if(substId == id){
With(id,subst(idExpr,substId,val),bodyExpr)
}else{
With(id,subst(idExpr,substId,val),subst(bodyExpr,substId,val))
}
}
```

**Task 1.3**

With(x, 1, With(f, Fun(y, Add(x,x)), f 2) --> App(Fun(x,App(Fun(f,f2),Fun(y, Add(x, y))), 1 )

**Task 2.1**

a )

It flats a given list. E.g. f(List("a","b",List("c","d"),"e")) --> List("a","b","c","d","e")

b )

No idea how to do it

**Task 2.2**

Use foldr because the constructor of list is right-associative

**Task 3.2**

That Tasks makes me headaches... see here

With static scoping: the result will be 5. Cause g(f(x)) is called with x=2 so g(f(2)) = g(y=4):= y + x. Here x is bound to the value 1 in the upper With-Expression

With dynamic scoping: Well... I

*it is 3.*

**guess****Task 4.1**

Lazy with call-by-value: 5 times

Lazy with call-by-name: 3 times

Eager with memorization: 3 times

**Task 4.2**

The lists elements are the result of the multiplication of 2 with the prior element.

First 6 Elements: [1,2,4,8,16,32]

**Task 4.3**

ys is a list of sums where the operands are the tails of the list itself and the given list

First 6 Elements:[0,1,3,7,15]

**Whole Task 5 is skipped, because its not relevant for the exam**

**Task 6.1**

Environment: Stores the location in the Store

Store: Stores a Value or a location in the store

**Task 6.2**

Scope of a variable: I don't know this by heart

Extend of a variable: As explained here the identifier that points to the value in the environment may be not available, but it is possible that another identifier points to the value.

**Task 6.3**

The result must be 3. The Value 1 is stored in the Store, that will be open increased by 1 and placed back in the store. The last expression in the sequence will open the box (with value 2) and add this with openbox(x) = 1, because it don't have recognition about the changes done in the sequence.

**Task 6.4**

Have to be done

**Whole Task 7 will be skipped, because its not a topic in the exam**

**Task 8.1**

With the usage of tailrec-annotation

Code: Alles auswählen

```
import scala.annotation.tailrec
object CPS extends App {
def cpsRemove[A](a:A,list:List[A]): List[A]={
@tailrec def innerRemove(a:A,list:List[A],currList:List[A]) : List[A] = {
if(list.isEmpty){
currList
}else{
if(a == list.head){
innerRemove(a,list.tail,currList)
}else{
innerRemove(a,list.tail, currList++List(list.head))
}
}
}
innerRemove(a,list,List())
}
}
```

**Task 8.2**

To be done

**Task 9**

Not done

**Task 10**

I guess its out of scope!