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... On Fri, Apr 27, 2018 at 8:59 PM, Esteban A. Maringolo <[email protected]> wrote: > On 27/04/2018 15:35, Richard Sargent wrote: > > On Fri, Apr 27, 2018 at 2:08 PM, Esteban A. Maringolo > > <[email protected] <mailto:[email protected]>> wrote: > > > As far as I knew the only way to have new literals was to modify the > > compiler. > > > > > > Yes. > > > > VA Smalltalk has an interesting syntax extension which allows an > > arbitrary expression to be a compile-time literal. > > Going by memory, something like ##(Dictionary new at: #a put: self > > something; at: #b put: self somethingElse; yourself). > > Dolphin Smalltalk provides that ##() literal as well since a decade at > least, so you have the full expression that gave origin to that literal, > but you don't need to compute it every time it is accessed. > > Although I don't remember seeing it with Dictionaries, but more with > string concatenations or "magic numbers" like seconds in a day stored as > ##(24 * 60 * 60). > > Regards, > > > -- > Esteban A. Maringolo > > -- Clément Béra https://clementbera.github.io/ https://clementbera.wordpress.com/
