On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse
<stepharo.s...@gmail.com> wrote:
> Tx sven got caught by a flu... freezing in my bed.
> I will check.
>
> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <s...@stfx.eu> wrote:
>> So I guess that you want a Smalltalk expression that, when evaluated, 
>> returns an arbitrary STON-ified object as a real object.
>>
>> Let's say you want to STON-ify the following object:
>>
>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a 
>> single quote.' } asDictionary.
>>
>> Note there is a single quote character inside the #note.
>>
>> You can do that using #print: when needed. Here is an expression to see how 
>> that works:
>>
>> Compiler evaluate: (String streamContents: [ :out |
>>   out
>>     nextPutAll: 'STON fromString: ';
>>     print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. 
>> #note->'Look: '', that was a single quote.' } asDictionary)) ]).
>>
>> The Smalltalk expression then looks like this:
>>
>> STON fromString: '{#note:''Look: \'', that was a single 
>> quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}'
>>
>> The double single quotes are Smalltalk's syntax's escaping, while the 
>> backslashes are STON's. Yes, that is a bit confusing, but consistent.
>>
>> Is this what you need ?
>>
>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <stepharo.s...@gmail.com> wrote:
>>>
>>> Hi
>>>
>>> I want to write a method that generate a method that when I execute
>>> this recreates the objects that I STONified.
>>> (I love STON).
>>>
>>> So I did something like that
>>>
>>> descriptionMethodFrom: descriptionItems
>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription
>>> itemDescriptionForXX"
>>>
>>>  ^ String streamContents: [ :s |
>>>            s nextPutAll: 'descriptions'; cr.
>>>            s nextPutAll: '^ STON fromString: '.
>>>            s nextPutAll: (STON toStringPretty: descriptionItems) ]
>>>
>>> and I get of course something wrong :) because the strings are not
>>> doubel quoted and the first expression is not surrounded by single
>>> quote.
>>>
>>> And I could do it but I want a smart way to do it. I was thinking that
>>> may be I'm missing something obvious.
>>>
>>> descriptions
>>> ^ STON fromString: [
>>> StringConfigurationItem {
>>> #propertyName : 'title',
>>> #default : 'my super cool book'
>>> },
>>> BooleanConfigurationItem {
>>> #propertyName : 'verbose',
>>> #default : 'true'
>>> },
>>> StringConfigurationItem {
>>> #propertyName : 'attribution',
>>> #default : 'me, myself and I'
>>> },
>>> StringConfigurationItem {
>>> #propertyName : 'series',
>>> #default : 'Square Bracket Associate Collection'
>>> }
>>> ]
>>>
>>
>>

Reply via email to