some expression and data files used by tests
This commit is contained in:
parent
0bca3333aa
commit
7a0ba26aa3
33
file-reader.expr
Normal file
33
file-reader.expr
Normal file
@ -0,0 +1,33 @@
|
||||
builtin ["os.file", "base"];
|
||||
|
||||
readInt=func(fh){
|
||||
line=readFile(fh);
|
||||
line ? [nil] {nil} :: {int(line)}
|
||||
};
|
||||
|
||||
ds={
|
||||
"init":func(filename){
|
||||
fh=openFile(filename);
|
||||
fh ? [nil] {nil} :: { @current=readInt(fh); @prev=@current };
|
||||
fh
|
||||
},
|
||||
"current":func(){
|
||||
prev
|
||||
},
|
||||
"next":func(fh){
|
||||
current ?
|
||||
[nil] {current}
|
||||
:: {@prev=current; @current=readInt(fh) but current}
|
||||
},
|
||||
"clean":func(fh){
|
||||
closeFile(fh)
|
||||
}
|
||||
}
|
||||
|
||||
//;f=$(ds, "int.list")
|
||||
/*
|
||||
;f++
|
||||
;f++
|
||||
;f++
|
||||
*/
|
||||
//;add(f)
|
18
iterator.expr
Normal file
18
iterator.expr
Normal file
@ -0,0 +1,18 @@
|
||||
ds={
|
||||
"init":func(end){@end=end; @current=0; @prev=@current},
|
||||
"current":func(){prev},
|
||||
"next":func(){
|
||||
(current <= end) ? [true] {@current=current+1; @prev=current} :: {nil}
|
||||
},
|
||||
"reset":func(){@current=0; @prev=@current}
|
||||
}
|
||||
|
||||
// Example
|
||||
//;
|
||||
//it=$(ds,3);
|
||||
//it++;
|
||||
//it."reset"
|
||||
//it++;
|
||||
//it++;
|
||||
//add(it)
|
||||
|
Loading…
Reference in New Issue
Block a user