Re: object(x) rethink

new topic     » goto parent     » topic index » view thread      » older message » newer message

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.


regards,
Jacques DeschĂȘnes
 

Ricardo Forno wrote:
> 
> Bill Reed wrote:
> > 
> > Igor Kachan wrote:
> > > 
> > > Bill Reed wrote:
> > >  
> > > > 
> > > > object useless????
> > > > 
> > > > ----------------------------------------------------------------------
> > > > A variable must be declared as an object in order to determine what
> > > > type it is.
> > > > 
> > > >   object x
> > > >   
> > > >   if sequence(x) then
> > > >     puts(1, "variable is a sequence")
> > > >   end if
> > > >   
> > > >   if integer(x)
> > > >     puts(1, "variable is an integer")
> > > >   end if
> > > >   
> > > > ----------------------------------------------  
> > > >   doeumentation for gets() from library.doc
> > > > ----------------------------------------------
> > > >   
> > > > 
> > > > Example 1:
> > > > 
> > > >               sequence buffer
> > > >               object line
> > > >               integer fn
> > > >               
> > > >               -- read a text file into a sequence
> > > >               fn = open("myfile.txt", "r")
> > > >               if fn = -1 then
> > > >                   puts(1, "Couldn't open myfile.txt\n")
> > > >                   abort(1)
> > > >               end if
> > > >               
> > > >               buffer = {}
> > > >               while 1 do
> > > >                   line = gets(fn)
> > > >                   if atom(line) then
> > > >                       exit   -- -1 is returned at end of file
> > > >                   end if
> > > >                   buffer = append(buffer, line)
> > > >               end while
> > > 
> > > Hi Bill,
> > > 
> > > Try please:
> > > }}}
<eucode>
> > > integer i   i= 1
> > > atom a      a= 2
> > > sequence s  s={3}
> > > object x    x={4,{5}}
> > > 
> > > if object(i) then ? i end if
> > > if object(a) then ? a end if
> > > if object(s) then ? s end if
> > > if object(x) then ? x end if
> > > </eucode>
{{{

> > > 
> > > Is *object()*, not *object*, useful?
> > > 
> > > This *object()* is just a dummy function now.
> > > It stands just for some 'symmetry' with integer(),
> > > atom() and sequence() functions.
> > > 
> > > Do you see now?
> > > 
> > > Regards,
> > > Igor Kachan
> > > kinz at peterlink.ru
> > 
> > 
> > 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.
> > 
> > I don't check for "if object(x)" or "if not object(x)"
> > 
> > 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.
> > 
> > }}}
<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>
{{{

> > 
> > Bill
> 
> Hi, Bill.
> You are missing the point.
> Declaring a variable as an object is very useful, no doubt. I routinely use
> "object x" the way you explained.
> Andy's proposal is that, as object(x) always yields true or crashes,
>  it should be changed to somewhat more useful. I agree with him.
> Best regards.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu