[DGD] Printing out nil?

Erwin Harte harte at xs4all.nl
Thu Mar 21 16:53:01 CET 2002


On Thu, Mar 21, 2002 at 10:43:16AM -0500, Jay Shaffstall wrote:
> I have a crash that happens when I try to print out the value of a variable 
> that's nil.  This is using version 1.2p1 of DGD, as I've had trouble 
> getting sources compiled on my machine to use the later versions.
> 
> The code is of the form:
> 
> 	string str;
> 
> 	...do some things, str may or may not get set to a valid string...
> 
> 	send_message ("String is : " + str);
> 
> This crashes DGD.  My questions:

Crashes?  I find that hard to believe, do you perhaps mean that you
get a runtime error along the lines of  "Bad argument 2 for kfun +"?

> 1) Is it illegal to concatenate a nil reference onto a string, or might I 
> have another problem entirely?

You'll get a runtime error when trying to add a nil to a string, yes.

> 2) I would have expected the nil reference to be replaced in the string 
> concatenation with something like "(nil)".  Is that supposed to happen, or 
> do I need to wrap all such possible nil references with conditionals to get 
> that sort of output?

You need to wrap possible-nil values if you want that behaviour.
Can't be very hard to have a function like this:

    string nil_string(mixed m) {
	return m == nil ? "(nil)" : (string)m;
    }

Hope that helps,

Erwin.
-- 
Erwin Harte <harte at xs4all.nl>
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list