Re: Beginner - Function Critique

Liste des GroupesRevenir à cl scheme 
Sujet : Re: Beginner - Function Critique
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 04. Jul 2025, 14:31:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <1048l43$rd5d$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Bourguignon wrote:

(defun read-file (filename delimiter)
   "Return a list of lists containing strings in pathname FILENAME
delimited by character DELIMITER."
   (let ((output '()))
     (with-open-file (in filename)
       (do ((line (read-line in nil) (read-line in nil)))
           ((null line))
         (push (line-split line delimiter) output))
       (nreverse output))))
 
 
Good.  Eventually, I switched to loop:
 
(defun read-file (filename delimiter)
    "Return a list of lists containing strings in pathname FILENAME
 delimited by character DELIMITER."
   (with-open-file (in filename)
    (loop
      :for line = (read-line in nil)
      :while line
      :collect (line-split line delimiter))))

There is no "line-split" in CL.


Gauche Scheme

(define (read-and-split-lines filename delimiter)
  (with-input-from-file filename
    (lambda()
      (generator-map
        (cut  string-split <> delimiter)
        read-line))))

(read-and-split-lines "input.dat" #\space)
  ===>
(("V0003" "oranges") ("V0002" "foo" "bar") ("V0001" "and" "so" "on")
 ("V0003" "screws") ("V0002" "apples") ("V0003" "glue"))

Date Sujet#  Auteur
4 Jul 25 o Re: Beginner - Function Critique1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal