This is the mail archive of the guile@cygnus.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: A useful syntax for regexps and other things


> > | If we're going to extend the read syntax, I'd prefer the scsh variant:
> >      #</some funny \\ weird string\/

> But wait a minute.
> Should this syntax really be part of guile-core at all?
> Is it really useful enough to motivate extending the syntax?
> I think the ordinary string notation has enough power.
> 
> /mdj
> 

I share mdj's doubts here.  It seems like a lot of weird syntax just
to be able to type a "\\" without doubling it.  But while we're on the
subject here is my favorite little tweak to string syntax...

Problem: In the middle of some neatly indented code you want to write
a long string.  Guile, like many other Scheme versions, allows you to
write an escaped newline, which results in no character in the string.
Unfortunately, all following lines within the string must be flush left
to prevent unwanted spaces from getting into the string.

Proposal: An escaped line break _and all following white space_
(i.e. leading whitespace on the next line) is translated to nothing in
the string.  To allow you to write leading blanks if you want them, an
escaped blank translates to a blank.  Note that this proposal makes
sense even in a Scheme version based on an archaic character set
without a newline character, and that an un-escaped line break still
works as before, as does an escaped line break followed by a flush left
continuation.

Example:

guile> (display "This is a string with an underlined word \n\
                \                         ----------\n\
                and some stuff \
                broken into small \
                pieces and indented \
                neatly.\n")
This is a string with an underlined word 
                         ----------
and some stuff broken into small pieces and indented neatly.

Patch to do it:

*** read.c.orig	Mon Oct 27 23:21:41 1997
--- read.c	Tue Oct 28 00:21:48 1997
***************
*** 450,456 ****
--- 450,462 ----
  	    switch (c = scm_gen_getc (port))
  	      {
  	      case '\n':
+ 		while (c = scm_gen_getc (port), (c==' ' || c=='\t'))
+ 		  ;
+                 scm_gen_ungetc (c, port);
  		continue;
+ 	      case ' ':
+ 		c = ' ';
+ 		break;
  	      case '0':
  		c = '\0';
  		break;

-- 
     --Keith

This mail message sent by GNU emacs and Linux.
Power to the people. Linux is here.
Food, Shelter, Source code.