www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Syntactical sugar for string templates and lambdas?

reply "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
I have spent some time thinking about how the D syntax can be 
polished by adding sugar. I wonder if this would be possible to 
implement in the parser:


IN:
(int`x + int`y) * `y

OUT:
(int __1,int __2) => (__1 + __2) * __2


IN:
callTemplate!(`mycmp`(`a,1+2))

OUT:
calltemplate!("mycmp(a," ~ __to_string( 1+2 ) ~ ")")



Ola.
Aug 26 2014
next sibling parent "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Tuesday, 26 August 2014 at 10:10:07 UTC, Ola Fosheim Grøstad 
wrote:
 IN:
 (int`x + int`y) * `y

 OUT:
 (int __1,int __2) => (__1 + __2) * __2
And in case anyone wonders, I was thinking that perhaps the order of the parameters could be lexical, so you get the transforms: IN: int`y < int`x OUT: (int x, int y) => y<x IN: int`y + func( `(int`b + `x) ) * int`x OUT: (int x,int y) => y + func( (int b)=> b+x ) + x Or if the contexts impose signatures that can be used for type deduction: IN: `y < `x OUT: (x,y) => y<x IN: `y + func( `b + `x ) * `x OUT: (x,y) => y + func( (b)=> b+x ) + x
Aug 26 2014
prev sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Tuesday, 26 August 2014 at 10:10:07 UTC, Ola Fosheim Grøstad 
wrote:
 I have spent some time thinking about how the D syntax can be 
 polished by adding sugar. I wonder if this would be possible to 
 implement in the parser:


 IN:
 (int`x + int`y) * `y

 OUT:
 (int __1,int __2) => (__1 + __2) * __2


 IN:
 callTemplate!(`mycmp`(`a,1+2))

 OUT:
 calltemplate!("mycmp(a," ~ __to_string( 1+2 ) ~ ")")
Apart from the fact that I find this harder to read than simply spelling it out: Backticks are already used for wysiwyg strings. It's almost impossible to reuse them for anything else.
Aug 26 2014
parent "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Tuesday, 26 August 2014 at 11:32:58 UTC, Marc Schütz wrote:
 Apart from the fact that I find this harder to read than simply 
 spelling it out: Backticks are already used for wysiwyg 
 strings. It's almost impossible to reuse them for anything else.
Pretend I use forward-ticks ´x+´y :-) What is hard to read depends on what you are used to, but declaring symbols to "not be evaluated here" by prefixing them with a "tick" seems to carry the semantics better than using string mixins and achieve a more concise syntax?
Aug 26 2014