Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Scala Expressions and Types1-19-2011Opening DiscussionCommand line impressions.Powerful but difficult.More confusing than a GUI for copying and moving?Similarities to Matlab.Remembering/memorizing commands.What happens if someone restarts a computer you are sshed into?Saving terminal sessions.Solutions to the IcP.Text Files/EditorsPrograms are typically written as plain text files and should be edited with a text editor.Notepad is a basic text editor on Windows.Word is NOT a text editor.Some text editors are better than others for programming.In this class we will use vi.viThe vi editor is standard on Linux which is one reason we like to use it.It is also good for programming.Has modes. Start in command mode. You type in an edit mode.i – insertI – insert at beginning of linea – appendA – append at end of lineR – replace charactersOther Commandsx – delete charactersdd – delete linesyy – yank/copy linesp or P – paste before or afterr – replace a single characterJ – join lines/ and n – search for something and nextcw – change a word. - repeat last commandu and Crtl-r – Undo and redoScala Script/First ProgramLet's go into your course and use vi to write our first Scala program then run it.The standard first program is “Hello World.” and I don't want to break with tradition.Scala REPLIf you just type scala and don't provide a file name to run, it will drop you into the REPL (Read, Evaluate, Print Loop).Here you can enter individual commands and have them run.It is great for testing things out and getting to learn the language.Key TermsToken – A set of characters that has meaning to the language.Statement – A set of tokens that give a complete instruction.Expression – Tokens put together that produce a value.Type – All values have types. A type is a set of values and the operations allowed on them.Literal – A token that represents a value.Numeric, String, Character, BooleanStatements and Semicolon InferenceIn Scala, as with most programming languages, programs are made by putting together statements.In Scala, any expression is a valid statement as are a few other constructs.Statements end with semicolons, but they will be inferred at the end of a line if they make sense so you rarely type them.OperatorsWe can build longer expressions by putting literals together with operators.Let's start off by playing with some of the numeric operations you are probably familiar with.+, -, *, /You can get the remainder after division with %.ObjectsAn object is defined to be information along with the things you can do with that information.The information in an object is called the properties.The actions are called methods.In Scala, even things like Int are objects and have methods on them.MethodsThe normal way to call a method in Scala (and most other object-oriented languages) is to put a period after the object and follow it with the method name.The REPL will do tab completion and list methods for you.Let's look at the methods on some basic types and try calling them.ArgumentsSome methods need additional information to work.To give this to the method we pass in arguments.Arguments are put in parentheses and separated by commas if there is more than one.The parentheses are generally optional in Scala if there is no argument.Operator SyntaxAll the “operators” in Scala are really just methods.Scala allows any method with zero or one arguments to be called with an operator syntax.That means you leave off the dot and the parentheses.If a method takes no arguments you can call it without the dot.Minute EssayWhat in today's lectures was confusing? Was there anything that surprised
View Full Document