Heretical template syntax proposal

Janderson ask at me.com
Wed Oct 22 22:36:19 PDT 2008


Bill Baxter wrote:
> 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

Its also the way ADA worked.  It was a great feature because it made 
programming more generic.  Imagine being able to use an array in the 
same template without having to write a wrapper function (and visa 
versa).  Sadly I don't think D will ever adopt this as its a pretty 
radical change from C and D.  Also it means all the libs would have to 
be re-written to work with this when they get ported to D 2 or 3.

-Joel



More information about the Digitalmars-d mailing list