On Fri, Apr 27, 2018 at 2:08 PM, Esteban A. Maringolo <emaringolo@gmail.com> wrote:
Hi Clément,
On 27/04/2018 10:32, Clément Bera wrote:
Obviously sets are not as easy to deal with. You cannot mutate empty arrays/bytearrays, if you concatenate something it creates a new object. You can add things in sets. So you need to be careful... You can make the object read-only to avoid issues (MyClassVar beReadOnlyObject).
Sorry, but I can't understand how a class variable could allow you to use a new literal.
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). Of course, the problem with that is it will not change if the implementations of the messages it sends entail some changes over time.
So if you want #{} to create a new empty set, or #{1 1 2} to create a Set with 1 and 2 as elements, there is no way to do it.
Or this %{$a -> 1. 'foo' -> false. 'baz' -> #{1 1 2}} to create a dictionary with such set as literal. :)
Regards,
-- Esteban A. Maringolo