mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Added read-string
This commit is contained in:
parent
e68c275af4
commit
9e5c1d963e
1 changed files with 21 additions and 2 deletions
|
@ -109,6 +109,7 @@
|
|||
write-string
|
||||
flush-output-port
|
||||
read-line
|
||||
read-string
|
||||
input-port?
|
||||
output-port?
|
||||
input-port-open?
|
||||
|
@ -193,7 +194,6 @@
|
|||
; letrec*
|
||||
; letrec-syntax
|
||||
; parameterize
|
||||
; read-string
|
||||
; record?
|
||||
; syntax-error
|
||||
; syntax-rules
|
||||
|
@ -521,8 +521,27 @@
|
|||
(func (car lst) (foldr func end (cdr lst)))))
|
||||
(define (read-line . port)
|
||||
(if (null? port)
|
||||
(Cyc-read-line (current-output-port))
|
||||
(Cyc-read-line (current-input-port))
|
||||
(Cyc-read-line (car port))))
|
||||
(define (read-string k . opts)
|
||||
(let ((port (if (null? opts)
|
||||
(current-input-port)
|
||||
(car opts))))
|
||||
(let loop ((acc '())
|
||||
(i k)
|
||||
(chr #f))
|
||||
(cond
|
||||
((eof-object? chr)
|
||||
(list->string
|
||||
(reverse acc)))
|
||||
((zero? i)
|
||||
(list->string
|
||||
(reverse
|
||||
(if chr (cons chr acc) acc))))
|
||||
(else
|
||||
(loop (if chr (cons chr acc) acc)
|
||||
(- i 1)
|
||||
(read-char port)))))))
|
||||
(define (flush-output-port . port)
|
||||
(if (null? port)
|
||||
(Cyc-flush-output-port (current-output-port))
|
||||
|
|
Loading…
Add table
Reference in a new issue