Heretical template syntax proposal (alternate D language syntax)

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Oct 24 06:19:54 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

Hum, that's a hard break from the C language family. Too much of a break 
I think.

Hum, on a side note, that makes me think how it would be like for a 
language like D, with the same semantics as D, but having a completely 
redesigned syntax, from the grounds up. I wonder if there could be 
significant advantages in such a language (in clarity, consistency, 
expressiveness, etc).
Because it is the case that D is continuously getting new additions in 
syntax and semantics. But while semantics are generally easier to change 
and refactor, because there is an infinite "domain space" for semantics, 
the "domain space" for (reasonable) syntax is limited, as we saw 
recently with the desire in the new template instantiation discussions 
about a new kind of brackets. And refactoring/restructuring the syntax 
of a language to accommodate such changes is such a breaking change that 
is nearly impractical without creating a new language.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list