// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c;
This sounds like a poor translation from a foreign concept Pike lacks.
If you were thinking of the Pikeish concept of definedness, such as whether something you indexed out of a mapping actually existed there, you would write (with b = my_mapping[some_index]):
a = zero_type(b) ? c : b;
/ Johan Sundström (a hugging punishment!)
Previous text:
2003-01-03 02:09: Subject: Re: PLEAC
On Fri, Jan 03, 2003 at 12:20:02AM +0100, Mirar @ Pike developers forum wrote:
Don't forget, | > str/-5; | "45123", | > str/-5.0; | "123", | "45123",
cool! :-)
lets get on with it: (gotta do something while i attempt to get the pike 7.4 debian packages to compile on woody)
Establishing a Default Value //----------------------------- // use b if b is true, else c a = b || c;
// set x to y unless x is already true if(!x) x=y;
// use b if b is defined, else c // an undefined variable would be a compile time error. a= b?b:c; foo = bar || "DEFAULT VALUE"; dir = argv[0] || "/tmp"; dir = arrayp(ARGV) ? ARGV[0] : "/tmp"; count[shell||"/bin/sh"]++;
user = getenv("USER") || getenv("LOGNAME") || getpwuid(getuid())[0] || "Unknown uid number "+getuid();
if(!starting_point) starting_point = "Greenwich";
if(!sizeof(a)) a=b; // copy only if empty a=(sizeof(b)?b:c); // assign b if nonempty, else c
greetings, martin.
/ Brevbäraren