some expression and data files used by tests

This commit is contained in:
Celestino Amoroso 2024-05-03 08:48:29 +02:00
parent 0bca3333aa
commit 7a0ba26aa3
3 changed files with 55 additions and 0 deletions

33
file-reader.expr Normal file
View 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)

4
int.list Normal file
View File

@ -0,0 +1,4 @@
10
20
5
12

18
iterator.expr Normal file
View 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)