Changeset 36868 in project


Ignore:
Timestamp:
11/22/18 15:55:55 (3 weeks ago)
Author:
sjamaan
Message:

Also add import to the second example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/chicken-for-python-programmers

    r36867 r36868  
    112112<enscript highlight=scheme>
    113113(import (chicken io))
     114
    114115(call-with-input-file "my-file.txt" (lambda (port) (read-string #f port)))
    115116</enscript>
    116117
    117 {{read-string}} is defined in [[/man/5/Module (chicken io)|the (chicken io) module]]. {{call-with-input-file}} calls its argument procedure with the opened file as an argument. The first argument to {{read-string}} is the limit, which tells it how many characters to read. We use {{#f}} to indicate we want to read everything (no limit).
     118{{read-string}} is defined in [[/man/5/Module (chicken io)|the (chicken io) module]]. This module is not loaded by default, so we import it first.
     119
     120{{call-with-input-file}} calls its argument procedure with the opened file as an argument. The first argument to {{read-string}} is the limit, which tells it how many characters to read. We use {{#f}} to indicate we want to read everything (no limit).
    118121
    119122=== Reading the contents of a file and returning a list of lines
     
    130133==== CHICKEN
    131134<enscript highlight=scheme>
     135(import (chicken io))
     136
    132137(call-with-input-file "my-file.txt" (lambda (port) (read-lines port)))
    133138</enscript>
Note: See TracChangeset for help on using the changeset viewer.