On 28 April 2018 at 03:34, Clément Bera <bera.clem...@gmail.com> 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... > > Maybe pool dictionaries provide a half-way house... http://www.instantiations.com/PDFs/Smalltalk-Report/pools.pdf http://files.pharo.org/books-pdfs/updated-pharo-by-example/2017-01-14-UpdatedPharoByExample.pdf cheers -ben