Sequential Execution and Scripts 1 26 2011 Opening Discussion Minute Essays Difficulty of the quiz Usefulness of hex Do I play ultimate Types of escape characters When to use them Grade return times Why both hex and octal Meaning of A F I hex Number 8 7 is Number 8 7 Need for commands Variables It is very common to want to represent values with names A variable is a name that we use to represent a value In Scala we can declare variables using val or var val name Type expression var name Type expression A val can t change it s value a var can The colon and type generally optional Tuples Another type in Scala is the Tuple type A tuple has comma separated values in parentheses They give us a way to handle a fixed set of associated values Assignment into a tuple does pattern matching Scripts We have spent most of our time in the REPL entering one statement at a time When we want to do things repeatedly it is nice to put the commands in a file called a script We can use vi to write a script and put Scala commands in the file We can run it by specifying the file name after the command scala Alternately we can load it into the REPL Sequential Execution When you put commands into a script they are normally executed one after the other from top to bottom This is what we call sequential execution and it is the default way things happen Order can be very significant for the instructions in a program Standard Input Scala provides a whole set of functions you can call to read from standard input readInt readDouble readLine And many more This can make your scripts far more useful as they can be used with different values each time you run them Some Problems We are still a little limited in that we can only do simple math and formatting but let s try to do some things with that in scripts We ll start with formatting money Calculating hourly wages Taking averages of grades Suggestions Minute Essay What questions do you have about things The next IcP is Monday
View Full Document