From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Richard Todd Newsgroups: gmane.lisp.guile.user Subject: Use [ ] as parens in guile Date: Sun, 11 Jan 2004 02:21:19 -0600 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <20040111082119.GA952@Richard-Todds-Computer.local> Reply-To: Richard Todd NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0357292514==" X-Trace: sea.gmane.org 1073810159 13498 80.91.224.253 (11 Jan 2004 08:35:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Jan 2004 08:35:59 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jan 11 09:35:56 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Afb4e-0004EB-00 for ; Sun, 11 Jan 2004 09:35:56 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Afc1W-0004T2-UH for guile-user@m.gmane.org; Sun, 11 Jan 2004 04:36:46 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Afc08-000476-T9 for guile-user@gnu.org; Sun, 11 Jan 2004 04:35:20 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Afbza-0003do-Vb for guile-user@gnu.org; Sun, 11 Jan 2004 04:35:18 -0500 Original-Received: from [199.232.41.8] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.24) id 1Afbza-0003dj-JN for guile-user@gnu.org; Sun, 11 Jan 2004 04:34:46 -0500 Original-Received: from [66.171.156.89] (helo=Richard-Todds-Computer.local) by mx20.gnu.org with esmtp (Exim 4.24) id 1AfaqW-0000aM-On for guile-user@gnu.org; Sun, 11 Jan 2004 03:21:20 -0500 Original-Received: by Richard-Todds-Computer.local (Postfix, from userid 501) id 8D2A383FE5; Sun, 11 Jan 2004 02:21:20 -0600 (CST) Original-To: guile-user@gnu.org User-Agent: Mutt/1.4.1i X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.lisp.guile.user:2573 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2573 --===============0357292514== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="DKU6Jbt7q3WqK7+M" Content-Disposition: inline --DKU6Jbt7q3WqK7+M Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi...I've seen a request from time to time in the history of guile (via google) to allow #\[ and #\] to work as parens. Other schemes support this, and apparently some people have gotten used to them. Well, as a fun exercise I hacked up a module that you use with #:use-syntax which allows this for all parens except the outermost parens of an expression. There should be no performance penalty once your module has been read in, but that initial load will take a hit with this implementation since it basically forces the reader to read each expression twice. Anyway, I thought I'd post it in case some of the people wanting this ability are still out there. It seems to work on the code I throw at it, but please let me know if you encounter any problems. This module (along with two modules that allow you to have alternative keyword syntaxes-- keyw: and :keyw) will be in the next release of my guile library. Hopefully savannah will be able to approve my project entry soon. Here's an example use (it's the let construction that people mostly seem to like doing with brackets): ------------------------ (define-module (tst)=20 #:use-syntax (guile-syntax square-parens)) (let ([a (+ 15 3)] [b 5] [c 6]) (display (+ a b c))) (newline) ;; more complicated expression.... (display [+ [+ [[if [=3D 0 1] + -] 5 1] 2]]) (newline) (display "[I am not confused by] [brackets] [in] [[text]") (display #\[) (display #\])(newline) ;; [brackets] [in comments] [obviously wouldn't count either!] --------------------- Richard Todd --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="square-parens.scm" Content-Transfer-Encoding: quoted-printable (define-module (guile-syntax square-parens)=20 #:export (square-parens) #:use-module (ice-9 regex)) (define (square-parens exp) (read=20 (open-input-string (with-output-to-string (lambda () (transform-input exp)))))) (define (transform-input exp) ;; we basically want to (write exp), except for the symbols, which we need ;; to check for #\[ and #\] along the way. ;; ;; We can't just regexp-substitute the whole thing, because someone could h= ave ;; brackets in strings, etc., and we don't want to harm those. (cond=20 ;; lists and pairs ((pair? exp) (display " ( ") (let lp ((elt exp)) (let ((rest (cdr elt))) (transform-input (car elt)) (cond ((pair? rest) (lp rest)) ((null? rest) (display " ) ")) (else (display " . ") (lp (cons rest '()))))))) ;; vectors ((vector? exp) (display " #( ") (let lp ((i 0)) (if (>=3D i (vector-length exp)) #t (begin (transform-input (vector-ref exp i)) (lp (+ i 1))))) (display " ) ")) ;; symbols ((symbol? exp) (regexp-substitute/global=20 (current-output-port) "\\[|\\]" (with-output-to-string (lambda () (write exp))) 'pre (lambda (match)=20 (if (string=3D? (match:substring match) "[") "(" ")")) 'post) (display " ")) ;; all others... (else (write exp) (display " ")))) --Nq2Wo0NMKNjxTN9z-- --DKU6Jbt7q3WqK7+M Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (Darwin) iD8DBQFAAQd/a9lhNGIqsRIRAmtPAJ0ZPaBeD3BgEN9cYU4MFZ86xE49AgCeIbLV 8eg04+GMvIeCwDvgxNFZP1o= =Njn5 -----END PGP SIGNATURE----- --DKU6Jbt7q3WqK7+M-- --===============0357292514== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user --===============0357292514==--