Re: case and quoted keys - a misunderstanding

Liste des GroupesRevenir à cl lisp 
Sujet : Re: case and quoted keys - a misunderstanding
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 16. Jun 2025, 07:41:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102oeb9$1fjbd$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
  (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))))

Date Sujet#  Auteur
16 Jun 25 * Re: case and quoted keys - a misunderstanding2B. Pym
23 Jun 25 `- Re: case and quoted keys - a misunderstanding1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal