September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
18
Task/History-variables/Zkl/history-variables-1.zkl
Normal file
18
Task/History-variables/Zkl/history-variables-1.zkl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class HistoryVar{
|
||||
var [private] _v, _history=List(), maxSz;
|
||||
fcn init(v,maxEntries=3){ maxSz=maxEntries; set(v) }
|
||||
fcn set(v){
|
||||
_v=v; _history.append(T(Time.Clock.time,v));
|
||||
if(_history.len()>maxSz) _history.del(0);
|
||||
self
|
||||
}
|
||||
fcn get(n=0){ // look back into history
|
||||
z:=_history.len();
|
||||
n=(if(n>=z) 0 else z-n-1);
|
||||
_history[n][1]
|
||||
}
|
||||
var [proxy] v=fcn{ _v };
|
||||
var [proxy] history=
|
||||
fcn{ _history.pump(List,fcn([(t,v)]){ T(Time.Date.ctime(t),v) }) };
|
||||
fcn __opAdd(x){ set(_v + x); self }
|
||||
}
|
||||
6
Task/History-variables/Zkl/history-variables-2.zkl
Normal file
6
Task/History-variables/Zkl/history-variables-2.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
hv:=HistoryVar(123);
|
||||
hv+4;
|
||||
hv.set("Shuttle prepared for liftoff");
|
||||
hv+": orbit achived";
|
||||
hv.history.concat("\n").println();
|
||||
hv.get(3).println("<-- value two changes ago");
|
||||
Loading…
Add table
Add a link
Reference in a new issue