Comments (7)
Yes I confirm the problem, here is an even shorter version:
STON toString: (Bag withAll: { 1@2. 1@2. 1@2 }).
STON fromString: 'Bag [ Point [ 1, 2 ], @2, @2 ]'.
I know the cause, I just have to think a bit about it.
from ston.
should solve your issue.
thanks again for reporting it.
from ston.
Thanks! That seems to work. Two observations though:
- This makes the notation for Bag more implementation-dependent (the GemStone implementation of Bag has different instance variables than the Pharo one)
- Bags serialized by the previous version of STON can not be materialized by this version anymore (
STON fromString: 'Bag[''abc'']'
no longer works)
An alternative solution I had in mind is to postpone adding the elements to the Bag to happen after the reference resolution. When creating the Bag, put its elements in an OrderedCollection that serves as a “placeholder”:
Bag class>>fromSton: stonReader
| elementsPlaceholder collection |
elementsPlaceholder := OrderedCollection new.
collection := self with: elementsPlaceholder.
stonReader parseListDo: [ :each |
elementsPlaceholder add: each ].
^ collection
Then in #stonProcessSubObjects:
, add the elements to the Bag after resolving their references:
Bag>>stonProcessSubObjects: block
| elementsPlaceholder |
elementsPlaceholder := self anyOne.
self removeAll.
elementsPlaceholder do: [ :element |
self add: (block value: element) ].
This also makes the #testCollections2
given above pass. As a sanity-check, it's also able to read a self-referencing Bag (b := STON fromString: 'Bag[@1]'. b anyOne == b
⇒ true
) (this wouldn't be the case, I think, if the reference-resolution were done in #fromSton:
, which is what I initially had in mind). What does not work yet is reading a Bag without any references, because in that case #stonProcessSubObjects:
is simply not sent; I'm not sure yet how best to handle that.
from ston.
By design and by nature, a serialisation format like STON exposes the internal structure of objects. It is just for a limited number of classes that a reasonably abstract and more implementation independent representation can be chosen.
For this reason, I do not consider cross-platform or inter-version compatibility as real goals. But of course I will try to maintain it.
With that being said, I am considering using another custom representation of Bags, with the value->occurences dictionary directly exposed, like
Bag { #a->2. #b->3 }
Would that work on Gemstone ?
BTW, I consider the old representation
Bag [ #a, #a, #b, #b, #b ]
as almost a bug, since it explodes the Bag's size.
from ston.
Ok, having a custom representation for Bags that avoids the size explosion and works across Smalltalk dialects seems like a good idea. (The GemStone implementation of Bag has more and different instance variables than the Pharo one: Bag allInstVarNames
⇒ #(#'_varyingSize' #'_numEntries' #'_indexedPaths' #'_levels' #'dict' #'size')
, dict
is like contents
in Pharo, size
is the size of the Bag; the other variables are inherited from UnorderedCollection).
from ston.
OK, done.
I also updated https://github.com/svenvc/ston/blob/master/ston-spec.md with a subsection about collections and Bag.
There are some more unit tests too
from ston.
Ok, thanks! I think we can consider this issue as closed.
from ston.
Related Issues (20)
- Error parsing the empty symbol HOT 1
- 32-bit Unicode characters not encoded/decoded correctly HOT 9
- Some tests fail on Squeak HOT 11
- Shouldn't Text class >> #fromSton: be on 'Ston-Text-Support' ? HOT 2
- Why appending a Z on Date with UTC offset? HOT 3
- Symbols containing non-byte characters are not correctly serialized HOT 2
- Instances of Color deserialized as instances of Dictionary when being referenced in the STON serialization file HOT 17
- Improve the definition of legal characters in class names HOT 4
- Cleanup newlines and blanks in "STON" packages
- Floating point numbers not materializing correctly HOT 1
- Color values lose precision when serialized HOT 1
- Special floating point values cause errors on materialization HOT 1
- Improve method comments HOT 3
- [BUG] - Can not serialize Float infinity HOT 7
- STON incorrectly converts instances of Text HOT 5
- STON incorrectly converts instances of Interval HOT 5
- Bug writing instances of SmallDictionary HOT 8
- Avoid writing variables with nil as value? HOT 3
- Bug reading instances of Text HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ston.