Re: Is variable void?

2017-11-27 Thread codephantom via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:

null != void



also...void is a completely useless concept for initialisation.

what can you determine about the nothingness of void? ... nothing.


writeln(typeof(void).stringof); // ?? what do I know now? nothing.

vs

Nullable!int x;
writeln(typeof(x).stringof); // Nullable!int .. now I know 
something.





Re: Is variable void?

2017-11-27 Thread codephantom via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 05:10:39 UTC, bauss wrote:

null != void


"initialized or not?" != void




Re: Is variable void?

2017-11-27 Thread bauss via Digitalmars-d-learn

On Monday, 27 November 2017 at 02:12:40 UTC, codephantom wrote:
On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman 
wrote:
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


  int x = void;

can I check if it's void before I use it, say, in a function 
it's been passed to?


// --

module test;

import std.stdio;
import std.typecons; // see: 
https://dlang.org/phobos/std_typecons.html#Nullable


void main()
{
Nullable!int x;  // requires: import std.typecons
assert(x.isNull);
writeln("x is ", x);

x = 1;
assert(!x.isNull);
writeln("x is ", x);

x.nullify(); // Forces x back to a null state.
assert(x.isNull);
writeln("x is ", x);

}
// --


null != void


Re: Is variable void?

2017-11-26 Thread codephantom via Digitalmars-d-learn

On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


  int x = void;

can I check if it's void before I use it, say, in a function 
it's been passed to?


// --

module test;

import std.stdio;
import std.typecons; // see: 
https://dlang.org/phobos/std_typecons.html#Nullable


void main()
{
Nullable!int x;  // requires: import std.typecons
assert(x.isNull);
writeln("x is ", x);

x = 1;
assert(!x.isNull);
writeln("x is ", x);

x.nullify(); // Forces x back to a null state.
assert(x.isNull);
writeln("x is ", x);

}
// --



Re: Is variable void?

2017-11-26 Thread crimaniak via Digitalmars-d-learn

On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


  int x = void;

can I check if it's void before I use it, say, in a function 
it's been passed to?


 You can use Nullable!int


Re: Is variable void?

2017-11-25 Thread John Chapman via Digitalmars-d-learn
On Saturday, 25 November 2017 at 15:38:15 UTC, Adam D. Ruppe 
wrote:
nope. It'd be indistinguishable from the user just happening to 
initialize it to some random value.


Thanks. I'll got with .init instead.



Re: Is variable void?

2017-11-25 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 25 November 2017 at 15:34:21 UTC, John Chapman wrote:
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


nope. It'd be indistinguishable from the user just happening to 
initialize it to some random value.




Re: Is variable void?

2017-11-25 Thread rikki cattermole via Digitalmars-d-learn

On 25/11/2017 3:34 PM, John Chapman wrote:
Is there any way of determining whether a variable has been initialized 
or not? For example, if something is declared like this:


   int x = void;

can I check if it's void before I use it, say, in a function it's been 
passed to?


`` = void;`` isn't null.

Don't treat it as such. It is a low level detail where you _will_ 
initialize it, just in a smarter way.


There is no conditions tied directly to it.


Is variable void?

2017-11-25 Thread John Chapman via Digitalmars-d-learn
Is there any way of determining whether a variable has been 
initialized or not? For example, if something is declared like 
this:


  int x = void;

can I check if it's void before I use it, say, in a function it's 
been passed to?