Thread overview
Re: new D2.0 + C++ language
Mar 21, 2009
bearophile
Mar 21, 2009
bearophile
Mar 21, 2009
Daniel Keep
March 21, 2009
Yigal Chripun:
> what you suggest is C++ with better syntax, *NOT* a variant of D. for that look at: http://en.wikipedia.org/wiki/Significantly_Prettier_and_Easier_C%2B%2B_Syntax

Thank you for the link, I did know only "A Modest Proposal: C++ Resyntaxed". In some situations that SPECS syntax is more readable than D syntax:

Function having an int argument and returning pointer to float:
(int -> ^float)

Pointer to function having an int and float argument returning nothing:
^(int, float -> void)

Note that SPECS uses  ^  :=  and  =  as in Pascal.
Pointer syntax of Pascal is better, and the :=  = often avoid the C bugs like if(a = b).

But probably D needs to tell apart functions and delegates too, so that syntax isn't enough. And I think now it's not easy to change the meaning of  ^ in D :-)

So a possibility (keeping the usual * pointer syntax):
{int => int}
Delegate:
{{int => int}}
That can also offer a syntax for anonymous functions/delegates:
{int x => x*x}
{x => x*x}
{{x => x*x}}

Bye,
bearophile
March 21, 2009
On Fri, Mar 20, 2009 at 10:31 PM, bearophile <bearophileHUGS@lycos.com> wrote:

> Note that SPECS uses  ^  :=  and  =  as in Pascal.
> Pointer syntax of Pascal is better, and the :=  = often avoid the C bugs like if(a = b).

Which isn't a problem in D ;)

> That can also offer a syntax for anonymous functions/delegates:
> {int x => x*x}
> {x => x*x}
> {{x => x*x}}

That's actually pretty nice.
March 21, 2009
Jarrett Billingsley:
> > Pointer syntax of Pascal is better, and the :=  = often avoid the C bugs like if(a = b).
> 
> Which isn't a problem in D ;)

Let's say D has a workaround to patch most of that C-syntax hole :-) And I'll never like C pointer syntax.


> That's actually pretty nice.

An alternative syntax that avoids the two nested {{}}:
Lambda functions:
{int x -> x*x}
{x -> x*x}
{float x, float x*y}
Lambda delegates:
{int x => x*x}
{x => x*x}
{float x, float y => x*y}

I may even like that :-)

Bye,
bearophile
March 21, 2009

bearophile wrote:
> Jarrett Billingsley:
>>> Pointer syntax of Pascal is better, and the := �= often avoid the C bugs like if(a = b).
>> Which isn't a problem in D ;)
> 
> Let's say D has a workaround to patch most of that C-syntax hole :-) And I'll never like C pointer syntax.
> 
> 
>> That's actually pretty nice.
> 
> An alternative syntax that avoids the two nested {{}}:
> Lambda functions:
> {int x -> x*x}
> {x -> x*x}
> {float x, float x*y}
> Lambda delegates:
> {int x => x*x}
> {x => x*x}
> {float x, float y => x*y}
> 
> I may even like that :-)
> 
> Bye,
> bearophile

{ int -> int } // function
{ this int -> int } // delegate

Not saying I support this syntax; just proposing an alternative.  The way I see it, there's no reason why functions are -> and delegates are =>; the difference is non-obvious.

  -- Daniel