Chapter 2, Exercises 7-9, Thinking in Scala
I'm trying a new tack. Maybe a little less error prone than trying to slip Scala source code past Radio UserLand's text munger. Unfortunately, UserLand's restrictive filename policy requires that I rename these as foo.scala.txt. Sorry.
Later: scratch that, I didn't like how that worked.
This entry corresponds to
http://theclapp.blog-city.com/read/9551.htm .
There's nothing very new here ...
Chapter 2, Exercise 7
Print three args from the command line
object c2x7 {
def main ( args : Array[String] ) = {
Console.println( "Arg 1: " + args( 0 ) );
Console.println( "Arg 2: " + args( 1 ) );
Console.println( "Arg 3: " + args( 2 ) );
}
}
Chapter 2, Exercise 8
AllTheColorsOfTheRainbow -- not really colors, just member access
class AllTheColorsOfTheRainbow {
var anIntegerRepresentingColors : Int = _ ;
def changeTheHueOfTheColor ( newHue : Int ) =
anIntegerRepresentingColors = newHue;
};
object c2x8 {
def main ( args : Array[String] ) = {
var atcotr = new AllTheColorsOfTheRainbow;
atcotr.changeTheHueOfTheColor( 10 );
}
}
Chapter 2, Exercise 9
HelloDate (javadoc -> scaladoc)
//: c2x9.scala
/** The first Thinking in Scala example program.
* Displays a string and today's date.
*
* @author Bruce Eckel
* @author www.BruceEckel.com
* @translator (into Scala) Doug Landauer
* @version 2.0
*/
package x;
object HelloDate {
/** Sole entry point to class & application
*
* @param args array of string arguments
* @return No return value
* @exception exceptions No exceptions thrown
*/
def main ( args : Array[String] ) = {
Console.println("Hello, it's: ");
Console.println(new java.util.Date());
}
} //\/:~
Here, we learn that the stuff inside scaladoc comments has to be sorta reasonable xhtml. I had to escape the ampersand. Scaladoc created 9 .html files for this example. I copied the one for the x package here. It does look better in context.
Update: Sorry, it was 54 .html files. I copied some of them up to here. You want to click on package x, Object HelloDate in order to see the part that's relevant to this exercise. Most of the other links won't work because I didn't upload their files.
Note that scaladoc (and, I imagine, javadoc) creates the .html files for the package in the same subdirectory where that package's .class files are generated.
11:31:42 PM