Edited, memorised or added to reading queue

on 07-Sep-2014 (Sun)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 149629596

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does to stand for in this example?

for (i <- 0 to 2)
  print(greetStrings(i))
Answer
a method call (0).to(2)
if a method takes only one parameter, you can call it without a dot or parentheses.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629623

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does + really stand for in 2 + 3?
Answer
it is a method call: (2).+(3)
method is named "+"

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629643

Tags
#odersky-programming-in-scala-2ed #scala
Question
if greetStrings is an array, greetStrings(i) gets transformed into
Answer
greetStrings.apply(i)

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629682

Tags
#odersky-programming-in-scala-2ed #scala
Question
What will greetStrings(0) = "Hello" be transformed into?
Answer
greetStrings.update(0, "Hello")

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149629693

Tags
#odersky-programming-in-scala-2ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
a factory method apply which takes variable number of argumetns and is defined on Array companion object
the code gets transformed to
val numNames2 = Array.apply("zero", "one", "two")

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149632156

Tags
#odersky-programming-in-scala-2ed #scala
Question
The order of mixins is significant.Roughly speaking, traits further to the [...]take effect first.
Answer
right

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
The order of mixins is significant.Roughly speaking, traits further to the right take effect first.

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632194

Tags
#odersky-programming-in-scala-2ed #scala
Question

class Animal
trait Furry extends Animal
trait HasLegs extends Animal
trait FourLegged extends HasLegs
class Cat extends Animal with Furry with FourLegged

The last part of the linearization of Cat is the linearization of its [...], which is copied as-is. The second to last part is the linearization of the first mixin, trait Furry, but
all classes that are already in the linearization of Animal are left out now. This is preceded by the linearization of FourLegged, where again any classes
that have already been copied in the linearizations of the superclass or the first mixin are left out.
Answer
superclass, Animal

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
#13; class Animal trait Furry extends Animal trait HasLegs extends Animal trait FourLegged extends HasLegs class Cat extends Animal with Furry with FourLegged The last part of the linearization of Cat is the linearization of its <span>superclass, Animal, which is copied as-is. The second to last part is the linearization of the first mixin, trait Furry, but all classes that are already in the linearization of Animal are left out n

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632201

Tags
#odersky-programming-in-scala-2ed #scala
Question

class Animal
trait Furry extends Animal
trait HasLegs extends Animal
trait FourLegged extends HasLegs
class Cat extends Animal with Furry with FourLegged

The last part of the linearization of Cat is the linearization of its superclass, Animal, which is [...]. The second to last part is the linearization of the first mixin, trait Furry, but
all classes that are already in the linearization of Animal are left out now. This is preceded by the linearization of FourLegged, where again any classes
that have already been copied in the linearizations of the superclass or the first mixin are left out.
Answer
copied as-is

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
y extends Animal trait HasLegs extends Animal trait FourLegged extends HasLegs class Cat extends Animal with Furry with FourLegged The last part of the linearization of Cat is the linearization of its superclass, Animal, which is <span>copied as-is. The second to last part is the linearization of the first mixin, trait Furry, but all classes that are already in the linearization of Animal are left out now. This is preceded by

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632212

Tags
#odersky-programming-in-scala-2ed #scala
Question

class Animal
trait Furry extends Animal
trait HasLegs extends Animal
trait FourLegged extends HasLegs
class Cat extends Animal with Furry with FourLegged

The last part of the linearization of Cat is the linearization of its superclass, Animal, which is copied as-is. The second to last part is the linearization of the [...], but all classes that are already in the linearization of Animal are left out now. This is preceded by the linearization of FourLegged, where again any classes that have already been copied in the linearizations of the superclass or the first mixin are left out.
Answer
first mixin, trait Furry

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
ends HasLegs class Cat extends Animal with Furry with FourLegged The last part of the linearization of Cat is the linearization of its superclass, Animal, which is copied as-is. The second to last part is the linearization of the <span>first mixin, trait Furry, but all classes that are already in the linearization of Animal are left out now. This is preceded by the linearization of FourLegged, where again any classes that have already been co

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632226

Tags
#odersky-programming-in-scala-2ed #scala
Question

class Animal
trait Furry extends Animal
trait HasLegs extends Animal
trait FourLegged extends HasLegs
class Cat extends Animal with Furry with FourLegged

The last part of the linearization of Cat is the linearization of its superclass, Animal, which is copied as-is. The second to last part is the linearization of the first mixin, trait Furry, but all classes that are [...]are left out now. This is preceded by the linearization of FourLegged, where again any classes that have already been copied in the linearizations of the superclass or the first mixin are left out.
Answer
already in the linearization of Animal

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
th FourLegged The last part of the linearization of Cat is the linearization of its superclass, Animal, which is copied as-is. The second to last part is the linearization of the first mixin, trait Furry, but all classes that are <span>already in the linearization of Animal are left out now. This is preceded by the linearization of FourLegged, where again any classes that have already been copied in the linearizations of the superclass or the first mixin ar

Original toplevel document (pdf)

cannot see any pdfs







#scala
Methods in Scala are not values, but functions are.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

tpolecat
to when people get confused on #scala, but it turns out that there are a lot of cases to consider. It would be nice if this could just be the last word on methods vs. functions in Scala, so if I missed anything please let me know. TL;DR ... <span>Methods in Scala are not values, but functions are. You can construct a function that delegates to a method via η-expansion (triggered by the trailing underscore thingy). The definition I will be using here is that a method is something




#scala
You can construct a function that delegates to a method via η-expansion (triggered by the trailing underscore thingy).
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

tpolecat
out that there are a lot of cases to consider. It would be nice if this could just be the last word on methods vs. functions in Scala, so if I missed anything please let me know. TL;DR ... Methods in Scala are not values, but functions are. <span>You can construct a function that delegates to a method via η-expansion (triggered by the trailing underscore thingy). The definition I will be using here is that a method is something defined with def and a value is something you can assign to a val. The Basic Idea When we define a method we see that




#scala
by adding the η-expansion postfix operator (η is pronounced "eta"), we can turn the method into a function value.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

tpolecat
with `_' if you want to treat it as a partially applied function val f = add1 ^ Note also the type of add1, which doesn't look normal; you can't declare a variable of type (n: Int)Int. Methods are not values. However, <span>by adding the η-expansion postfix operator (η is pronounced "eta"), we can turn the method into a function value. Note the type of f. scala> val f = add1 _ f: Int => Int = scala> f(3) res0: Int = 4 The effect of _ is to perform the equivalent of the following: we construct a Function1 in




#scala

The effect of _ is to perform the equivalent of the following: we construct a Function1 instance that delegates to our method.

scala> val g = new Function1[Int, Int] { def apply(n: Int): Int = add1(n) }
g: Int => Int = <function1>

scala> g(3)
res18: Int = 4

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on




#scala
The return keyword is not "optional" or "inferred"; it changes the meaning of your program, and you should never use it.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

tpolecat
May 09, 2014 Don't Use Return in Scala Alright, every time Martin's Coursera course runs we get people in #scala asking why they get style points taken off for using return. So here's the pro tip: <span>The return keyword is not "optional" or "inferred"; it changes the meaning of your program, and you should never use it. Let's look at a little example. // Add two ints, and use this method to sum a list def add(n:Int, m:Int): Int = n + m def sum(ns: Int*): Int = ns.foldLeft(0)(add) scala> sum(33, 42,




#scala

// Inline add and addR
def sum(ns: Int*): Int = ns.foldLeft(0)((n, m) => n + m) // inlined add

scala> sum(33, 42, 99)
res2: Int = 174 // alright

def sumR(ns: Int*): Int = ns.foldLeft(0)((n, m) => return n + m) // inlined addR

scala> sumR(33, 42, 99)
res3: Int = 33 // um.

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

tpolecat
(addR) scala> sumR(33, 42, 99) res1: Int = 174 So far so good. There is no apparent difference between sum and sumR which may lead you to think that return is simply an optional keyword. But let's refactor a bit by inlining add and addR. <span>// Inline add and addR def sum(ns: Int*): Int = ns.foldLeft(0)((n, m) => n + m) // inlined add scala> sum(33, 42, 99) res2: Int = 174 // alright def sumR(ns: Int*): Int = ns.foldLeft(0)((n, m) => return n + m) // inlined addR scala> sumR(33, 42, 99) res3: Int = 33 // um. What the what? So, the short version is: A return expression, when evaluated, abandons the current computation and returns to the caller of the method in which return appears. So in




Flashcard 149632499

Tags
#scala
Question
// Inline add and addR
def sum(ns: Int*): Int = ns.foldLeft(0)((n, m) => n + m) // inlined add

scala> sum(33, 42, 99)
res2: Int = 174 // alright

def sumR(ns: Int*): Int = ns.foldLeft(0)((n, m) => return n + m) // inlined addR

scala> sumR(33, 42, 99)
res3: ???
What will this expression return and why?
Answer
33 // um.

A return expression, when evaluated, abandons the current computation and returns to the caller of the method in which return appears.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Parent (intermediate) annotation

Open it
Int*): Int = ns.foldLeft(0)((n, m) => n + m) // inlined add scala> sum(33, 42, 99) res2: Int = 174 // alright def sumR(ns: Int*): Int = ns.foldLeft(0)((n, m) => return n + m) // inlined addR scala> sumR(33, 42, 99) res3: Int = <span>33 // um. <span><body><html>

Original toplevel document

tpolecat
(addR) scala> sumR(33, 42, 99) res1: Int = 174 So far so good. There is no apparent difference between sum and sumR which may lead you to think that return is simply an optional keyword. But let's refactor a bit by inlining add and addR. <span>// Inline add and addR def sum(ns: Int*): Int = ns.foldLeft(0)((n, m) => n + m) // inlined add scala> sum(33, 42, 99) res2: Int = 174 // alright def sumR(ns: Int*): Int = ns.foldLeft(0)((n, m) => return n + m) // inlined addR scala> sumR(33, 42, 99) res3: Int = 33 // um. What the what? So, the short version is: A return expression, when evaluated, abandons the current computation and returns to the caller of the method in which return appears. So in