1. Object smart routines
The following absolute value function can only handle atoms
I will give a demonstration on how to make functions
Object smart.
Object smart means it can handle atoms or sequences.
function absolute(atom a)
if 0 > a then
a = -a
end if
return a
end function
The function below is object smart.
function abs(object x)
if atom(x) then
if 0 > x then
x = -x
end if
else
for A = 1 to length(x)
x[A] = abs(x[A])
end for
end if
end function
--function use follows
object x
x = absolute(-4)--here x = 4
--x = absolute({5, -4, {}, {{-1}}})--here an error occurred.
x = abs(-4)--here x = 4
x = abs({5, -4, {}, {{-1}}})--here x = {5, 4, {}, {{1}}}
--Lucius Lamar Hilley III
-- E-mail at luciuslhilleyiii at juno.com
2. Re: Object smart routines
On Wed, 3 Dec 1997, Lucius L Hilley III wrote:
[Lots of stuff that I had to snip because this software doesn't like a
disproportionate amount of quoted text :( ]
Try the version in mathbag.e:
global function sgn(object a)
return -(a<0)+(a>0)
end function
global function abs(object a)
return a * sgn(a)
end function
These are both "object-smart", as are most of the other routines
therein. Have a look back in the digests for the conversation I had with
Lee woo seob about it...
--
Carl R White | e-mail...: crwhite- at -comp.brad.ac.uk
| finger...: crwhite- at -dcsun1.comp.brad.ac.uk
| web......: http://www.student.comp.brad.ac.uk/~crwhite/
*** Anti-Spam: Fake IP address in Header. Change '- at -' to '@' in .sig. ***