OK, this is an idea (saving clean blocks as Smalltalk), but I am not sure I 
like it.

This is a huge security problem (open code execution, [ Smalltalk quitPrimitive 
]).

Furthermore, it would create possible uncheckable portability problems.

And even if it were added, it would not cover all blocks, there would still be 
exceptions.

> On 3 Nov 2016, at 03:04, Mariano Martinez Peck <[email protected]> wrote:
> 
> 
> 
> On Wed, Nov 2, 2016 at 8:51 PM, Henrik Nergaard <[email protected]> 
> wrote:
> You could always store the closure as a string and then evaluate it on 
> materialization, at least if it is clean (no thisContext and no return)
> 
> For blocks without no self usage:
> ------------------
> | blk |
> 
> blk := [ :a :b | a <= b ].
> 
> #_ assert: blk isClean.
> 
> blk := Compiler evaluate: blk asString.
> 
> #_ assert: (blk value: 1 value: 2)
> ----------------
> 
> If self is used then it must also be stored to materialize it correctly again:
> 
> ----------------
> | blk ref |
> 
> blk := [ self crLog ].
> ref := blk receiver.
> blk := Smalltalk compiler evaluate: blk asString in: nil to: ref.
> blk value
> ----------------
> 
> On the topic of STON, is there a way to specify that a variable should only 
> be serialized if it is referenced elsewhere depper in the tree?
> This could be useful, for example when storing morphs that are active in the 
> world to only include #owner that are not the root serialized object and 
> other structures were you might not want to serialize its parent but only 
> deeper into the tree structure.
> 
> 
> 
> I proposed exactly that to SIXX developer which would allow you to serialize 
> at least SortedCollection with clean closures.
> 
> 
> 
> 
>  
> Best regards,
> Henrik
> 
> 
> -----Original Message-----
> From: Pharo-users [mailto:[email protected]] On Behalf Of 
> Sven Van Caekenberghe
> Sent: Wednesday, November 2, 2016 11:11 PM
> To: Any question about pharo is welcome <[email protected]
> Subject: Re: [Pharo-users] About STONS efficiency at storing nested objects { 
> was : (Re: Keeping data with an application)}
> 
> You can't serialise blocks with STON.
> 
> The design goal of STON was to be able to serialise regular domain models.
> 
> Classes are written as a global reference to their name, as a kind of 
> shortcut (as opposed to writing out the whole class structure).
> 
> For blocks there is no easy solution, AFAIK.
> 
> > On 2 Nov 2016, at 20:03, Dimitris Chloupis <[email protected]> wrote:
> >
> > I tried to use my ChronosManager object with it and STON does not seem
> > to like this
> >
> > m := ChronosManager new.
> > s:= STON toString: m
> > s inspect.
> >
> > STONWriter>>error:
> > BlockClosure(Object)>>stonOn:
> > STONWriter>>nextPut:
> > STONWriter>>encodeKey:value:
> > STONMapWriter>>at:put:
> > [ :each |
> > (anObject instVarNamed: each)
> >       ifNotNil: [ :value | dictionary at: each asSymbol put: value ]
> >       ifNil: [ anObject stonShouldWriteNilInstVars
> >                       ifTrue: [ dictionary at: each asSymbol put: nil ] ] ] 
> > in [
> > :dictionary | instanceVariableNames
> >       do: [ :each |
> >               (anObject instVarNamed: each)
> >                       ifNotNil: [ :value | dictionary at: each asSymbol 
> > put: value ]
> >                       ifNil: [ anObject stonShouldWriteNilInstVars
> >                                       ifTrue: [ dictionary at: each 
> > asSymbol put: nil ] ] ] ] in STONWriter>>writeObject: in Block: [ :each | 
> > ...
> > Array(SequenceableCollection)>>do:
> > [ :dictionary |
> > instanceVariableNames
> >       do: [ :each |
> >               (anObject instVarNamed: each)
> >                       ifNotNil: [ :value | dictionary at: each asSymbol 
> > put: value ]
> >                       ifNil: [ anObject stonShouldWriteNilInstVars
> >                                       ifTrue: [ dictionary at: each 
> > asSymbol put: nil ] ] ] ] in STONWriter>>writeObject: in Block: [ 
> > :dictionary | ...
> > [ self newlineIndent.
> > block value: mapWriter ] in [ | mapWriter | mapWriter := STONMapWriter
> > on: self.
> > writeStream nextPut: ${.
> > self
> >       indentedDo: [ self newlineIndent.
> >               block value: mapWriter ].
> > self newlineIndent.
> > writeStream nextPut: $} ] in STONWriter>>writeObject:streamMap: in Block: [ 
> > self newlineIndent....
> > STONWriter>>indentedDo:
> > [ | mapWriter |
> > mapWriter := STONMapWriter on: self.
> > writeStream nextPut: ${.
> > self
> >       indentedDo: [ self newlineIndent.
> >               block value: mapWriter ].
> > self newlineIndent.
> > writeStream nextPut: $} ] in STONWriter>>writeObject:streamMap: in Block: [ 
> > | mapWriter |...
> > [ writeStream nextPutAll: anObject class stonName.
> > self prettyPrintSpace.
> > block value ] in STONWriter>>writeObject:do: in Block: [ writeStream 
> > nextPutAll: anObject class stonName....etc...
> > STONWriter>>with:do:
> > STONWriter>>writeObject:do:
> > STONWriter>>writeObject:streamMap:
> > STONWriter>>writeObject:
> > KMKeymap(Object)>>stonOn:
> > STONWriter>>nextPut:
> > STONWriter>>encodeKey:value:
> > [ :key :value |
> > first
> >       ifTrue: [ first := false ]
> >       ifFalse: [ self mapElementSeparator ].
> > self encodeKey: key value: value ] in [ self newlineIndent.
> > pairs
> >       keysAndValuesDo: [ :key :value |
> >               first
> >                       ifTrue: [ first := false ]
> >                       ifFalse: [ self mapElementSeparator ].
> >               self encodeKey: key value: value ] ] in 
> > STONWriter>>encodeMap: in Block: [ :key :value | ...
> > [ :assoc | aBlock value: assoc key value: assoc value ] in 
> > Dictionary>>keysAndValuesDo: in Block: [ :assoc | aBlock value: assoc key 
> > value: assoc va...etc...
> > [ :each | each ifNotNil: [ aBlock value: each ] ] in
> > Dictionary>>associationsDo: in Block: [ :each | each ifNotNil: [
> > aBlock value: each ] ]
> > Array(SequenceableCollection)>>do:
> > Dictionary>>associationsDo:
> > Dictionary>>keysAndValuesDo:
> > [ self newlineIndent.
> > pairs
> >       keysAndValuesDo: [ :key :value |
> >               first
> >                       ifTrue: [ first := false ]
> >                       ifFalse: [ self mapElementSeparator ].
> >               self encodeKey: key value: value ] ] in 
> > STONWriter>>encodeMap: in Block: [ self newlineIndent....
> > STONWriter>>indentedDo:
> > STONWriter>>encodeMap:
> > [ self encodeMap: hashedCollection ] in STONWriter>>writeMap: in
> > Block: [ self encodeMap: hashedCollection ]
> > STONWriter>>with:do:
> >
> 
> 
> 
> 
> 
> 
> -- 
> Mariano
> http://marianopeck.wordpress.com


Reply via email to