• Re: Style question

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 30 01:09:30 2025
    From Newsgroup: comp.lang.lisp

    Rob Warnock wrote:

    (defun file-forms (path)
    "Sucks up an entire file from PATH into a list of forms (sexprs),
    returning two values: the list of forms and the number of forms read."
    (with-open-file (s path)
    (loop with eof = (list :eof)
    for form = (read s nil eof)
    until (eq form eof)
    collect form into forms
    counting t into form-count
    finally (return (values forms form-count)))))

    Gauche Scheme

    (use srfi-42) ;; list-ec

    (define (file-forms file)
    (let ((count 0))
    (values
    (call-with-input-file file
    (lambda (inport)
    (list-ec
    (:port form inport read)
    (begin (inc! count))
    form)))
    count)))
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jun 30 10:07:19 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    Rob Warnock wrote:

    (defun file-forms (path)
    "Sucks up an entire file from PATH into a list of forms (sexprs),
    returning two values: the list of forms and the number of forms read."
    (with-open-file (s path)
    (loop with eof = (list :eof)
    for form = (read s nil eof)
    until (eq form eof)
    collect form into forms
    counting t into form-count
    finally (return (values forms form-count)))))

    Gauche Scheme

    (use srfi-42) ;; list-ec

    (define (file-forms file)
    (let ((count 0))
    (values
    (call-with-input-file file
    (lambda (inport)
    (list-ec
    (:port form inport read)
    (begin (inc! count))
    form)))
    count)))

    Gauche Scheme

    (define (file-forms file)
    (with-input-from-file file
    (lambda()
    (do ((x #f)
    (forms () (cons x forms))
    (i 0 (+ 1 i)))
    ((eof-object? (set! x (read)))
    (values (reverse forms) i))))))


    --- Synchronet 3.21d-Linux NewsLink 1.2