The stately := operator feature proposal
John Colvin
john.loughran.colvin at gmail.com
Thu May 30 02:16:27 PDT 2013
On Thursday, 30 May 2013 at 00:20:00 UTC, MrzlganeE wrote:
> Hi,
>
> Please consider a request for just one piece of syntax sugar in
> D.
>
> In places where I write a bunch of short mathy code, I do not
> want to use 'auto'. The := operator would allow to declare a
> variable, deduce its type, and define its value.
>
> void main() {
> x := 1;
> y := 2.0;
> z := x * y;
> y = 3.0;
> }
>
> I do not want to see the word 'auto', because it has little to
> do with the problem I am expressing. I find it distracting.
> 'auto' suggests D's type system -- but I am just thinking of
> the algorithm. I want to see less words about the type system,
> and focus my eyes on the problem that I am solving.
>
> I realize that D is not about syntax sugar, but this is
> different:
>
> - It is easily understood by computer scientists, and
> mathematicians coming from many different backgrounds -- it's
> not obscure like a perl syntax construct.
>
> - I would not write 'auto' while expressing an algorithm on a
> whiteboard. But I may very well write :=
>
> - It has a historical record of use in old BNF-grammar
> languages.
>
> - I think people would really *use* it, where they don't want
> to use auto today.
>
> - It's not 'un-C-like' -- it is only not-like-C, because C
> didn't support the feature. It is actually a natural fit!
>
> for (i := 0; i < 24; i++) {
> }
>
> - It is very easily remembered: If you've seen it once, you
> know it.
>
> Today, I would rather write 'double y = 2.0;' than 'auto y =
> 2.0;'
> But := would change that.
>
> Please consider it.
>
> - MrzlganeE
I'm not completely sold. The convenience seems good, but having
declarations and assignments clearly separable is actually rather
nice.
This sort of work would - along with other ideas such as physical
units etc. - be best placed in a lightweight DSL (domain specific
language) that simply hides the necessary mixins etc.
D lends itself to this wonderfully, it would make for a very nice
mathematical/scientific language. I'm almost tempted to make such
a language myself. Integrated with SciD.... ?? Hmmm, I feel a
project coming on.
More information about the Digitalmars-d
mailing list