
Now, let’s introduce another type, Double, for working with real-valued numbers. If we wanted to override that, we’d need to use parentheses to indicate it, just like in basic algebra. Notice that Scala knows that multiplication takes precedence over addition in such computations. scala> x + 3Īnd of course, we can assign the results of such computations to other variables. Returning to the variable x, we can now use it for other computations. Typical names for variables will be strings like x, y1, result, firstName, here_is_a_long_variable_name. They must not be identical to one of the “reserved words” that Scala has already defined, such as for, if, def, val, and var.Variable names may contain: letters, numbers, underscore.

You can choose the names for variables, but they must follow some rules. Here, x is a variable, which we’ve indicate by prefacing it with val, which indicates it is a fixed variable whose value cannot change. Let’s do this trivially to start with, breaking down the print statement above into two steps. We often need to store the result of evaluating an expression to a variable for later use (in fact, programming doesn’t get done with out doing this). You can think of the print command as a verb, and its parameter (e.g.


#SCALA TUTORIAL CODE#
If you are having problems with this, you might try the examples by evaluating them in the code box on SimplyScala. This tutorial assumes you have Scala installed and that you are using some form of Unix (if you use Windows, you’ll want to look into Cygwin). (Though perhaps some of the later ones on functional programming and such that I intend to do will be, so check back.) In the meantime, check out existing Scala learning materials I’ve listed in the links page for the course. Note: if you already know a programming language, this tutorial will probably not be very useful for you. The one exception I’m aware of is SimplyScala. These tutorials assume no previous programming background, an assumption which is unfortunately still quite rare in the help-folks-learn-Scala universe, and which more or less necessitates the creation of these tutorials. The is the first of several Scala tutorials I’m creating for my Fall 2011 graduate Introduction to Computational Linguistics course at UT Austin, loosely based on similar tutorials that Katrin Erk created for teaching Python in a similar course.
