|
I decided to finally play around with Traits. I decided I was going to
reinvent the field of integers by making a TGroup trait and composing
two of those with some aliasing, just like how we get a(n algebraic)
field from overlaying two groups together. I defined my field thusly:
Object subclass: #MyInteger
uses: TGroup @ {#inverse -> #negated. #* -> #+} + TGroup @
{#inverse -> #reciprocal}
instanceVariableNames: 'value'
classVariableNames: ''
poolDictionaries: ''
category: 'Algebra'.
But there's a problem. When I accept the above, the class definition
prints out, and those Associations print themselves without
whitespace. That means that '#* -> #+' becomes '#*->#+', which is the
Symbol #*-> followed by garbage. Using #'*' doesn't work, because #'*'
printString == '#*'.
The easy solution is to change Association's #printOn: to put
whitespace around the -> (and ditto for #storeOn:). But before I
"just" do that, I'd like to hear comments on the idea.
It would mean that "1->2" would print as "1 -> 2" (and storeString as
"(1 -> 2)").
I have a small test suite for the change, including this seemingly
innocuous snippet, which fails with a SyntaxError when it runs:
self assert: #+ -> #bar equals: (Compiler evaluate: (#+ -> #bar) storeString).
frank
|