GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Monday 10 May 2004
Chapter 3, Exercise 6, Thinking in Scala

I made the output from this one a bit more verbose. Hope Radio doesn't mess up the quotings and the backslashes.

object c3x6 {
    def show1 ( ns: String, s: String ) : String =
        ns + " (is \"" + s + "\")";
    def show ( p: String, q: String, opName: String, res: Boolean ) = {
        Console.print( show1( "p", p ) );
        Console.print( " " + opName + " " );
        Console.print( show1( "q", q ) );
        Console.println( "?  " + res );
    }
    def testStringComp ( x: String, y: String ) = {
        show( x, y, "==", x == y );
        show( x, y, "!=", x != y );
        show( x, y, ".equals()", x.equals( y ) );
        // show( x, y, "<", x < y );
    }
    def main ( args: Array[String] ) = {
        testStringComp( "a", "b" );
        testStringComp( "a", "a" );
        testStringComp( "123456", "123" + "456" );
    }
}

I tried a less than, but these strings are java.lang.Strings, so they don't have a less-than method.

Here's the output that I got:

p (is "a") == q (is "b")?  false
p (is "a") != q (is "b")?  true
p (is "a") .equals() q (is "b")?  false
p (is "a") == q (is "a")?  true
p (is "a") != q (is "a")?  false
p (is "a") .equals() q (is "a")?  true
p (is "123456") == q (is "123456")?  true
p (is "123456") != q (is "123456")?  false
p (is "123456") .equals() q (is "123456")?  true

11:41:56 PM   comment/     


Click here to visit the Radio UserLand website. Click to see the XML version of this web page. © Copyright 2007 Doug Landauer .
Last update: 07/2/6; 12:39:21 .
Click here to send an email to the editor of this weblog.

May 2004
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Apr   Jun

Previous/Next