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: Optional Arguments (was Re: CVS script)


> How did DSSL get to have #! as the marker for `optional' and
> suchlike, anyhow?  It seems to me a very poor choice of characters
> for that.  Makes me think that the folks involved in that must not
> use Unix at all...  weird.

[This response may ramble slightly, and I will suggest solutions
that are not necessarily my recommendations.  These are meant to
illuminte my point that this complaint is unfounded.]

Well, lots of people use Unix without writing shell-scripts.
But in any case, they were defining a programming language,
not an extension to shell scripts.  It is not clear to me why
the Bourne shell comment syntax really should be an issue for
a programming language that has a very differnt syntax, and that
uses shell's comment character for other pruposes.

# is just not a comment character in Scheme or DSSSL, and it
can't be.  You can argue that #! should be reserved - but
why should it be?

What you want want a file to contain instructions in two different
syntaxes:  Scheme/DSSSL. plus the magic #! header.  Fine, but
the header is not part of the Scheme/DSSL program.  Consider
a MIME header - that is *not* part of a MIME body, and it would
be unreasonable to expect that MIME headers be valid comment syntax
for any MIME body.

There is no reason why a file with a #! header needs to be a
valid Scheme file.  It is a minor convenience, nothing more.

Conceptually, you should do something like this:

	#/bin/sh
	sed -e '1,3d' < $0 | guile
	exit
	(define ...)

This makes it clear that the Scheme code is separate from the script.

Now, in practice, it is convenient to not have to reun sed:  It is
faster that way, for one thing.  Fine, add a Guile option telling
to skip a #! header.

	#/bin/sh
	guile --script "$@"
	exit
	(define ...)

Of course, you don't want to start /bin/sh either.  Fine:

	#/usr/bin/guile --script
	(define ...)

Or better yet, use the existing meta-arg feature to indicate the
input file starts out with a script header, before the actual
Scheme code.

Or of course, you can add an extension to the Scheme lexer to that
an *initial #! is special, or treat #!/ specially.  That is more
convenient still.

Finally, my recommendation:
Treat "#!" followed by (optional spaces then) "/" as a comment
start, in a way compatible with Guile and scsh.  "#!" followed by a
letter is one of the special tokens.  "#!" followed by anything else
is an error.  Voila, problem solved, in a clean way that does not
require any magic, that is compatible with most existing uses, and
that is copatible with the DSSSL ISO standard.

> How entrenched is that "standard" anyhow?

It's an ISO standard.  It's pretty entrenched, in the sense that
you're not going to change it.  (You're free to ignore it, of course.)
While DSSSL has not seem tramedous amount of use, it is used for
the Docbook tools which Gnome, Linux Dcouemntation project, Cygnus,
and others are using or moving towards.

> How hard would it be to write a perl program to transform everyone's
> DSSL programs to the new syntax?  Seems like changing that in the
> DSSL implementations themselves would involve little more than a
> search and replace anyhow.

That is not going happen.  Just accept it.  No-one is going to
be interested in doing that to solve a non-existant problem.

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner