Re: Function initialization at the first call.
- Posted by petelomax Jan 19, 2013
- 1113 views
FYI, I also changed object() in Phix because, as you said, one less variable, just better.
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.
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