Re: General rule when not to write ;

2021-05-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 19, 2021 at 05:53:12PM +, Alain De Vos via Digitalmars-d-learn 
wrote:
> It seems I need }; for a function a delegate and an alias.
> ```
> double function(int) F = function double(int x) {return x/10.0;};
> double delegate(int)   D = delegate double(int x) {return c*x/10.0;};
> alias myfunx=function int(int number) { return number; };
> ```

The ';' here is for terminating the alias, it is not part of the
delegate.

Basically, the grammar is this:

alias SYMBOL = DEFINITION ;

It just so happens that DEFINITION here is a function literal:

delegate ReturnType(...) { ... }

If you substitute this into the grammar, you get:

alias SYMBOL = delegate ReturnType(...) { ... } ;

That's all there is to it.  This isn't rocket science.


T

-- 
Don't drink and derive. Alcohol and algebra don't mix.


Re: General rule when not to write ;

2021-05-19 Thread Alain De Vos via Digitalmars-d-learn

It seems I need }; for a function a delegate and an alias.
```
double function(int) F = function double(int x) {return x/10.0;};
double delegate(int)   D = delegate double(int x) {return 
c*x/10.0;};

alias myfunx=function int(int number) { return number; };
```


Re: General rule when not to write ;

2021-05-19 Thread Paul Backus via Digitalmars-d-learn

On Wednesday, 19 May 2021 at 13:46:55 UTC, Jesse Phillips wrote:
The ; is used to end a statement, but I don't know how to 
define that and distinguish it from an expression.


An expression has a value. A statement doesn't.

You can add a `;` at the end of an expression to make a statement 
from it. When you do, the value of that expression is discarded.


Re: General rule when not to write ;

2021-05-19 Thread Jesse Phillips via Digitalmars-d-learn

On Tuesday, 18 May 2021 at 16:27:13 UTC, Alain De Vos wrote:

After each } i write a ;
And let the compiler tell me it is an empty instruction.
What are the general rules where ; is not needed after a }


This is a good question, I'm not sure I can provide a concise 
answer.


In general you don't need a ; after }

The ; is used to end a statement, but I don't know how to define 
that and distinguish it from an expression.


The {} create a block of code, usually they will contain 
statements, so it would be common to see ; inside.


The only real time I would expect a }; is when you're defining a 
lambda/delegate and assigning to a variable.


auto Foo = X;

If X is something that ends with } we will still expect a ; to 
end the statement.


Re: General rule when not to write ;

2021-05-18 Thread FeepingCreature via Digitalmars-d-learn

On Tuesday, 18 May 2021 at 16:27:13 UTC, Alain De Vos wrote:

After each } i write a ;
And let the compiler tell me it is an empty instruction.
What are the general rules where ; is not needed after a }


Is `;` ever needed after a `}`?

I guess in `void delegate() dg = { writeln!"Hello World"; };`, 
but that hardly counts, because it belongs to the variable 
declaration, not the `{}`.


General rule when not to write ;

2021-05-18 Thread Alain De Vos via Digitalmars-d-learn

After each } i write a ;
And let the compiler tell me it is an empty instruction.
What are the general rules where ; is not needed after a }