This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: help to get this running faster


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]