Last update September 29, 2010

Doc Comments /
Expression



Expressions

More Information

Details about the TypeInfo? class can be found under Phobos:Object.

Warning: assert(object) does NOT just perform a null check (in fact, it only performs one when using a debug build of Phobos). Instead, it checks the invariant of the object. See the section on class invariants.

Suggestions

Order Of Evaluation

Is this also illegal? x=1+2*3

Logical Exclusive Or Operator

I've occationally wished for a logical exclusive or operator. The XorXor (^^) operator would relate to the OrOr ("||") and AndAnd ("&&") operators in the same way that the bit wize xor ("^") operator relates to bit wize Or ("|") and And ("&").

Example

if (paper ^^ plastic)
{
    bag(items);
}

filed as Issue:131 -- rejected as WONTFIX, use (paper != 0) == (plastic != 0)

Using and and or as alternatives for && and ||

if ( "aardvark" < "zebra" and "C" < "D" )
    writefln("all is right in the world");

-- Even as a C programmer I like the and/or rather than &&/||. But the language should not have both.

DavidO?

Delegates are not closures

Any function of the this form is always invalid

T delegate() fn(T i)
{
	return T delegate(/* somthing */)
		{
		// code
		};
}

This is because a delegate literal is actually an anonymous nested function that refers to the stack frame of the enclosing function. This reference cause the delegate to be invalid for the same reason that returning a pointer to a local variable is invalid.

int* fn()
{
	int i;
	return &i; // return value points to "undefined space"
}

Import Expressions Example

To protect against the possibility of having a formatting code in the file, the example should probably be:

 void foo()
 {
     // Prints contents of file foo.txt
     writefln("%s", import("foo.txt") );
 }

Messages

Add your comments here...

Links

See the corresponding page in the D Specification: DigitalMars:d/expression.html
FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: September 29, 2010 7:15 (diff))