Re: sprintf() query

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

It seems like you are describing object orientation.

-- (this is nothing new or exciting, just a lead-in for the sentence that follows) 
enum NUMBER,STRING -- classes 
 
object x = {NUMBER,1234}         -- or new_number(1234) 
object str = {STRING,"hello"}    -- or new_string("hello") 
 
enum CLASS,DATA  -- internal class structure 
 
constant formats = {"%d","%s"} 
 
procedure write(object x) 
  integer class = x[CLASS] 
  string fmt = formats[class] 
  printf(1,fmt,{x[DATA]}) 
end procedure 
write(x) 
 
-- or maybe something more like 
procedure call_method(string name, object x) 
  integer class = x[CLASS] 
  integer rdx = find(name,rtn_names[class]) 
  call_proc(rids[class][rdx],{x[DATA]}) 
end procedure 
call_method("write",x) 

What you cannot do is rely on the declaration type - and that is just as true for a full-blown object orientated system as it is OE/Phix - but on the actual object creation method - the value must get tagged somehow.

To clarify that, in an OOP system:

abstract class b {} 
concrete class c extends b {} 
concrete class d also extends b {} 
 
b myb; 

then obviously the declaration of myb may limit your choices but does not determine what routines get invoked or what it is, but rather that all depends on whether you put a c or d in it.

Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu