Re: object(x) rethink
- Posted by Igor Kachan <kinz at peterli?k.r?> Mar 02, 2008
- 762 views
Bill Reed wrote: [snip] > Sure, integer, atom, and sequences are *objects*, > but not all objects are sequences, and > not all objects are atoms and > not all objects are integers. Yes, but we are talking just about types of variables here.
integer i -- it can be the integer value only atom a -- it can be integer and floating sequence s -- its elements can be any type, including object type object x -- it can be any type at all
> I don't check for "if object(x)" or "if not object(x)" Ok, but why not to check if variable is type of "object" or it is not? > If I declare an object as a sequence, and one time it becomes an an integer, > I get a "type_check failure". I can assign anything to an object, but I > can't assign an integer to a sequence. There is some confusion in "declare an object as a sequence". Let us say "declare a variable as object" or "declare a variable as sequence" etc. Then, you *can* assign an integer to a sequence using indexing or slicing. Try please:
sequence s integer i i=5 s = {1,2,3,4,{5,5,5,5},6,7} ? s s[5] = i ? s -- sequence {5,5,5,5} is integer 5 now
> }}} <eucode> > > object x > > x = "abc" -- ok > x = -1 -- ok > > But: > > sequence x > > x = "abc" -- ok > x = -1 -- type_check error, x is -1 > > To fix: > > object o > sequence s > integer i > atom a > > o = "abc" > o = -1 > o = 5.3 > > if sequence(o) then > s = o > elsif integer(o) then > i = o > elsif atom(o) then > a = o > end if > </eucode> {{{ Ok, but why not to have object(o) is true only if variable o was declared as object? Regards, Igor Kachan kinz at peterlink.ru