History variables: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 568: Line 568:
2013-Jan-19 23:04:55.1662596; goodby
2013-Jan-19 23:04:55.1662596; goodby
</pre>
</pre>

=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
No native support. We implement an anonymous stack associated with the variable, and a few syntax rules to define the needed operations.
No native support. We implement an anonymous stack associated with the variable, and a few syntax rules to define the needed operations.
Line 594: Line 595:
(h-undo x) → ❌ error: no more values x
(h-undo x) → ❌ error: no more values x
</lang>
</lang>

=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
Line 1,147: Line 1,149:


</pre>
</pre>

=={{header|Julia}}==
=={{header|Julia}}==
Julia currently does not support overloading the assignment "=" operator.
Julia currently does not support overloading the assignment "=" operator.
Line 1,811: Line 1,814:
undo 3, current value: a
undo 3, current value: a
$x is: a</lang>
$x is: a</lang>
=={{header|Perl 6}}==
{{works with|Rakudo|2018.03}}
<lang perl6>class HistoryVar {
has @.history;
has $!var handles <Str gist FETCH Numeric>;
method STORE($val) is rw {
push @.history, [now, $!var];
$!var = $val;
}
}

my \foo = HistoryVar.new;

foo = 1;
foo = 2;
foo += 3;
foo = 42;

.say for foo.history;
say "Current value: {foo}";</lang>
{{out}}
<pre>[Instant:1523396079.685629 (Any)]
[Instant:1523396079.686844 1]
[Instant:1523396079.687130 2]
[Instant:1523396079.687302 5]
Current value: 42
</pre>


=={{header|Phix}}==
=={{header|Phix}}==
Line 2,081: Line 2,057:
(check-equal? (hvar-current hv) 0)
(check-equal? (hvar-current hv) 0)
</lang>
</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.03}}
<lang perl6>class HistoryVar {
has @.history;
has $!var handles <Str gist FETCH Numeric>;
method STORE($val) is rw {
push @.history, [now, $!var];
$!var = $val;
}
}

my \foo = HistoryVar.new;

foo = 1;
foo = 2;
foo += 3;
foo = 42;

.say for foo.history;
say "Current value: {foo}";</lang>
{{out}}
<pre>[Instant:1523396079.685629 (Any)]
[Instant:1523396079.686844 1]
[Instant:1523396079.687130 2]
[Instant:1523396079.687302 5]
Current value: 42
</pre>


=={{header|REXX}}==
=={{header|REXX}}==
Line 2,348: Line 2,353:
x history.
x history.
</lang>
</lang>

=={{header|Swift}}==
=={{header|Swift}}==
Swift does not support history variables. However, you can add a watcher that can track when the variable will change.
Swift does not support history variables. However, you can add a watcher that can track when the variable will change.