Re: lisp idiom for processing each line in a file?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: lisp idiom for processing each line in a file?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 30. Jun 2025, 17:34:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103uebf$29av8$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:

 
Gauche Scheme:
 
(with-input-from-file "data.bak"
  (^()  (do ((line #f))
          ((eof-object? (set! line (read-line))))
          (print line))))

One could do it this way, but the repetition of "read-line"
is clunky.

(with-input-from-file "data.bak"
  (^() (do ((line (read-line) (read-line)))
         ((eof-object? line))
         (print line))))

Let's use "<>" (it's used in the macro "cut") to indicate
duplication of the preceding expression.

(with-input-from-file "data.bak"
  (lambda()
    (do. ((line (read-line) <>))
       ((eof-object? line))
       (print line))))

(define-syntax do.-aux
  (syntax-rules  ( <> )
    [ (do.-aux ((v init <>) more ...) seen stuff ...)
      (do.-aux ((v init init) more ...) seen stuff ...) ]
    [ (do.-aux (what more ...) (seen ...) stuff ...)
      (do.-aux (more ...) (seen ... what) stuff ...) ]
    [ (do.-aux () seen stuff ...)
      (do seen stuff ...) ] ))

(define-syntax do.
  (syntax-rules ()
    [ (do. (things ...) more ...)
      (do.-aux (things ...) () more ...) ] ))
 

Date Sujet#  Auteur
30 Jun 25 * Re: lisp idiom for processing each line in a file?2B. Pym
30 Jun 25 `- Re: lisp idiom for processing each line in a file?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal