RosettaCodeData/Task/Polymorphism/Phix/polymorphism.phix

25 lines
538 B
Plaintext

type point(object o)
return sequence(o) and length(o)=2 and atom(o[1]) and atom(o[2])
end type
function new_point(atom x=0, atom y=0)
return {x,y}
end function
type circle(object o)
return sequence(o) and length(o)=2 and point(o[1]) and atom(o[2])
end type
function new_circle(object x=0, atom y=0, atom r=0)
if point(x) then
r = y -- assume r got passed in y
return {x,r} -- {point,r}
end if
return {{x,y},r}
end function
point p = new_point(4,5)
circle c = new_circle(p,6)
?p
?c