Functional Programming (Scala)

8 flashcards · Programming Languages · by Athena Papkouf

  1. non-primitive expression evaluation

    1. Take the leftmost operator 2. Evaluate its operands (left before right) 3. Apply the operator to the operands

  2. evaluation of parameterized functions

    1. Evaluate all function arguments, from left to right 2. Replace the function application by the function’s right-hand side, and, at the same time 3. Replace the formal parameters of the function by the actual arguments.

  3. Does every expression reduce to a value (in a finite number of steps)?

    No. Here is a counter-example def loop: Int = loop loop

  4. call-by-name evaluation

    apply the function to unreduced arguments

  5. call-by-value

    reduce function arguments to values before rewriting the function application

  6. If CBV evaluation of an expression e terminates, then CBN evaluation of e terminates, too. ▶ The other direction is not true

  7. Scala’s evaluation strategy

    Scala normally uses call-by-value. But if the type of a function parameter starts with => it uses call-by-name.

  8. difference between val and def

    def form is “by-name”, val form is “by-value”