Programming in Scalaを読み始めた Chapter5
Chapter5はさらっと。
scala> 0x5 res1: Int = 5 scala> 0x00FF res2: Int = 255 scala> 035 res3: Int = 29 scala> 35 res4: Int = 35 scala> 35L res5: Long = 35 scala> 35l res6: Long = 35 scala> 1.2345 res7: Double = 1.2345 scala> 1.2345e1 res8: Double = 12.345 scala> 123E45 res9: Double = 1.23E47 scala> 1.2345F res10: Float = 1.2345 scala> 3e5f res11: Float = 300000.0 scala> 3e5 res12: Double = 300000.0 scala> 3e5D res13: Double = 300000.0 scala> 'A' res14: Char = A scala> '\101' res15: Char = A scala> '\u0041' res16: Char = A scala> val B\u0041\u0044 = 1 BAD: Int = 1 scala> val backslash = '\\' backslash: Char = \ scala> val hello = "hello" hello: java.lang.String = hello scala> val escapes = "\\\"\'" escapes: java.lang.String = \"' scala> println("""Welcome to Ultamix 3000. | Type "HELP" for help.""") Welcome to Ultamix 3000. Type "HELP" for help. scala> println("""|Welcome to Ultamix 3000. | |Type "HELP" for help.""".stripMargin) Welcome to Ultamix 3000. Type "HELP" for help. scala> val s = 'aSymbol s: Symbol = 'aSymbol scala> s.name res19: String = aSymbol scala> var bool = true bool: Boolean = true scala> var fool = false fool: Boolean = false scala> val sum = 1 + 2 sum: Int = 3 scala> val sumMore = (1).+(2) sumMore: Int = 3 scala> val longSum = 1+2L longSum: Long = 3 scala> val s = "Hello, world!" s: java.lang.String = Hello, world! scala> s indexOf 'o' res20: Int = 4 scala> s indexOf('o', 5) res21: Int = 8 scala> -2.0 res22: Double = -2.0 scala> (2.0).unary_- res23: Double = -2.0 scala> val s = "Hello, world!" s: java.lang.String = Hello, world! scala> s.toLowerCase res24: java.lang.String = hello, world! scala> s toLowerCase res26: java.lang.String = hello, world! scala> val list1 = List(1,2,3) list1: List[Int] = List(1, 2, 3) scala> val list2 = List(1,2,3) list2: List[Int] = List(1, 2, 3) scala> list1 == list2 res27: Boolean = true scala> list1.eq(list2) res28: Boolean = false scala> list1.eq(list1) res29: Boolean = true scala> list1.ne(list2) res31: Boolean = true scala> 0 max 5 res32: Int = 5 scala> -2.7 abs res33: Double = 2.7 scala> -2.7 round res34: Long = -3 scala> 4 to 6 res35: Range.Inclusive = Range(4, 5, 6)