From Newsgroup: comp.lang.lisp
B. Pym wrote:
(defun read-to-char (c stream)
(loop for x = (read-char stream nil)
while x do (when (char= x c) (return t))))
How verbose!! The function can be expressed much more concisely as:
(defun read-to-char (c stream)
(loop for x = (read-char stream nil)
while x when (char= x c) return t))
or if one doesn't mind the possibility of an extra return value, as:
(defun read-to-char (c stream)
(ignore-errors (loop when (eql (read-char stream) c) return it))
Why is LOOP needed?
Scheme:
(define (read-to-char c port)
(let ((r (read-char port)))
(unless (or (eof-object? r) (eq? c r))
(read-to-char c port))))
Gauche Scheme
(use srfi-121) ; generators
(define (read-to-char c port)
(generator-find (is c) (cut read-char port)))
Given:
(define is
(case-lambda
[(x) (lambda(y) (equal? y x))]
[(pred x) (lambda(y) (pred y x))]
[(pred key x) (lambda(y) (pred (key y) x))]))
--- Synchronet 3.21d-Linux NewsLink 1.2