guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help to get this running faster


From: Keisuke Nishida
Subject: Re: help to get this running faster
Date: 05 Sep 2000 03:52:19 -0400
User-agent: T-gnus/6.14.4 (based on Gnus v5.8.6) (revision 02) SEMI/1.13.7 (Awazu) Chao/1.14.0 (Momoyama) Emacs/20.7 (i686-pc-linux-gnu) MULE/4.0 (HANANOEN)

address@hidden (Karl M. Hegbloom) writes:

>     Brad> (define* (load-records fname #&optional (sep #\tab))
>     Brad>   (call-with-input-file fname
>     Brad>     (lambda (i-stream)
>     Brad>       (do ((records '())
>     Brad>        (line (read-line i-stream) (read-line i-stream)))
>     Brad>       ((eof-object? line) records)
>     Brad>     (set! records (append records (list (split-discarding-char sep 
> line list))))))))
> 
>  Rather than using `append' like that, I would use `cons', and finally
>  return `(reverse! records)'.  I think that would be faster.

And you would want to avoid using `set!'.  Probably the simplest way
of doing this is:

(define* (load-records fname #&optional (sep #\tab))
  (with-input-from-file fname
    (lambda ()
      (do ((line (read-line) (read-line))
           (records '() (cons (split-discarding-char sep line list) records)))
          ((eof-object? line) (reverse! records))))))

BTW, there is a procedure `string-tokenize' in SRFI-13.  Has anyone
implemented it?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]