SketchyLISP Stuff | Copyright (C) 2006 Nils M Holm |
[ More Sketchy LISP Stuff ] |
Conformance: R5RS
Purpose: Read a newline-terminated sequence of characters. Return a string containing the characters read.
Implementation:
(define (read-line) (letrec ((collect-chars (lambda (c s) (cond ((or (eof-object? c) (char=? c #\newline)) (apply string (reverse s))) (#t (collect-chars (read-char) (cons c s)))))) (first-char (read-char))) (cond ((eof-object? first-char) first-char) (#t (collect-chars first-char '())))))
Example:
(read-line) hello world => " hello world "
[ More Sketchy LISP Stuff ] |