Lecture - Imperative Programming TT23, VIII


  • Mutable and immutable collections
    • scala.collection.mutable vs scala.collection.immutable
    • Lists share the same static type but the dynamic type can be different
  • GUI programming
    • scala-swing
      • Layout
      • Events
      • Drawing
      • Threads

Example code

import scala.swing.

object FirstSwingApp extends SimpleSwingApplication {
	def top = new MainFrame {
		contents = new Label("Hello world")
	}
}
  • MainFrame is a subclass of Frame which quits the application when done (e.g. the cross is clicked).
  • In match expressions, case Blah which try and match a specific value or type called Blah, but case blah means anything will bind to blah. Can fix by doing
case `blah`

Flashcards

Can you explain the difference between

case Blah
case blah
case `blah`

in Scala?


case Blah       // Matches a specific type or value named Blah,
case blah       // Will bind anything to a variable called "blah",
case `blah`     // Matches a specific type or value named blah.



Related posts