Re: Function initialization at the first call.

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

FYI, I also changed object() in Phix because, as you said, one less variable, just better.

mattlewis said...

The only other way would be to have a separate variable as a flag to identify whether you have initialized it. The 4.0 update to object()'s behavior was intended to simplify this.

SnakeCharmer said...

By the way, it would be much more convenient to make String equal to "" initially.

Possibly, but this could also lead to other program errors. In any case, there is no "default" variable value for any sort of euphoria objects, and I don't see that happening.

Again fyi only, prior to the change to object(), I used separate flags, and initialised the (static integer) flag at compile-time, which was not possible with non-integers (due to reference counting and other logistical issues). So instead of:

a() 
... 
 
string s = "string" -- (or "", same problem) 
 
procedure a() 
  ?s -- oops, s not assigned 
end procedure 

I would code

a() 
integer init=0 -- (can be initialised at compile time) 
string s 
procedure a() 
  if not init then 
    s = "string" 
    init = 1 
  end if 
  ?s 
end procedure 

In short, forward calls and initialisation of non-integers gave me headaches in Phix too, prior to the change to object().

Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu