From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.lisp.guile.user Subject: Re: I/O, modules Date: Tue, 13 Nov 2012 10:53:29 +0100 Message-ID: <87r4nxomli.fsf@zigzag.favinet> References: <42782.199.48.147.41.1352786231.squirrel@lavabit.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1352800392 15987 80.91.229.3 (13 Nov 2012 09:53:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Nov 2012 09:53:12 +0000 (UTC) Cc: guile-user@gnu.org To: thorsopia@lavabit.com Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Nov 13 10:53:22 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TYDBI-0005Lp-OE for guile-user@m.gmane.org; Tue, 13 Nov 2012 10:53:20 +0100 Original-Received: from localhost ([::1]:37375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYDB9-0001lM-5p for guile-user@m.gmane.org; Tue, 13 Nov 2012 04:53:11 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:52745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYDB2-0001he-9j for guile-user@gnu.org; Tue, 13 Nov 2012 04:53:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TYDAz-0003kq-7l for guile-user@gnu.org; Tue, 13 Nov 2012 04:53:04 -0500 Original-Received: from smtp206.alice.it ([82.57.200.102]:35508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TYDAy-0003kg-Sf for guile-user@gnu.org; Tue, 13 Nov 2012 04:53:01 -0500 Original-Received: from zigzag.favinet (82.56.5.67) by smtp206.alice.it (8.6.058.01) id 508F91B901E0E423; Tue, 13 Nov 2012 10:52:51 +0100 Original-Received: from ttn by zigzag.favinet with local (Exim 4.72) (envelope-from ) id 1TYDBd-0000Np-Tz; Tue, 13 Nov 2012 10:53:41 +0100 In-Reply-To: <42782.199.48.147.41.1352786231.squirrel@lavabit.com> (thorsopia@lavabit.com's message of "Tue, 13 Nov 2012 00:57:11 -0500 (EST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.102 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9669 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain () thorsopia@lavabit.com () Tue, 13 Nov 2012 00:57:11 -0500 (EST) [...] to read the whole file at once. Should I import some module to get the above functions? Which one? Personally, i would do: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=upcase.out -*- mode: compilation; default-directory: "/tmp/" -*- Compilation started at Tue Nov 13 10:04:09 cd /tmp ; cat upcase ; guile -s upcase upcase to ; echo =/= ; cat to ;;; upcase (use-modules (ttn-do mogrify)) (define (upcase-file i o) (call-with-output-file o (lambda (o) (display (string-upcase (editing-buffer (find-file-read-only i) (buffer-string))) o)))) (apply upcase-file (cdr (command-line))) ;;; upcase ends here =/= ;;; UPCASE (USE-MODULES (TTN-DO MOGRIFY)) (DEFINE (UPCASE-FILE I O) (CALL-WITH-OUTPUT-FILE O (LAMBDA (O) (DISPLAY (STRING-UPCASE (EDITING-BUFFER (FIND-FILE-READ-ONLY I) (BUFFER-STRING))) O)))) (APPLY UPCASE-FILE (CDR (COMMAND-LINE))) ;;; UPCASE ENDS HERE Compilation finished at Tue Nov 13 10:04:09 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable which (trivially) uses module (ttn-do mogrify) for input: If you grep ttn-do, you'll see other examples, most of which do more inside =E2=80=98editing-buffer=E2=80=99 than outside. In various versions = of Guile, there is module =E2=80=98(ice-9 gap-buffer)=E2=80=99, which is "related tec= hnology". [...] problem with modules. How to check what can be imported? You can =E2=80=98(set! %load-verbosely #t)=E2=80=99 to check. On a deeper = level, Guile resolves a module name to a filename using var =E2=80=98%load-path=E2=80=99= , which is initialized from env var =E2=80=98GUILE_LOAD_PATH=E2=80=99 and command-line= arg =E2=80=98-L DIR=E2=80=99 (one or more). By default, cwd is excluded from these, for security. Try to specify it explicitly, e.g.: "guile -L . -s import-test.scm". At least, this is my understanding of Guile 1.x -- maybe 2.0 differs. [clickety click] Hmm, i see you've successfully tempted me into passing a half hour playing w/ this stuff. Well done! Might as well share the fruit. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline; filename=upcase Content-Transfer-Encoding: quoted-printable ;;; upcase ;;; ;;; Usage: guile -s upcase INFILE OUTSTEM ;;; ;;; Description: Upcase INFILE to both OUTSTEM-unsafe, OUTSTEM-safe{1,2}. (use-modules (ttn-do mogrify)) (define (upcase-file i o) ;; unsafe: Output fails silently if =E2=80=98display=E2=80=99 does short = =E2=80=98write=E2=80=99. ;; This occurs for some Guile versions, sometimes. (let ((o (string-append o "-unsafe"))) (call-with-output-file o (lambda (o) (display (string-upcase (editing-buffer (find-file-read-only i) (buffer-string))) o)))) ;; safe1: As long as you have the memory. :-D (let ((o (string-append o "-safe1"))) (editing-buffer (find-file i) (let ((new (string-upcase (buffer-string)))) (delete-region (point-min) (point-max)) (insert new)) (write-to-port (open-output-file o)))) ;; safe2: Like safe1, but w/ a more functional style. (let ((o (string-append o "-safe2"))) (editing-buffer (string-upcase (editing-buffer (find-file-read-only i) (buffer-string))) (write-to-port (open-output-file o)))) ;; Add more shouted mumblings here. ) (apply upcase-file (cdr (command-line))) ;;; upcase ends here --=-=-= Content-Type: text/plain Poking around in ~/codebits/scheme, i also found this: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=upcase.scm #!/usr/local/bin/guile \ -e main -s !# ;;; ID: $Id: upcase.scm,v 1.3 1999/05/15 10:15:31 ttn Exp $ (define (toupper s) (list->string (map (lambda (c) (if (char-lower-case? c) (char-upcase c) c)) (string->list s)))) (define main (lambda args (let r ((form (read-line))) (or (eof-object? form) (begin (write-line (toupper form)) (r (read-line))))) (quit))) ;;; $RCSfile: upcase.scm,v $$Revision: 1.3 $ ends here --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable It operates line at a time, which is nice for pipes, etc... OK, enough! =2D-=20 Thien-Thi Nguyen ..................................... GPG key: 4C807502 . NB: ttn at glug dot org is not me . . (and has not been since 2007 or so) . . ACCEPT NO SUBSTITUTES . ........... please send technical questions to mailing lists ........... --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAlCiGJ0ACgkQZwMiJEyAdQKK6ACeJfiv1gF/ZcZD8+5EhT8U9nqt 0bQAniKmAWWqx4FlE1vKt1dmDmf+KMgT =35Nx -----END PGP SIGNATURE----- --==-=-=--