Code Monkey home page Code Monkey logo

Comments (7)

svenvc avatar svenvc commented on July 30, 2024

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.

svenvc avatar svenvc commented on July 30, 2024

6a894a4

should solve your issue.

thanks again for reporting it.

from ston.

Rinzwind avatar Rinzwind commented on July 30, 2024

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 == btrue) (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.

svenvc avatar svenvc commented on July 30, 2024

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.

Rinzwind avatar Rinzwind commented on July 30, 2024

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.

svenvc avatar svenvc commented on July 30, 2024

OK, done.

c8cfdda

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.

Rinzwind avatar Rinzwind commented on July 30, 2024

Ok, thanks! I think we can consider this issue as closed.

from ston.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.