[bitc-dev] Opinions wanted: Infix shift operators

Christopher Gilbreth cngilbreth at gmail.com
Wed Jul 28 14:01:17 PDT 2010


On Wed, Jul 28, 2010 at 2:51 PM, Jonathan S. Shapiro <shap at eros-os.org>wrote:

> On Tue, Jul 27, 2010 at 11:18 PM, Christopher Gilbreth
> <cngilbreth at gmail.com> wrote:
> > Hi,
> > I would suggest using double square brackets [[ and ]]:
> >
> > int f[['a, 'b]](arg1, arg2) { ... }
>
> Unfortunately, doubling up the brackets doesn't eliminate the
> ambiguity with array indexing. You can have nested array references
> too:
>
>    a[b[i]]
>
>
That's only ambiguous for a very dumb tokenizer, though. Just keeping a
stack of the current open brackets would solve the problem: when the
tokenizer encounters a ']', it can look at the top of its stack for the most
recent open bracket it's seen. If it was '[', then the tokenizer parses ']'.
If it was '[[', then the next character after the current one (']') must be
']', otherwise it's a parse error. In general, any closing bracket
encountered must match the most recent open bracket seen (correct?). This is
fundamentally different from the case for the angle brackets '<<' and '>>',
since '>>' may not be two brackets, but an infix operator.

Also, I would expect that keeping a stack of the open brackets would be much
easier than distinguishing between expression contexts and type contexts.
The former can be done with a pure tokenizer -- no semantic information
required!

> Actually, I would like to take this one step further and suggest that [[
> and
> > ]] be ASCII synonyms for the Unicode characters U+27E6 and U+27E7:
> > > http://www.decodeunicode.org/en/u+27e6
> > http://www.decodeunicode.org/en/u+27e7
>
 Now *that* would solve the ambiguity. But quick: where is the u+27e6
> key on your keyboard?
>

Of course I agree there must be an ascii equivalent. But on the other hand,
we also don't live in 1980 -- we can find easy ways of inserting these
characters. This is a bit off-topic, but I have one for Emacs that I use for
inserting Greek and other characters: to type, say, Greek lowercase alpha, I
type 'a', then hit a pre-assigned key (I have it set to backtick '`', bit it
could just as easily be F1, or any key combination you like) to cycle
through alternatives. So 'a' <cycle> yields 'α'. Hitting the cycle key again
goes back to 'a'. Similarly 'A' <cycle> yields ∀ (the forall symbol),
<cycle> again yields ℵ (Hebrew Aleph character), and cycling again goes back
to 'A'. I took the idea from TeXmacs  (www.texmacs.org). It took me all of a
few hours to write. I've been meaning to put this on the web somewhere, but
haven't done so yet.


> Using this sort of thing for pretty printing and accepting it as input
> is fine, but the ascii version needs to work too.
>

And it does! :-)

Cheers,
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.coyotos.org/pipermail/bitc-dev/attachments/20100728/47066ded/attachment.html 


More information about the bitc-dev mailing list