History variables: Difference between revisions
Content added Content deleted
(Added Algol W) |
|||
Line 595: | Line 595: | ||
</lang> |
</lang> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA |
ELENA 4.x : |
||
<lang elena>import extensions |
<lang elena>import extensions; |
||
import system'collections |
import system'collections; |
||
import system'routines |
import system'routines; |
||
import extensions'routines |
import extensions'routines; |
||
class HistoryVariable |
class HistoryVariable |
||
{ |
{ |
||
Stack previous := new Stack(); |
|||
object value; |
|||
object |
prop object Value |
||
{ |
|||
⚫ | |||
set Value:v |
|||
set(value) |
|||
{ |
|||
if ((this value) != nil) |
|||
{ |
|||
previous.push(this value) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
undo() |
|||
{ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
{ |
|||
value := nil |
|||
} |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
get string Printable() => this value; |
|||
⚫ | |||
T<literal> literal => _value. |
|||
} |
} |
||
public program |
public program() |
||
{ |
|||
[ |
|||
var o := |
var o := new HistoryVariable(); |
||
o |
o.Value := 5; |
||
o |
o.Value := "foo"; |
||
o |
o.Value := o.Value + "bar"; |
||
console |
console.printLine(o); |
||
o |
o.forEach:printingLn; |
||
o |
o.undo().undo().undo(); |
||
console |
console.printLine(o.Value ?? "nil") |
||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 653: | Line 658: | ||
foo |
foo |
||
5 |
5 |
||
nil |
|||
</pre> |
</pre> |
||