Skip to content
Permalink
Browse files

Add ObjectOrientedPrograming section

  • Loading branch information
julienrf committed Nov 23, 2016
1 parent f491691 commit 543fa5c1da5ade1553d813f1b04b67ed9923d869
Binary file not shown.
@@ -0,0 +1,23 @@
package scalatutorial.aux

abstract class IntSet {
def incl(x: Int): IntSet
def contains(x: Int): Boolean
}

object Empty extends IntSet {
def contains(x: Int): Boolean = false
def incl(x: Int): IntSet = new NonEmpty(x, Empty, Empty)
}
class NonEmpty(elem: Int, left: IntSet, right: IntSet) extends IntSet {

def contains(x: Int): Boolean =
if (x < elem) left contains x
else if (x > elem) right contains x
else true

def incl(x: Int): IntSet =
if (x < elem) new NonEmpty(elem, left incl x, right)
else if (x > elem) new NonEmpty(elem, left, right incl x)
else this
}
@@ -175,7 +175,9 @@ object LexicalScopes extends ScalaTutorialSection {
*
* = Packages and Imports =
*
* Top-level definitions can be organized in ''packages'':
* Top-level definitions can be organized in ''packages''.
* To place a class or object inside a package, use a package clause
* at the top of your source file:
*
* {{{
* // file foo/Bar.scala
@@ -223,6 +225,48 @@ object LexicalScopes extends ScalaTutorialSection {
* Bar.someMethod
* }
* }}}
*
* = Automatic Imports =
*
* Some entities are automatically imported in any Scala program.
*
* These are:
*
* - All members of package `scala`
* - All members of package `java.lang`
* - All members of the singleton object `scala.Predef`.
*
* Here are the fully qualified names of some types and functions
* which you have seen so far:
*
* {{{
* Int scala.Int
* Boolean scala.Boolean
* Object java.lang.Object
* String java.lang.String
* }}}
*
* = Writing Executable Programs =
*
* So far our examples of code were executed from your Web
* browser, but it is also possible to create standalone
* applications in Scala.
*
* Each such application contains an object with a `main` method.
*
* For instance, here is the "Hello World!" program in Scala:
*
* {{{
* object Hello {
* def main(args: Array[String]) = println("hello world!")
* }
* }}}
*
* Once this program is compiled, you can start it from the command line with
*
* {{{
* $ scala Hello
* }}}
*/
def nothing(): Unit = ()
}

0 comments on commit 543fa5c

Please sign in to comment.
You can’t perform that action at this time.