June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
51
Task/History-variables/Elena/history-variables.elena
Normal file
51
Task/History-variables/Elena/history-variables.elena
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import extensions.
|
||||
import system'collections.
|
||||
import system'routines.
|
||||
import extensions'routines.
|
||||
|
||||
class HistoryVariable
|
||||
{
|
||||
object prop Value :: _value.
|
||||
stack _previous := Stack new.
|
||||
|
||||
set Value:v
|
||||
[
|
||||
if ($nil != _value)
|
||||
[
|
||||
_previous push(_value)
|
||||
].
|
||||
|
||||
_value := v
|
||||
]
|
||||
|
||||
undo
|
||||
[
|
||||
ifnot (_previous isEmpty)
|
||||
[
|
||||
_value := _previous pop
|
||||
];
|
||||
[
|
||||
_value := $nil
|
||||
]
|
||||
]
|
||||
|
||||
enumerator => _previous.
|
||||
|
||||
dispatch => _value.
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
var o := HistoryVariable new.
|
||||
o Value := 5.
|
||||
o Value := "foo".
|
||||
o Value := o Value + "bar".
|
||||
|
||||
console printLine(o).
|
||||
|
||||
o forEach:printingLn.
|
||||
|
||||
o undo; undo; undo.
|
||||
|
||||
console printLine(o Value).
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue