GIGO: words unreadable aloud
Mishrogo Weedapeval
 

 

  Wednesday 5 May 2004
Chapter 3, Exercise 3, Thinking in Scala

Today's exercise corresponds to this entry from the Lisp/Java version. Nothing new, though I suppose I should figure out whether "else if" chains work as expected.

package x;
object c3x3 {
    def test ( testval: Int, target: Int ) = {
        var result = 0;
        if(testval > target) {
            result = +1;
        }
        else {
            if(testval < target) { result = -1 }
            else                 { result = 0 }
        }
        result;
    }
    def test2 ( testval: Int, target: Int ) = {
        if (testval > target) { 1 }
        else {
            if (testval < target) { -1 }
            else                  { 0 }
        }
    }
    def main ( args: Array[String] ) = {
        Console.println(test(10, 5));
        Console.println(test(5, 10));
        Console.println(test(5, 5));
        Console.println(test2(10, 5));
        Console.println(test2(5, 10));
        Console.println(test2(5, 5));
    }
}

Hmm; they do seem to, though I'm not posting that version.
9:45:11 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:38:58 .
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