Re: names for init block keywords?

Laurent Dube <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Organization DEI
Message-ID <[email protected]>
Hi Mark,

I've been too busy to participate lately, barely having time to catch up
on discussion traffic when I can.

Mark Hahn wrote:
> I actually got the need for "once" from a c.l.p. thread.  Several claimed
> the need for it.  It is not only the difference in timing but the difference
> in scope.  Don't forget that "after" is in the outer scope and "once" is in
> the function scope.
>
> You are right though that it is only replacing an if statement whereas the
> "after" keyword is filling a more fundamental gap.

I must intervene on one point that will be important in simulation.
New simulation objects are instantiated according to need at the start
as well as while a simulation progresses. However their dynamic state
is not necessarily initialized immediately at the time they are created,
so that the object's init_ method cannot be used for this.

On the other hand, it's not the concern of the consumer of the object's
services to know if the object has been initialized or not at the time
it first queries the object by calling it's "run" function. It's up to
the main "run" function of the object to take care of that. So there is
a need for an initialization mechanism at the function level.

In other words, without exception, each simulated element runs an
initialization routine before falling into one of its possibly many
running modes. But that's not at object instantiation time, it's at
object first-use time.

It's true we can program this with an if at the top of the object's main
"run" function, but I prefer the convenience of a keyword that will
also avoid requiring an has_not_been_init_yet flag.

An interesting aside is that it's not uncommon to re-init an element
during a simulation, to a state that may be different each time, but
using the same routine as for the initial initialization. So there may
be cases where the contents of the "once:" block may only consist of a
call to a separate function init() of the object! Oh well...

> How about "outer:" ?  It is already a keyword and it means the outside scope
> which this code runs in.  I like that.

I like "outer:" for defInit.

About "init:", I don't see a confusion with init_, as init_ is a method
at the object level, and "init:" designates a block inside a function.
Using "once:" is ok too, but it uses up a keyword that may have another
use later as meaning "when a condition is finally achieved, do something
once, as in

    once has_grown_up:
        get_first_job()

which is more elegant than

    if has_grown_up and not had_first_job:
        get_first_job()

So I prefer to not use up the possible keyword "once", and to use "init:"
or "before:", with preference for "init:".

  Laurent Dube
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.