Experience shows that programmers often experience difficulties
when trying to switch to a functional programming style. StdImperative
is a new, innovative programming language designed to remedy this.
Recent attempts — such as Scala — try to mix functional and procedural styles. StdImperative is different. StdImperative is a purely imperative
language, but built using the same technologies that power functional
programs. Programmers can use all the
constructions they like most, including assignment to variables, as well
as for
and while
loops with a full set of control flow statements, and
easy to use I/O. But they will also benefit from
the underlying functional technology: programs will contain less bugs and be easier
to write. And if you really want to mix functional and imperative code, StdImperative integrates seamlessly with Clean.
Here is an example of a program that counts to 10 and shows the result on standard output:
The first line introduces the name of the program, and must match the filename (in this case, main.icl). The second line specifies that this source file is written in StdImperative. The third line specifies which procedure should be run on startup. The rest should be self-explanatory!module main import StdImperative Start = run count_to_10 count_to_10 = X := 1 ` repeat X := X + 1 until X >= 10 ` print "X is now " ` println X
bottles = for X := 99 to 1 do ( cout << X << " bottles of beer on the wall!" << endl ` cout << X << " bottles of beer!" << endl ` cout << "Take one down, pas it around" << endl ` when (X==1) do break ` cout << X-1 << " bottles of beer on the wall!" << endl ` cout << endl ) ` cout << "No more bottles of beer on the wall!" << endl
Of course, StdImperative has lexical scoping. In the following
fragment the variable V
is local to the compound statement containing
the injump
label, shadowing the definition of V
in the outer scope:
StdImperative has an orthogonal design and list processing capabilities which together act similar to Python's list comprehensions, as seen in the following sorting algorithm:jumping_scopes = X := 0 ` V := 3 ` goto "injump" ` "backjump"@ cout << "Begin: " << V << endl ` when (X) do return 0 ` X +:= 1 ` ( V local V := 0 ` goto "outjump" ` "injump"@ V := 1 ` cout << "Inside: " << V << endl ) ` "outjump"@ cout << "Outside: " << V << endl ` V := 27 ` goto "backjump"
The distribution of StdImperative contains more examples. Why not try it yourself today?pigeonhole_sort = V := [4,6,5,1,3,6,7] ` M local M := V[0] ` for E <-| V do when (E>M) do M:=E ` I := (for X := 0 to M do -1) ` I[V] := 0 to size V-1 ` V := V[for J <-| I do when (J>=0) do J] ` return V
StdImperative is distributed as a compiler, implemented using a combination of CPS semantics and EDSL technology for the Clean System. It is available for Windows and Linux.
Please select your preferred version:Version 1.0 was released on 2014-04-01. The source code for the Clean System can be found here, source code for StdImperative is included in the above distribution.
The IDE for StdImperative under Windows does not support multiple undo.
StdImperative itself is distributed under the terms of the EUPL 1.1
All other parts, i.e. all files originating from the Clean System, are distributed under the terms of the LGPL.