Re: object(x) rethink
jacques deschĂȘnes wrote:
> I think you completely miss the point with generic type.
> There is no point testing if a variable is of type 'object' as all variables
> hold an object.
> The object data type is there as a generic container and as is, it is very
> usefull.
> It is right to say that it is useless to write something like:
>
> if object(x) then...
>
> But for the coherance of the language this must be a valid declaration and
> must
> behave like any other datatype validation.
> There is nothing to change in the language here. All language that use generic
> type behave the same way.
> In OOP for exemple there is alway a generic class from which all other classes
> are derived and if you test any class to know if it is of that generic the
> answer
> will allways be TRUE, like in euphoria.
> This coherent in syntax and in semantic.
Ok, I've prepared some code, to be more concrete and clear.
Try it please:
type old_object(object x)
return object(x)
end type
global type object(old_object x)
if integer(x) then return 1
elsif atom(x) then return 2
elsif sequence(x) then return 3
else return 4 -- reserved for variables, declared with type 'object'
end if
end type
sequence s
s={1,1}
? object(s) -- true, 3
integer i
i=1
? object(i) -- true, 1
atom a
a=2.5
? object(a) -- true, 2
object x
x = {}
? object(x) -- true, 3 or 2 or 1 now
-- but must be 4, I think
The "object" word is ambiguous in EU, I think.
It is some piece of data in common sence, so to say,
and it is some very specific type of variable.
This new type in above code seems to have both
meanings, I think.
But that old one - it is just useless, yes,
you are right.
Regards,
Igor Kachan
kinz at peterlink.ru
|
Not Categorized, Please Help
|
|