On Fri, Apr 27, 2018 at 3:58 PM, Esteban A. Maringolo <[email protected]>
wrote:

> oh, you were talking about how te VM views the object,
> I was thinking in terms of how the compiler sees the text.
>
> So I'm talking about literals "syntax".
>
> Thanks anyway for the "trick" :)
>

Another common technique is a "once block". Teach Block how to evaluate
itself once and to use its cached result the next time.

It's not as fast as a literal, but it is a pretty effective way to have a
clean implementation with as complex code as one could wish.
Clear the cache when saving the image or at image start up or ... whenever
seems good (such as when you change the implementation of what was cached.

e.g.
[Dictionary new
at: #a put: self something;
at: #b put: self somethingElse;
yourself]
once



>
> On 27/04/2018 16:34, Clément Bera wrote:
> > The guy who asked the question said: "...when you want to shorten some
> > object initialization"
> >
> > Using ClassVariable is an alternative way to shorten object
> > initialization, reading a ClassVariable is almost the same performance
> > as reading a literal, so that looked like a good alternative to me. Both
> > the ClassVariable and the literal have the same issues (same object so
> > if you mutate it you have to deal with it).
> >
> > But yes, it's not a new literal.
> >
> > For new literals, you can extend the compiler or hard patch thing:
> >
> > MyClass>>foo
> > ^ #bar
> >
> > (MyClass>>#foo) literalAt: ((MyClass>>#foo) literals indexOf: #bar) put:
> > Set new.
> >
> > MyClass new foo
> >
> >>>> a Set ()
> >
> > Obviously it depends what you mean by literal, the latter code uses the
> > literal bytecode instruction, which does not make the pushed object a
> > literal object...
>
>
> --
> Esteban A. Maringolo
>
>

Reply via email to