www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - 2 little enigmas with is & Unqual!

reply spir <denis.spir gmail.com> writes:
Hello,

1. Why isn't Unqual!(char) =3D=3D char?
    writeln( is( Unqual!(typeof('c')) =3D=3D char ) );	// false
    writeln( is( Unqual!(char) =3D=3D char ) );		// false
    writeln( is( char =3D=3D char ) );			// true!
(dmd v2.049)

2. Why cannot one write "assert(is(Unqual(t1) =3D=3D t2))"?
    assert( is( char =3D=3D char ) );			// OK
    assert( is( Unqual!(char) !=3D char ) );		// compile Error
    assert( is( Unqual!(typeof('c')) !=3D char ) );	// compile Error
(is() gets on my nerves ;-)

Denis
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3

spir.wikidot.com
Dec 01 2010
next sibling parent reply vincent picaud <vincent.picaud laposte.net> writes:
spir Wrote:

 Hello,
 
 1. Why isn't Unqual!(char) == char?
     writeln( is( Unqual!(typeof('c')) == char ) );	// false
     writeln( is( Unqual!(char) == char ) );		// false
     writeln( is( char == char ) );			// true!
 (dmd v2.049)
 

Using GCD 4.3.5 ( more precisely on Linux/Debian ) writeln( is( Unqual!(typeof('c')) == char ) ); writeln( is( Unqual!(char) == char ) ); writeln( is( char == char ) ); returns true true true as expected
 2. Why cannot one write "assert(is(Unqual(t1) == t2))"?
     assert( is( char == char ) );			// OK
     assert( is( Unqual!(char) != char ) );		// compile Error
     assert( is( Unqual!(typeof('c')) != char ) );	// compile Error
 (is() gets on my nerves ;-)
 

not sure of that, but I think "is" is a compile time feature, hence you must write static assert( is( char == char ) ); // OK static assert( is( Unqual!(char) == char ) ); // OK static assert( is( Unqual!(typeof('c')) == char ) ); // Ok hope this can help....
 Denis
 -- -- -- -- -- -- --
 vit esse estrany ☣
 
 spir.wikidot.com
 

Dec 01 2010
parent vincent picaud <vincent.picaud laposte.net> writes:
spir Wrote:

 On Wed, 01 Dec 2010 10:03:57 -0500
 vincent picaud <vincent.picaud laposte.net> wrote:
 
 spir Wrote:
 
 Hello,
 
 1. Why isn't Unqual!(char) == char?
     writeln( is( Unqual!(typeof('c')) == char ) );	// false
     writeln( is( Unqual!(char) == char ) );		// false
     writeln( is( char == char ) );			// true!
 (dmd v2.049)
 

Using GCD 4.3.5 ( more precisely on Linux/Debian ) writeln( is( Unqual!(typeof('c')) == char ) ); writeln( is( Unqual!(char) == char ) ); writeln( is( char == char ) ); returns true true true as expected

All right, I do not have the same results using dmd. Seems like abug, doesn't it?

Perhaps... I will check at home with dmd/windows, here I only gdc/linux
 2. Why cannot one write "assert(is(Unqual(t1) == t2))"?
     assert( is( char == char ) );			// OK
     assert( is( Unqual!(char) != char ) );		// compile Error
     assert( is( Unqual!(typeof('c')) != char ) );	// compile Error
 (is() gets on my nerves ;-)
 

not sure of that, but I think "is" is a compile time feature, hence you must write static assert( is( char == char ) ); // OK static assert( is( Unqual!(char) == char ) ); // OK static assert( is( Unqual!(typeof('c')) == char ) ); // Ok

Well, on dmd: static assert( is( Unqual!(char) == char ) ); raises: Error: static assert (is(Unqual!(char) == char)) is false which is at least consistent with the result written above. But strangely, I cannot reverse the predicate: static assert( is( Unqual!(char) != char ) ); yields: found '!=' when expecting ')' Actually, i even cannot write: static assert( is( char != dchar ) ); // same error Is this normal? Doesn't is() allow != at all?

I think it is the right reason, is() does not support "!=", only "=="
 hope this can help....

Yes, helps a lot, thank you Vincent.

Thank, I m a new comer here, :)
 
 
 Denis
 -- -- -- -- -- -- --
 vit esse estrany ☣
 
 spir.wikidot.com
 

Dec 01 2010
prev sibling parent spir <denis.spir gmail.com> writes:
On Wed, 01 Dec 2010 10:03:57 -0500
vincent picaud <vincent.picaud laposte.net> wrote:

 spir Wrote:
=20
 Hello,
=20
 1. Why isn't Unqual!(char) =3D=3D char?
     writeln( is( Unqual!(typeof('c')) =3D=3D char ) );	// false
     writeln( is( Unqual!(char) =3D=3D char ) );		// false
     writeln( is( char =3D=3D char ) );			// true!
 (dmd v2.049)
=20

Using GCD 4.3.5 ( more precisely on Linux/Debian ) =20 writeln( is( Unqual!(typeof('c')) =3D=3D char ) ); =20 writeln( is( Unqual!(char) =3D=3D char ) ); =20 writeln( is( char =3D=3D char ) ); =20 =20 returns=20 =20 true true true =20 as expected

All right, I do not have the same results using dmd. Seems like abug, doesn= 't it?
 2. Why cannot one write "assert(is(Unqual(t1) =3D=3D t2))"?
     assert( is( char =3D=3D char ) );			// OK
     assert( is( Unqual!(char) !=3D char ) );		// compile Error
     assert( is( Unqual!(typeof('c')) !=3D char ) );	// compile Error
 (is() gets on my nerves ;-)
=20

not sure of that, but I think "is" is a compile time feature, hence you m=

 static  assert( is( char =3D=3D char ) );			// OK
 static  assert( is( Unqual!(char)  =3D=3D char ) );		// OK
 static  assert( is( Unqual!(typeof('c'))  =3D=3D char ) );	// Ok

Well, on dmd: static assert( is( Unqual!(char) =3D=3D char ) ); raises: Error: static assert (is(Unqual!(char) =3D=3D char)) is false which is at least consistent with the result written above. But strangely, = I cannot reverse the predicate: static assert( is( Unqual!(char) !=3D char ) ); yields: found '!=3D' when expecting ')' Actually, i even cannot write: static assert( is( char !=3D dchar ) ); // same error Is this normal? Doesn't is() allow !=3D at all?=20
 hope this can help....

Yes, helps a lot, thank you Vincent. Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Dec 01 2010