RosettaCodeData/Task/Polymorphism/Phix/polymorphism.phix

27 lines
633 B
Text
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
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
2017-09-23 10:01:46 +02:00
return {{x,y},r} -- {point,r}
-- (or {new_point(x,y),r} if you prefer)
2016-12-05 23:44:36 +01:00
end function
point p = new_point(4,5)
2017-09-23 10:01:46 +02:00
circle c1 = new_circle(p,6),
c2 = new_circle(4,5,6}
?c1
?c2