with and checked with expression?

ArturG via Digitalmars-d digitalmars-d at puremagic.com
Wed May 25 06:28:53 PDT 2016


On Wednesday, 25 May 2016 at 00:36:04 UTC, Seb wrote:
> On Tuesday, 24 May 2016 at 19:03:11 UTC, ArturG wrote:
>> would something like this be usefull?
>
> A general word of advice - try to keep your post short & 
> concise. It is more likely to get replies then.
>

Yes i might have used to many examples, should have used dpaste 
for all of them.

> Yes it would be to me, but I am not sure whether it would 
> justify the rather uncommon #{} syntax. Does any language out 
> there use it?
>

The syntax is of course up for debate, but similar to the with 
statement and others it creates its own scope so it should'nt be 
and exception and also use the {}.
Just picked the # because i needed a separator for the input and 
its optional parameters and it's a easy to reach single symbol 
which isnt ambigius with other D symbols.

We cant use the syntax from freatures which provide similar 
functionality from other languages[1], because they use existing 
D syntax and are'nt as flexible as the with expression/statement.

D already has similar syntax for struct initialiser and anonymous 
classes and as it can be chained it also kinda behaves like a 
eagerly called function/delegate.

[1] https://en.wikipedia.org/wiki/Method_cascading

> For the expression?, imho it is very useful - existence checks 
> are very common. I know that at least ruby and CoffeeScript 
> have it. Do you know more?

c#, dart and others but they only have the ?. operator.
c# has ?[ for checked index and you might also want ?( for 
checked opCall which i didnt want to propose because it can be 
done with the with expression.



More information about the Digitalmars-d mailing list