Re: CL idioms

Liste des GroupesRevenir à cl lisp 
Sujet : Re: CL idioms
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 11. Sep 2024, 06:33:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbr6je$3efqg$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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))

Date Sujet#  Auteur
11 Sep 24 o Re: CL idioms1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal