• Re: Beginner - Function Critique

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Fri Jul 4 13:31:48 2025
    From Newsgroup: comp.lang.lisp

    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"))
    --- Synchronet 3.21d-Linux NewsLink 1.2