## Questions slides/code 1-5 + 'Intro to Scala'

MrGumby
Mausschubser
Beiträge: 65
Registriert: 16. Apr 2013 15:07

### Questions slides/code 1-5 + 'Intro to Scala'

Hi there,

I collected the questions I have for the first few slide sets. Here goes:

1) 'Intro to Scala': trait is described as similar to interfaces in Java, but with state and fields. So it is actually nearer to an abstract class, right?

2) Slide 2, p.27: Typo in case Num(n) => expo instead of expr (as in the code)

3) Code V03: Why is the env in the F1LAEDynamicInterp called SubRep (and not env like in F1LAEStaticInterp), when it is acts exactly like it?

4) Code V05: What is the difference between

Code: Alles auswählen

type Env = (Symbol) => Value
in RCFLAEFunFuns and

Code: Alles auswählen

type Env = scala.collection.Map[Symbol, Value]
in RCFLAEInterpMeta. One is a function, the other a map, but what difference does it make in the evaluation?

5) Could you upload the solution for the non-programming tasks of exercise 10? Especially: is call-by-name the same as call-by-reference and if not what is the difference? And can you tell me whether I understood the three correctly:
- call-by-value is eager evaluation (value is evaluated and then passed)
- call-by-reference is lazy evaluation (as in lecture 10, where we passed the EClosure, instead of the value)
- call-by-need is sth. like super-lazy evaluation, where we'd use the EClosure just once and then stored that result similarly to call-by-value
??

Thank you !

Ragnar
Mausschubser
Beiträge: 63
Registriert: 21. Okt 2009 19:15

### Re: Questions slides/code 1-5 + 'Intro to Scala'

Hi,

1) a single class can implement multiple traits and have no constructors, which is why we explain them as interfaces + state
but in the end, traits are different from both interfaces and abstract classes.

3) updated the code
4) actually map is a subtype of a function: Map[Symbol, Value] <: (Symbol => Value)
so wherever the function type is required you can also use a map.
it makes no difference for the evaluation.

5)
the solution for ex 10 does contain the different evaluations: https://repository.st.informatik.tu-dar ... olution.hs

call by value and call by reference have actually little to do with the other things, they mostly make a difference in a language with mutable variables.
consider:

Code: Alles auswählen

def inc(x: Int) = {
x = x + 1
}
var x = 10
inc(x)
println(x)

what would be printed in normal scala code? scala uses call by value. what would happen in a call by reference language?

eager evaluation is about evaluating an argument to a function before passing it to the function,
while call by name and call by need are strategies that do not evaluate arguments before passing them to the function.
the difference is in the order and amount of evaluations, as demonstrated by the above linked examples.
both call by name and call by need are lazy evaluation strategies.

MrGumby
Mausschubser
Beiträge: 65
Registriert: 16. Apr 2013 15:07

### Re: Questions slides/code 1-5 + 'Intro to Scala'

Thank you!

concerning question 5) again:

I wanted to know the difference between call-by-name and call-by-reference. From what I found on the internet, I thought they should be the same: The thing we did with the EClosure, right?! Or what is the difference?

Ragnar
Mausschubser
Beiträge: 63
Registriert: 21. Okt 2009 19:15

### Re: Questions slides/code 1-5 + 'Intro to Scala'

Call-by-name is an evaluation strategy used to specify evaluation semantics of programming languages (most often used during formal study).
Whereas call-by-reference is about whether you copy the values you pass to functions, or if you just pass a references to those values (which does not change evaluation order, arguments are still evaluated before the function call).