file-reader.expr: simpler implementation
This commit is contained in:
parent
b1d6b6de44
commit
866de759dd
@ -1,23 +1,22 @@
|
|||||||
builtin ["os.file", "base"];
|
builtin ["os.file", "base"];
|
||||||
|
|
||||||
readInt=func(fh){
|
readInt=func(fh){
|
||||||
line=fileRead(fh);
|
line=fileReadText(fh);
|
||||||
line ? [nil] {nil} :: {int(line)}
|
line ? [nil] {nil} :: {int(line)}
|
||||||
};
|
};
|
||||||
|
|
||||||
ds={
|
ds={
|
||||||
"init":func(filename){
|
"init":func(filename){
|
||||||
fh=fileOpen(filename);
|
fh=fileOpen(filename);
|
||||||
fh ? [nil] {nil} :: { @current=readInt(fh); @prev=@current };
|
fh ? [nil] {nil} :: { @current=readInt(fh) };
|
||||||
fh
|
fh
|
||||||
},
|
},
|
||||||
"current":func(){
|
"current":func(){
|
||||||
prev
|
current
|
||||||
},
|
},
|
||||||
"next":func(fh){
|
"next":func(fh){
|
||||||
current ?
|
@current=readInt(fh);
|
||||||
[nil] {current}
|
current
|
||||||
:: {@prev=current; @current=readInt(fh) but current}
|
|
||||||
},
|
},
|
||||||
"clean":func(fh){
|
"clean":func(fh){
|
||||||
fileClose(fh)
|
fileClose(fh)
|
||||||
@ -25,9 +24,9 @@ ds={
|
|||||||
}
|
}
|
||||||
|
|
||||||
//;f=$(ds, "int.list")
|
//;f=$(ds, "int.list")
|
||||||
/*
|
|
||||||
;f++
|
//;f++
|
||||||
;f++
|
//;f++
|
||||||
;f++
|
//;f++
|
||||||
*/
|
//*/
|
||||||
//;add(f)
|
//;add(f)
|
||||||
|
Loading…
Reference in New Issue
Block a user