Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Re: reading a file into a string
William James
2/1/2016 6:28:00 PM
Dr. Edmund Weitz wrote:
> I want to read a whole (text) file into a string. And I wonder what
> would be the best way to do it.
>
> With CMUCL I would to do something like
>
> (defun file-size (file-name)
> (let* ((result (multiple-value-list (unix:unix-stat file-name)))
> (ok (car result)))
> (if ok
> (nth 8 result)
> (error "Couldn't stat file ~S" file-name))))
>
> (defun string-from-file (file-name &key (max-size 4096))
> (let ((size (file-size file-name)))
> (when (> size max-size)
> (error "File ~S is too large" file-name))
> (let ((string (make-string size)))
> (with-open-file (stream file-name)
> (read-sequence string stream))
> string)))
>
> My questions are:
>
> 1. Is this solution efficient and OK or are there any significant
> reasons to use a different approach?
>
> 2. Is there an ANSI-compliant solution that is comparable in
> performance? Maybe something along the lines of Bulent
> Murtezaoglu's solution that can be found at
MatzLisp (Ruby):
IO.read("input.dat")
--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: reading a file into a string
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password