• Re: CL idioms

    From B. Pym@21:1/5 to Pascal Costanza on Wed Sep 11 04:33:54 2024
    XPost: comp.lang.scheme

    Pascal Costanza wrote:

    In Scheme I would probably do something like (list->vector (reverse
    dict)) but is there a way to build the vector directly without knowing
    the size in advance? Or is there a more "CL" way to do this?

    What about this:

    (with-open-file (str filename :direction :input)
    (loop for line = (read-line str nil 'eof)
    until (eql line 'eof)
    collect line into dict
    finally (return (apply #'vector dict))))

    or:

    (with-open-file (str filename :direction :input)
    (loop for line = (read-line str nil 'eof)
    until (eql line 'eof)
    count t into line-count
    collect line into dict
    finally (return
    (make-array line-count :initial-contents dict))))

    Gauche Scheme

    (use gauche.generator)

    (generator->vector (file->generator "output.dat" read-line))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)