[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What SHOULD happen if a line begins with ()?

What SHOULD happen if you're reading an I-expression, and
a line begins with ( after whitespace?
I notice that none of the examples of I-expressions have lines beginning with "(",
and I think the text isn't clear about this.
(I'm not sure I'm supposed to take the
implementation code as normative.)

I _think_ what might be valuable would be setting up the rules
so that if you accidentally fed non-I-expression code in, it would be
accepted "as normal".  (I actually think that I-code should NOT be
the default, but that you'd need to turn it on, but there are values
in having it be a "safe" format).

I _think_ that what should happen is the something like the following:
* If the I-expression syntax WOULD NOT have added a "(",
   i.e., we're at the same or lower indentation, accept it.
* If the I-expression syntax WOULD have added a "(" in the s-expression,
   Skip the FIRST "(" in the line, and skip its matching ")"
   (by "matching" I mean "as if you had NOT skipped it).
* Initially we're at column 1.

That way, pretty-printed Scheme would also be legal I-expressions,
with the same meaning.  E.G., this is legal (note the "((" beginning a line):
 (define (tester) 
    ((lambda (a b) (+ a b)) 1 2))


Taylor Campbell earlier said:
> What about files where the whole file is wrapped in some form, but
>nothing has extra indentation?  This is found in a _lot_ of libraries
>for PLT, for instance:
>(module foo mzscheme
>  (require bar)
>  (provide baz)
>;; The top-level forms in the module body have no indentation.
>(define (mumble frotz) (garglemumph quux))
>(define (baz ...) ...)

Note that the (define...) have the same indentation as (module...)
but are actually inside.  One approach might be this simple rule:
"An open '(' on column 1 disables I-expressions, and normal
s-expression reading occurs until the s-expression closes".
That has a big disadvantage, namely, now it matters whether something
starts on the left edge or not. I don't think that would be a great idea;
instead, best to require people to enable it to use it, and just
spec the enabling mechanism.  But I'd like to know what others think.

Thanks.  I'm sending several comments on this idea, because I
think it's a neat idea, and it's worth emulating on other Lispy languages too.

--- David A. Wheeler