RosettaCodeData/Task/Read-a-specific-line-from-a-file/Factor/read-a-specific-line-from-a-file.factor
2023-07-01 13:44:08 -04:00

15 lines
372 B
Factor

USING: continuations fry io io.encodings.utf8 io.files kernel
math ;
IN: rosetta-code.nth-line
: nth-line ( path encoding n -- str/f )
[ f ] 3dip '[
[ _ [ drop readln [ return ] unless* ] times ]
with-return
] with-file-reader ;
: nth-line-demo ( -- )
"input.txt" utf8 7 nth-line [ "line not found" ] unless*
print ;
MAIN: nth-line-demo