Scala
is a object-oriented, statically-typed and functional programming language for the JVM. The strength of Scala lies in it's powerful syntax which allows to write readable, manageable code which are short and conc Ise–and It comes with great support for common design pattern (i.e. a special keyword for implementing the Singleton des IGN pattern).
There is plenty of good tutorials and introductions for learning Scala on the web, but only a few mention the great Possi Bilities programmers has to extend Scala or even build an own domain specific language using Scala without being forced t o use macros as seen in Lisp-like languages.
One interesting feature of Scala is "blocks" which work quite different then code blocks in Java and C + + although they us e the same syntax. A block in Scala is rather a sequence of expressions which are evaluated successively and it returns the value of the last Expression. Just think of them as the ' do ' function in LISP. Blocks is surrounded by curly braces and the expressions they hold is separated by semicolons.
1 2 |
scala> {val x = 2; x + 5} res 0:int = 7 |
Thanks to some syntactic sugar the semicolon can is replaced by a line breaks which becomes handy in larger blocks.
1 2 3) 4 5 |
scala> {val x = 5 x + 5} res 1:int = 10 |
Because blocks is just expressions they can be used, of course, like every other expression. They can stored in variables, returned by functions and also is used as parameters for functions:
1 2 3 4 5 6 7 8 |
Scala> println (2 + 5) 7 |