From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.lisp.guile.user Subject: Re: How to read from a file Date: Fri, 18 Jun 2010 18:21:40 +0200 Organization: Decebal Computing Message-ID: <87zkysb9bf.fsf@linux-lqcw.site> References: <878w6ccsz9.fsf@linux-lqcw.site> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1276878078 9762 80.91.229.12 (18 Jun 2010 16:21:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 Jun 2010 16:21:18 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jun 18 18:21:16 2010 connect(): No such file or directory Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OPeJf-0004Dz-Ia for guile-user@m.gmane.org; Fri, 18 Jun 2010 18:21:15 +0200 Original-Received: from localhost ([127.0.0.1]:42223 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPeJe-0002cx-OE for guile-user@m.gmane.org; Fri, 18 Jun 2010 12:21:14 -0400 Original-Received: from [140.186.70.92] (port=44980 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OPeJX-0002bE-38 for guile-user@gnu.org; Fri, 18 Jun 2010 12:21:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OPeJV-0002JI-MW for guile-user@gnu.org; Fri, 18 Jun 2010 12:21:07 -0400 Original-Received: from smtp-vbr13.xs4all.nl ([194.109.24.33]:2160) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OPeJV-0002J4-Ch for guile-user@gnu.org; Fri, 18 Jun 2010 12:21:05 -0400 Original-Received: from linux-lqcw.site (84-53-123-169.wxdsl.nl [84.53.123.169]) by smtp-vbr13.xs4all.nl (8.13.8/8.13.8) with ESMTP id o5IGL2T4051687 for ; Fri, 18 Jun 2010 18:21:03 +0200 (CEST) (envelope-from Cecil@decebal.nl) In-Reply-To: <878w6ccsz9.fsf@linux-lqcw.site> (Cecil Westerhof's message of "Fri, 18 Jun 2010 16:31:38 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Homepage: http://www.decebal.nl/ X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7898 Archived-At: Op vrijdag 18 jun 2010 16:31 CEST schreef Cecil Westerhof: > When looking at: > http://www.gnu.org/software/guile/docs/faq/OLD-guile-faq.html > > The following code should work: > #!/usr/bin/guile \ > -e main -s > !# > (use-modules (ice-9 readline)) > (activate-readline) > > (define (main args) > (let ((input-file (cadr args)) > (output-file (caddr args))) > (with-input-from-file input-file > (lambda () > (while (not (eof-object? (peek-char))) > (display (read-line)) > (newline)))))) > > But when executing it, I get: > ERROR: Unbound variable: read-line > > What am I doing wrong? I found it: #!/usr/bin/guile \ -e main -s !# (use-modules (ice-9 readline)) (use-modules (ice-9 rdelim)) (activate-readline) (define (main args) (let ((input-file-name (cadr args)) (output-file-name (caddr args)) (input-file "") (output-file "") (this-line "")) (set! input-file (open-file input-file-name "r")) (set! output-file (open-file output-file-name "w")) (while (not (eof-object? (peek-char input-file))) (set! this-line (read-line input-file)) (write-line this-line output-file) ) (close-port output-file) (close-port input-file))) A file of 5.000.000 lines and 163 MB is processed in 26 seconds. At the moment it is just copying, but that is properly the most expensive part. There should be some error checking and the processing should be done, but that is the next step. Could this be done more efficient? By the way, it is not that bad. My Emacs Lisp code takes about two times as long. It does also a replace, but that will not take 50% of the time. So it looks like Guile has a good performance notwithstanding that it is said that Guile's IO performance is not very fast at the moment. It is about as fast as a Perl script. The problem with the Perl script is that it only works with ASCII. It goes wrong on files that contain other characters. That is why I at the moment use the Emacs Lisp script. I am wondering what will happen when Guile's IO performance becomes good. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof