Changeset 36866 in project


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

Update file I/O section in CHICKEN for Python programmers to CHICKEN 5 (thanks to Sjors for pointing out the confusing old links)

File:
1 edited

Legend:

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

    r32554 r36866  
    111111==== CHICKEN
    112112<enscript highlight=scheme>
    113 (read-all "my-file.txt")
    114 </enscript>
    115 
    116 {{read-all}} is defined in [[/manual/Unit utils|Unit utils]].
     113(import (chicken io))
     114(call-with-input-file "my-file.txt" (lambda (port) (read-string #f port)))
     115</enscript>
     116
     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).
    117118
    118119=== Reading the contents of a file and returning a list of lines
     
    129130==== CHICKEN
    130131<enscript highlight=scheme>
    131 (read-lines "my-file.txt")
    132 </enscript>
    133 
    134 {{read-lines}} is defined in [[/manual/Unit utils|Unit utils]].
     132(call-with-input-file "my-file.txt" (lambda (port) (read-lines port)))
     133</enscript>
     134
     135{{read-lines}} is also defined in [[/man/5/Module (chicken io)|the (chicken io) module]].
    135136
    136137
Note: See TracChangeset for help on using the changeset viewer.