Skip to content
Snippets Groups Projects
Commit 9d0f8a3f authored by Regis Blanc's avatar Regis Blanc Committed by Etienne Kneuss
Browse files

explaining basic imperative features

parent 24a79f90
No related branches found
No related tags found
No related merge requests found
...@@ -33,18 +33,46 @@ syntax. ...@@ -33,18 +33,46 @@ syntax.
The above example illustrates three new features introduced by XLang: The above example illustrates three new features introduced by XLang:
1. Declaring a variable in a local scope 1. Declaring a variable in a local scope
2. Blocks of statement 2. Blocks of expressions
3. Assignment 3. Assignment
You can use Scala variables with a few restrictions. The variables can only be
declared and used locally in the same function, and inner functions cannot
close over them. XLang introduces the possibility to use sequences of
expressions (blocks) -- a feature not available in PureScala, where you're only
option is a sequence of ``val`` which essentially introduce nested ``let``
declarations.
.. warning::
Be careful when combining variables with nested functions from PureScala. Leon
will reject code with nested functions accessing a variable from an outside scope:
.. code-block:: scala
def foo(x: Int) = {
var a = 12
def bar(y: Int): Int = {
a = a + 1
a + y
}
bar(17)
}
The problem with such code is the complications involved in representing closures as
they need a pointer to an environment containing the variables. Leon is only able
to handle closures with ``val``, where it is sufficient to explicitly pass the values
as parameters.
While loops While loops
***********
Arrays Arrays
******
Nested function closure on local variables.
.. note:: .. note::
some note comes here some note comes here
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment