Skip to main content

patch_seq_file_for_each_line

Function patch_seq_file_for_each_line 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn patch_seq_file_for_each_line( stack: Stack, ) -> Stack
Expand description

Process each line of a file with a quotation

Stack effect: ( String Quotation – Bool )

Opens the file, calls the quotation with each line (including newline), then closes the file.

Returns true on success (including empty files), false if the file could not be opened or a read error occurred mid-stream.

The quotation should have effect ( String – ), receiving each line and consuming it. Empty files return success without calling the quotation.

§Line Ending Normalization

Line endings are normalized to \n regardless of platform. Windows-style \r\n endings are converted to \n. This ensures consistent behavior when processing files across different operating systems.

§Example

"data.txt" [ string-chomp process-line ] file-for-each-line
[ "Done processing" write_line ]
[ "Error reading file" write_line ]
if

§Safety

  • stack must be a valid, non-null stack pointer
  • Top of stack must be a Quotation or Closure
  • Second on stack must be a String (file path)