This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: help to get this running faster
- To: karlheg at bittersweet dot inetarena dot com (Karl M. Hegbloom)
- Subject: Re: help to get this running faster
- From: Keisuke Nishida <kxn30 at po dot cwru dot edu>
- Date: 05 Sep 2000 03:52:19 -0400
- Cc: Brad Knotwell <knotwell at ix dot netcom dot com>, guile-user at gnu dot org
- List-Id: <guile-user.gnu.org>
- References: <200009030352.UAA01306@ix.netcom.com><87zoln1u5h.fsf@bittersweet.intra>
karlheg@bittersweet.inetarena.com (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?
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user