Edited, memorised or added to reading list

on 08-Sep-2014 (Mon)

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

#scala
When a function value containing a return statement is evaluated nonlocally, the computation is abandoned and the result is returned by throwing a NonLocalReturnControl[A].

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

tpolecat
it returns from the method it appears in. Another example: def foo: Int = { val sumR: List[Int] => Int = _.foldLeft(0)((n, m) => return n + m) sumR(List(1,2,3)) + sumR(List(4,5,6)) } scala> foo res4: Int = 1 Non-Local Return <span>When a function value containing a return statement is evaluated nonlocally, the computation is abandoned and the result is returned by throwing a NonLocalReturnControl[A]. This implementation detail escapes into the wild without much ceremony: def lazily(s: => String): String = try s catch { case t: Throwable => t.toString } def foo: String = laz




#scala
calling return in Scala is like invoking the continuation in Scheme

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

tpolecat
ype) you know that the expression has no normal form; when evaluated it must loop forever, exit the VM, or (behind door #3) abruptly pass control elsewhere, which is what's happening here. If your reaction is "well logically you're just <span>invoking the continuation, which we totally do all the time in Scheme so I don't see the problem" then fine. Cookie for you. The rest of us think it's insane. Return is not referentially transparent. This kind of goes without saying, but just in case you're not sure what thi




#scala
whenever you encounter an expression of type Nothing: because Nothing is uninhabited (there are no values of that type) you know that the expression has no normal form; when evaluated it must (one of):
  • loop forever
  • exit the VM
  • abruptly pass control elsewhere (use return or throw exception?)

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

tpolecat
What's going on? Whatever the type of return 2 is, it comforms with both Int and String. And since both of those classes are final and Int is an AnyVal you know where this is headed. def x: Int = { val a: Nothing = return 2; 1 } Right. So, <span>whenever you encounter an expression of type Nothing you would do well to turn smartly and head the other direction. Because Nothing is uninhabited (there are no values of that type) you know that the expression has no normal form; when evaluated it must loop forever, exit the VM, or (behind door #3) abruptly pass control elsewhere, which is what's happening here. If your reaction is "well logically you're just invoking the continuation, which we totally do all the time in Scheme so I don't see the problem" then fine. Cookie for you.




#odersky-programming-in-scala-2ed #scala
Scala’s on-demand imports are written with a trailing underscore (_) instead of an asterisk (*) like in Java.

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149632614

Tags
#odersky-programming-in-scala-2ed #scala
Question
if we have:

abstract class Fruit(
  val name: String,
  val color: String
)
what does import fruit._ mean?

def showFruit(fruit: Fruit) {
  import fruit._
  // rest of the method
}
Answer
you can use name and color (fields from Fruit) directly:
println(name +"s are "+ color)


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 149632625

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does it mean?
import Fruits.{Apple, Orange}
Answer
importing only 2 names from Fruits


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 149632636

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does it mean?
import Fruits.{Apple => McIntosh, Orange}
Answer
This imports the two members Apple and Orange from object Fruits.
However, the Apple object is renamed to McIntosh.


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 149632647

Tags
#odersky-programming-in-scala-2ed #scala
Question
How can I refer to java.sql.Date class if I use this in Scala?
import java.{sql => S}
Answer
S.Date


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 149632658

Tags
#odersky-programming-in-scala-2ed #scala
Question
What's the other way of writing
import Fruits._
in full, using import selector?
Answer
import Fruits.{_}


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 149632669

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to import everything from Fruits but rename Apple to McIntosh?
Answer
import Fruits.{Apple => McIntosh, _}


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 149632680

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to import everything except for Pear (i.e. exclude Pear) from Fruits?
Answer
import Fruits.{Pear => _, _}


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 149632691

Tags
#odersky-programming-in-scala-2ed #scala
Question
How can I write import p.n using full import selectors?
Answer
import p.{n}


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







#odersky-programming-in-scala-2ed #scala
The implicit imports in every Scala program are:
  • import java.lang._
  • import scala._
  • import Predef._

statusnot read reprioritisations
last reprioritisation on reading queue position [%]
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149632715

Tags
#odersky-programming-in-scala-2ed #scala
Question
The implicit imports in every Scala program are:
  • [...]
  • import scala._
  • import Predef._

Answer
import java.lang._


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 implicit imports in every Scala program are: import java.lang._ import scala._import Predef._

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632722

Tags
#odersky-programming-in-scala-2ed #scala
Question
The implicit imports in every Scala program are:
  • import java.lang._
  • [...]
  • import Predef._

Answer
import scala._


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 implicit imports in every Scala program are: import java.lang._ import scala._import Predef._

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632729

Tags
#odersky-programming-in-scala-2ed #scala
Question
The implicit imports in every Scala program are:
  • import java.lang._
  • import scala._
  • [...]
Answer
import Predef._


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 implicit imports in every Scala program are: import java.lang._ import scala._import Predef._

Original toplevel document (pdf)

cannot see any pdfs







Flashcard 149632747

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

class Outer {
 class Inner {
  private def f() { println("f") }
  class InnerMost {
   f()
  }
 }
 (new Inner).f() // is it legal in Scala? why? woudl it be legal in Java?
}
Answer
access (new Inner).f() is illegal because f is declared private in Inner and the access is not from within class Inner - in Java it would be legal


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 149632756

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

class Outer {
 class Inner {
  private def f() { println("f") }
  class InnerMost {
   f() // is it legal in Scala? why? would it be legal in Java?
  }
 }
 (new Inner).f() // warning - illegal!
}
Answer
Yes. In both languages. A inner class accessing private member of the class it is declared in.


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 149632767

Tags
#odersky-programming-in-scala-2ed #scala
Question
In Java protected members are accessible from subclasses and within the same package. How is it in Scala?
Answer
only accessible from subclasses


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 149632778

Tags
#odersky-programming-in-scala-2ed #scala
Question
Every member not labeled private or protected is [...].
Answer
implicitely public


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 149632789

Tags
#odersky-programming-in-scala-2ed #scala
Question
What does access modifier private[this] mean? Is it more or less restrictive than private ?
Answer
It is more restrictive, because it allows access only from the same object. Same class, different object is not allowed (think: typical implementation of equals() in Java has this.x == that.x; it wouldn't work with private[this] in Scala)


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 149632800

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to create package object for a package rocket ?
Answer

package object rocket {
  // definitions go here
}


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 149632811

Tags
#odersky-programming-in-scala-2ed #scala
Question
What do you put into package objects? How is it different than Java?
Answer
Any kind of definition that you can put inside a class, you can also put at the top level of a package, by putting it into package object. In Java, only classes and interfaces can be members of packages.


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