// readme.txt for Union class (NEURON template) by Bill Lytton
// here's an example for Union -- overloading plus so it can handle
// numbers, strings or lists
//* usage example -- overloading of addition
obfunc plus() { local i localobj lo
lo=new Union()
if (argtype(1)==0) { lo.x=$1+$2
} else if (argtype(2)==2) { sprint(lo.s,"%s%s",$s1,$s2)
} else if (argtype(2)==1) { lo.o=new List()
for i=0,$o1.count-1 lo.o.append($o1.object(i))
for i=0,$o2.count-1 lo.o.append($o2.object(i))
}
return lo
}
XO=plus(5,3)
print XO.x
XO=plus("hello ","there")
print XO.s
XO=plus(tmplist,tmplist)
print tmplist.count,XO.o.count
|