Association >> #printString and friends

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Association >> #printString and friends

Frank Shearar-3
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

Reply | Threaded
Open this post in threaded view
|

Re: Association >> #printString and friends

Nicolas Cellier
+1 add those spaces


2013/5/1 Frank Shearar <[hidden email]>
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