Heretical template syntax proposal
Bill Baxter
wbaxter at gmail.com
Wed Oct 22 22:02:55 PDT 2008
In another thread the idea was discussed of using [x] for template arguments.
The main objection to this was that it would be ambiguous with array indexing.
I know [x] has meant array indexing for a long time, but I think
there's not really any longstanding connection between that and any
math notation that existed previously.
In fact (x) is arguably a more mathematical way to index an array. An
array is just a function that given some input returns some output.
So array(i) actually makes a lot of sense.
This is actually how Matlab behaves, in fact. In Matlab you don't
index with [i] you index with (i).
There's no reason as far as I can tell that [i] needs to mean array indexing.
So if you change array indexing to (i) (both std arrays and AAs) then
you can use [x] for template syntax.
I think the ambiguity between arrays and functions that would result
is a non-issue. An array is a kind of function so there's no real
issue. In fact in Matlab you have exactly that ambiguity and it works
just fine. In fact it's even more natural since it allows you to
replace an array with a function any time your app's needs grow beyond
the simple mapping function provided by the array.
Ok, it's probably totally unpalatable to anyone who has ever
programmed in a C family language, but I think it could work if we had
the stomach to do it.
--bb
More information about the Digitalmars-d
mailing list