Pharo-users
By thread
pharo-users@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
February 2019
- 79 participants
- 589 messages
Re: [Pharo-users] How to write out simple Json?
by Richard O'Keefe
1. A JSON "object" corresponds to some kind of
dictionary in Smalltalk.
2. {#a -> 1. #b -> 2} is NOT A DICTIONARY.
It is an Array of Associations.
3. {#a -> 1. #b -> 2} asDictionary
*is* a dictionary.
4. My Smalltalk allows #{#a -> 1. #b -> 2}
-- how could I let it be less expressive than
-- the language named for a snake?
On Fri, 1 Mar 2019 at 02:57, Tim Mackinnon <tim(a)testit.works> wrote:
> As I merrily chat to myself - I noticed that STONWriter almost does what I
> need - it just complains in #writeAssociation: so I make a subclass
> STONJSONWriter and override:
>
> writeAssociation: association
> âdonât smack meâ¦.
> jsonMode
> ifTrue: [ self error: 'wrong object class for JSON mode'
> ]."
> self
> encodeKey: association key
> value: association value
>
> I get exactly what I would expect - valid Json from simple Collections,
> Associations and Array.
>
> So would it be handy to have such a writer in the image (or let STONWriter
> be more configurable for this?)
>
> Tim
>
> p.s. my finally example would then be:
>
> ex := { 'track'-> 'pharo'.
> 'language' -> 'smalltalk'.
> 'exercises' ->
> {'slug' -> 'hello'.
> 'id' -> 55.
> 'topics' -> #('a' 'b' 'c') }
> }.
>
> String streamContents: [ :stream |
> (STONJSONWriter on: (stream))
> jsonMode: true;
> prettyPrint: true;
> writeList: ex ].
>
> > On 28 Feb 2019, at 13:45, Tim Mackinnon <tim(a)testit.works> wrote:
> >
> > Just to add more flavour to this - it seems quite wordy that we have to
> do this (or equivalent) to write some config.
> >
> > ex := OrderedDictionary new
> > at: 'track' put: 'pharo';
> > at: 'language' put: 'smalltalk';
> > at: 'exercises' put: (
> > OrderedDictionary new
> > at: 'slug' put: 'hello';
> > at: 'id' put: 55;
> > at: 'topics' put: #('a' 'b' 'c');
> > yourself );
> > yourself.
> >
> > String streamContents: [ :stream |
> > (NeoJSONWriter on: (stream)) prettyPrint: true;
> > mapInstVarsFor: Association;
> > nextPut: ex ].
> >
> > So Iâm still wondering the NeoJSONObjectMapping can do something easy
> for Association other than simply mapInstVars?
> >
> >
> >> On 28 Feb 2019, at 13:36, Tim Mackinnon <tim(a)testit.works> wrote:
> >>
> >> Hi Sven - is there no convenience shortcut we can use in our code to
> make this less wordy when we are specifying it?
> >>
> >> E.g. the following is very convenient to write - but doesnât work (as
> you have $â and not $â )
> >>
> >> ex := { 'track'-> 'pharo'.
> >> 'language' -> 'smalltalk'.
> >> 'exercises' ->
> >> {'slug' -> 'hello'.
> >> 'id' -> 55.
> >> 'topics' -> #('a' 'b' 'c') }
> >> }.
> >>
> >> String streamContents: [ :stream |
> >> (STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
> >>
> >> I had thought maybe NeoJSON might help and put:
> >>
> >> String streamContents: [ :stream |
> >> (NeoJSONWriter on: (stream)) prettyPrint: true;
> >> "mapInstVarsFor: Association;"
> >> nextPut: ex ].
> >>
> >> But I get the error about missing an association mapping. If I
> uncomment that bit - I get things like: { "value" : âpharo" },
> >>
> >> So is there a way I can write a simple mapper for Association that will
> write out the key in a string and the value in a string?
> >>
> >> Iâm quite suprised we canât easily write out fragments of Json in our
> code in a light weight way? Or do I need to make a proper Config object and
> then teach it how to map properly such that rather than fiddling with our {
> x->y } dictionary sugar I do something like:
> >>
> >> Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is:
> #(1 2 3).
> >>
> >> And I guess at:is: can do the Association asDictionary thing?
> >>
> >> But I thought Neo might give me something like that, as it must be
> terribly common?
> >>
> >> Tim
> >>
> >>> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
> >>>
> >>> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
> >>>
> >>> JSON cannot deal with Associations by themselves.
> >>>
> >>>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
> >>>>
> >>>> I am stumped about how to write out some simple json (for a config
> file). I didn't think I need Neo, and STONJSON would be fine but it seems
> like creating items like:
> >>>>
> >>>> { 'id'-> self id. 'name' -> self name }
> >>>>
> >>>> gives an error about the association. I think you have to do: {
> ('id'-> self id) asDictionary. ('name' -> self name) asDictionary }
> everywhereâ¦.
> >>>>
> >>>> But when I switch over to NeoJsonWriter it also complains about
> Assocations too. I just want a simple output like:
> >>>> { "id" : 12, "name" : "timâ }
> >>>>
> >>>> I thought it was simple to do this? Am I missing something obvious.
> >>>>
> >>>> Tim
> >>>
> >>>
> >>
> >>
> >
> >
>
>
>
Feb. 28, 2019
Richard Kenneth Eng is NOT Mr. Smalltalk
by Michael Zeder
Dear community,
I am a silent follower of this list. Now, I feel urged to speak up not
on a technical, but a community matter.
Every village deserves it's fool. And a wise man does not feed the
troll (i did, and doing it right now, sorry). But if this fool is about
to take over a considerable amount of public control, the community has
to stand up against it. So, I put this to you:
I frequently research on Smalltalk-related topics (computer scientist,
try to devote time to open source dev next to my small enterprise). And
more and more, I notice that Google search results show very much on
top of the result list contributions by a self-appointed "Mr.
Smalltalk" aka R.K.Eng. who excels at SEO and flooding social media.
While self-initiatives are a thriving force for open communities, in
this case:
* one individual is hoging credit and applause, without ever having
commited a single line of code, putting himself into focus (without
having any profound knowledge; to the contrary: he shows a deep
ignorance towards "our" and other languages, throwing around dubious
advertisment slogans),
* ...is throwing around with wrong claims (pulling off any potentially
interested developer),
* ...is starting pointless flame wars against other programming
languages (again: detrimental to our community)
* ...is doing SEO to make Google show his own results before FOSS
community or sciences pages.
* ...is getting traction (and money) for his own ends (publicity for
the self-appointed "Mr. Smalltalk")
* ...denies community leadership by merit (Pharo core developers do
know, what they have created and where they want to go in the future,
and which audience we should target, they don't need a clueless person
telling them to "get into TIOBE index", just for example)
* is claiming credit for the work, others have done, fostering his own
publicity (not the interests of Pharo/VisualWorks etc).
Here is the Medium thread that made me write this mail to you all.
https://medium.com/@michael.z3d3r/who-is-this-self-appointed-mr-9ad9a18676eb
https://medium.com/@richardeng/even-people-who-understand-prototypal-inheri…
the bottom line of our tedious flame war in a screenshot:
PS: a side note on Javascript (with lower S). wether you love or hate
this quirky lovechild of Lisp and Self/Smalltalk, telling JS developers
they are stupid and that they should abandon powerful Vue.js, for
example, in favor of Amber Smalltalk [cudos to Amber devs! great
thing!]) is utterly stupid! Every professional Javascript developer,
who is trying Smalltalk the first time, because he/she has read in a
post of "Mr. Smalltalk", that it is better, will instantly dismiss
Smalltalk and be disappointed. I love Smalltalk (certainly more than
JS), but it is detrimental, to throw around with these wrong claims
(which in the end are only a self-serving, ego-centric,
attention-greedy campaign to promote "Mr. Smalltalk" himself, a total
newbie, who claims credit for the work of others).
My suggestion: This community is open and inclusive. But we should
clarify, that if a single individual repeatedly goes against those, who
do the actual work, claims credits, insults people, then this person is
not fit to be part of this community. It sheds a very bad light onto
us. --> If R.K. Eng cannot respect community structure and decisions,
we should exclude him officially and publicly take distance from this
person.
Thank you for your attention.
Michael Zeder
Feb. 28, 2019
Re: [Pharo-users] Interval form: x to: y when x > y - or how to count down...
by Richard O'Keefe
I would expect 1:0 to give me an empty sequence
because (a) for all other natural numbers n,
1:n gives me a sequence of n numbers, and (b)
how else am I supposed to get an empty sequence?
Under your interpretation, (x to: y) would never
be empty.
This has absolutely nothing to do with C.
As I commented, every programming language I
know except S uses a default increment of +1
in counted loops, if it allows default increments
at all. Fortran, Algol 68, Pascal, PL/I, the
seq(1) command in Unix, Haskell, the `seq'
function in Erlang, between/3 in Prolog, OCaml,
F#, InterLISP-D, and so it goes.
Fortran is an interesting case, because Fortran 66
left DO label id = lower,upper
unspecified when lower > upper and several compilers
made such loops execute once, to the point where
programmer tended to think the standard required that,
but Fortran 77 nailed it down: NO iterations in that
case.
Here's a typical use of #to:do:
s := 0.
1 to: a size do: [:i |
a at: i put: (s := (a at: i) + s)].
Why would you think it a good idea for this
to crash if the array is empty?
Smalltalk being Smalltalk, nothing stops you adding
through: end do: aBlock
self to: end by: (end < self ifTrue: [-1] ifFalse: [1])
do: aBlock.
to Integer if you really want to.
Oh, there's an ambiguity. Should
5 through 1 mean 5,4,3,2,1 or 1,2,3,4,5?
Both can be argued for.
On Fri, 1 Mar 2019 at 02:03, Tim Mackinnon <tim(a)testit.works> wrote:
> Hi Richard - but why would you expect 1 to: 0 to give you an empty
> sequence?
>
> If I inspect â0 to: 1â I see:
> 1 -> 0
> 2 -> 1
>
> So I would expect â1 to: 0â to see:
> 1 -> 1
> 2 -> 0.
>
> I asked for a sequence going from 1 down to 0 (in my mind). Knowing about
> all the by: -1 stuff seems very Câish.
>
> Of course, I get that maybe it will break peoples existing code (and maybe
> that would be why it never gets changed) - but it still feels very strange.
> Or am I missing something?
>
> Tim
>
> On 28 Feb 2019, at 12:38, Richard O'Keefe <raoknz(a)gmail.com> wrote:
>
> Of the couple of hundred programming languages I have
> used, there is precisely one that does what you expect
> (the S programming language, as implemented in R).
> And it is a major pain in the posterior with no upside
> that I can discern.
>
> Suppose I want a sequence of n consecutive integers
> beginning with 1. In Smalltalk, (1 to: n) does the
> job. In R, 1:n *almost* does the job. But what
> happens when n = 0? Smalltalk gives me the right
> answer: an empty sequence. R gives me (1,0). That
> means that *every* *flaming* *time* I write
> for (i in 1:n) {...}
> I have to take special care to ensure that n is not
> 0, sometimes even having to whack in an extra
> if (n > 0) for (i in 1:n) {...}
>
> Trawling through my Smalltalk code, I find that about
> 6.8% of my counted loops are by: -1,
> 0.7% of them are by: a negative number other than -1,
> 2.5% of them are by: a positive number other than 1,
> 90 % are just to:do: with no by:
> Inspecting some of the 90% showed that many of them
> would go catastrophically wrong if 1 to: 0 do:
> performed its body
>
> On Sat, 23 Feb 2019 at 03:58, Tim Mackinnon <tim(a)testit.works> wrote:
>
>> I've just been caught out with Intervals - why can't you do:
>> 5 to: 1 do: [ :i | Transcript show: i printString] (eg a negative
>> interval)?
>>
>> if you want to iterate down a series of numbers do you really have to do:
>> 5 to: 1 by: -1 do: [â¦
>>
>> I always assumed that if x > y the step was automatically -1 (but its
>> not).
>>
>> I asked on Discord - and someone pointed out that if you use variables it
>> could be ambiguous - but is it really? I donât know if other smalltalks do
>> it this way (I vaguely recall Dolphin going down, but not sure).
>>
>> Either way the Interval comment should mention this - and Iâll correct it
>> when I get the wisdom of the crowd here.
>>
>> Tim
>>
>
>
Feb. 28, 2019
Re: [Pharo-users] Mac OS X test [ smaller image ]
by Hilaire
Thanks for the feedback Cedrick. We have all different experiences, I
guess depending on the OS X version.
Did you try to drag the DrGeo.app in the Application location and start
it from there?
Hilaire
Le 28/02/2019 à 13:08, Cédrick Béler a écrit :
> Can someone with privilege to the Application location, test this new
> DrGeo bundle[2]? THANKS !
--
Dr. Geo
http://drgeo.eu
Feb. 28, 2019
Re: [Pharo-users] How to write out simple Json?
by Sven Van Caekenberghe
This is wrong !!
Think about it, what would then happen with a mixed list ?
{ #key->#value. 1. true }
That would generate invalid JSON.
> On 28 Feb 2019, at 14:56, Tim Mackinnon <tim(a)testit.works> wrote:
>
> As I merrily chat to myself - I noticed that STONWriter almost does what I need - it just complains in #writeAssociation: so I make a subclass STONJSONWriter and override:
>
> writeAssociation: association
> âdonât smack meâ¦.
> jsonMode
> ifTrue: [ self error: 'wrong object class for JSON mode' ]."
> self
> encodeKey: association key
> value: association value
>
> I get exactly what I would expect - valid Json from simple Collections, Associations and Array.
>
> So would it be handy to have such a writer in the image (or let STONWriter be more configurable for this?)
>
> Tim
>
> p.s. my finally example would then be:
>
> ex := { 'track'-> 'pharo'.
> 'language' -> 'smalltalk'.
> 'exercises' ->
> {'slug' -> 'hello'.
> 'id' -> 55.
> 'topics' -> #('a' 'b' 'c') }
> }.
>
> String streamContents: [ :stream |
> (STONJSONWriter on: (stream))
> jsonMode: true;
> prettyPrint: true;
> writeList: ex ].
>
>> On 28 Feb 2019, at 13:45, Tim Mackinnon <tim(a)testit.works> wrote:
>>
>> Just to add more flavour to this - it seems quite wordy that we have to do this (or equivalent) to write some config.
>>
>> ex := OrderedDictionary new
>> at: 'track' put: 'pharo';
>> at: 'language' put: 'smalltalk';
>> at: 'exercises' put: (
>> OrderedDictionary new
>> at: 'slug' put: 'hello';
>> at: 'id' put: 55;
>> at: 'topics' put: #('a' 'b' 'c');
>> yourself );
>> yourself.
>>
>> String streamContents: [ :stream |
>> (NeoJSONWriter on: (stream)) prettyPrint: true;
>> mapInstVarsFor: Association;
>> nextPut: ex ].
>>
>> So Iâm still wondering the NeoJSONObjectMapping can do something easy for Association other than simply mapInstVars?
>>
>>
>>> On 28 Feb 2019, at 13:36, Tim Mackinnon <tim(a)testit.works> wrote:
>>>
>>> Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it?
>>>
>>> E.g. the following is very convenient to write - but doesnât work (as you have $â and not $â )
>>>
>>> ex := { 'track'-> 'pharo'.
>>> 'language' -> 'smalltalk'.
>>> 'exercises' ->
>>> {'slug' -> 'hello'.
>>> 'id' -> 55.
>>> 'topics' -> #('a' 'b' 'c') }
>>> }.
>>>
>>> String streamContents: [ :stream |
>>> (STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
>>>
>>> I had thought maybe NeoJSON might help and put:
>>>
>>> String streamContents: [ :stream |
>>> (NeoJSONWriter on: (stream)) prettyPrint: true;
>>> "mapInstVarsFor: Association;"
>>> nextPut: ex ].
>>>
>>> But I get the error about missing an association mapping. If I uncomment that bit - I get things like: { "value" : âpharo" },
>>>
>>> So is there a way I can write a simple mapper for Association that will write out the key in a string and the value in a string?
>>>
>>> Iâm quite suprised we canât easily write out fragments of Json in our code in a light weight way? Or do I need to make a proper Config object and then teach it how to map properly such that rather than fiddling with our { x->y } dictionary sugar I do something like:
>>>
>>> Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is: #(1 2 3).
>>>
>>> And I guess at:is: can do the Association asDictionary thing?
>>>
>>> But I thought Neo might give me something like that, as it must be terribly common?
>>>
>>> Tim
>>>
>>>> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>>>>
>>>> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
>>>>
>>>> JSON cannot deal with Associations by themselves.
>>>>
>>>>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
>>>>>
>>>>> I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like:
>>>>>
>>>>> { 'id'-> self id. 'name' -> self name }
>>>>>
>>>>> gives an error about the association. I think you have to do: { ('id'-> self id) asDictionary. ('name' -> self name) asDictionary } everywhereâ¦.
>>>>>
>>>>> But when I switch over to NeoJsonWriter it also complains about Assocations too. I just want a simple output like:
>>>>> { "id" : 12, "name" : "timâ }
>>>>>
>>>>> I thought it was simple to do this? Am I missing something obvious.
>>>>>
>>>>> Tim
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Feb. 28, 2019
Re: [Pharo-users] How to write out simple Json?
by Sven Van Caekenberghe
I really don't understand.
JSON needs Dictionaries and Arrays (or other Sequenceable Collections). That has nothing to do with Pharo or how NeoJSON or STONJSON are implemented - it is what defines JSON.
Of course, compatible objects work as well (NeoJSONObject is an example). You could make your own.
Since there is no literal syntax in Pharo for a Dictionary, you have to write something like
>>> { #id->1. #name->'tim' } asDictionary
This has been discussed for years, I won't start that again. The above is short enough for me, but a bit of a pain when nesting.
Part of the power of Pharo is a very simple syntax, we can express an awful lot with very few constructs.
Your mapping examples won't work: you try to make something that is not a map but a list of associations into a map, that is simply not possible, sorry.
> On 28 Feb 2019, at 14:45, Tim Mackinnon <tim(a)testit.works> wrote:
>
> Just to add more flavour to this - it seems quite wordy that we have to do this (or equivalent) to write some config.
>
> ex := OrderedDictionary new
> at: 'track' put: 'pharo';
> at: 'language' put: 'smalltalk';
> at: 'exercises' put: (
> OrderedDictionary new
> at: 'slug' put: 'hello';
> at: 'id' put: 55;
> at: 'topics' put: #('a' 'b' 'c');
> yourself );
> yourself.
>
> String streamContents: [ :stream |
> (NeoJSONWriter on: (stream)) prettyPrint: true;
> mapInstVarsFor: Association;
> nextPut: ex ].
>
> So Iâm still wondering the NeoJSONObjectMapping can do something easy for Association other than simply mapInstVars?
>
>
>> On 28 Feb 2019, at 13:36, Tim Mackinnon <tim(a)testit.works> wrote:
>>
>> Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it?
>>
>> E.g. the following is very convenient to write - but doesnât work (as you have $â and not $â )
>>
>> ex := { 'track'-> 'pharo'.
>> 'language' -> 'smalltalk'.
>> 'exercises' ->
>> {'slug' -> 'hello'.
>> 'id' -> 55.
>> 'topics' -> #('a' 'b' 'c') }
>> }.
>>
>> String streamContents: [ :stream |
>> (STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
>>
>> I had thought maybe NeoJSON might help and put:
>>
>> String streamContents: [ :stream |
>> (NeoJSONWriter on: (stream)) prettyPrint: true;
>> "mapInstVarsFor: Association;"
>> nextPut: ex ].
>>
>> But I get the error about missing an association mapping. If I uncomment that bit - I get things like: { "value" : âpharo" },
>>
>> So is there a way I can write a simple mapper for Association that will write out the key in a string and the value in a string?
>>
>> Iâm quite suprised we canât easily write out fragments of Json in our code in a light weight way? Or do I need to make a proper Config object and then teach it how to map properly such that rather than fiddling with our { x->y } dictionary sugar I do something like:
>>
>> Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is: #(1 2 3).
>>
>> And I guess at:is: can do the Association asDictionary thing?
>>
>> But I thought Neo might give me something like that, as it must be terribly common?
>>
>> Tim
>>
>>> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>>>
>>> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
>>>
>>> JSON cannot deal with Associations by themselves.
>>>
>>>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
>>>>
>>>> I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like:
>>>>
>>>> { 'id'-> self id. 'name' -> self name }
>>>>
>>>> gives an error about the association. I think you have to do: { ('id'-> self id) asDictionary. ('name' -> self name) asDictionary } everywhereâ¦.
>>>>
>>>> But when I switch over to NeoJsonWriter it also complains about Assocations too. I just want a simple output like:
>>>> { "id" : 12, "name" : "timâ }
>>>>
>>>> I thought it was simple to do this? Am I missing something obvious.
>>>>
>>>> Tim
>>>
>>>
>>
>>
>
>
Feb. 28, 2019
Re: [Pharo-users] How to write out simple Json?
by Tim Mackinnon
As I merrily chat to myself - I noticed that STONWriter almost does what I need - it just complains in #writeAssociation: so I make a subclass STONJSONWriter and override:
writeAssociation: association
âdonât smack meâ¦.
jsonMode
ifTrue: [ self error: 'wrong object class for JSON mode' ]."
self
encodeKey: association key
value: association value
I get exactly what I would expect - valid Json from simple Collections, Associations and Array.
So would it be handy to have such a writer in the image (or let STONWriter be more configurable for this?)
Tim
p.s. my finally example would then be:
ex := { 'track'-> 'pharo'.
'language' -> 'smalltalk'.
'exercises' ->
{'slug' -> 'hello'.
'id' -> 55.
'topics' -> #('a' 'b' 'c') }
}.
String streamContents: [ :stream |
(STONJSONWriter on: (stream))
jsonMode: true;
prettyPrint: true;
writeList: ex ].
> On 28 Feb 2019, at 13:45, Tim Mackinnon <tim(a)testit.works> wrote:
>
> Just to add more flavour to this - it seems quite wordy that we have to do this (or equivalent) to write some config.
>
> ex := OrderedDictionary new
> at: 'track' put: 'pharo';
> at: 'language' put: 'smalltalk';
> at: 'exercises' put: (
> OrderedDictionary new
> at: 'slug' put: 'hello';
> at: 'id' put: 55;
> at: 'topics' put: #('a' 'b' 'c');
> yourself );
> yourself.
>
> String streamContents: [ :stream |
> (NeoJSONWriter on: (stream)) prettyPrint: true;
> mapInstVarsFor: Association;
> nextPut: ex ].
>
> So Iâm still wondering the NeoJSONObjectMapping can do something easy for Association other than simply mapInstVars?
>
>
>> On 28 Feb 2019, at 13:36, Tim Mackinnon <tim(a)testit.works> wrote:
>>
>> Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it?
>>
>> E.g. the following is very convenient to write - but doesnât work (as you have $â and not $â )
>>
>> ex := { 'track'-> 'pharo'.
>> 'language' -> 'smalltalk'.
>> 'exercises' ->
>> {'slug' -> 'hello'.
>> 'id' -> 55.
>> 'topics' -> #('a' 'b' 'c') }
>> }.
>>
>> String streamContents: [ :stream |
>> (STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
>>
>> I had thought maybe NeoJSON might help and put:
>>
>> String streamContents: [ :stream |
>> (NeoJSONWriter on: (stream)) prettyPrint: true;
>> "mapInstVarsFor: Association;"
>> nextPut: ex ].
>>
>> But I get the error about missing an association mapping. If I uncomment that bit - I get things like: { "value" : âpharo" },
>>
>> So is there a way I can write a simple mapper for Association that will write out the key in a string and the value in a string?
>>
>> Iâm quite suprised we canât easily write out fragments of Json in our code in a light weight way? Or do I need to make a proper Config object and then teach it how to map properly such that rather than fiddling with our { x->y } dictionary sugar I do something like:
>>
>> Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is: #(1 2 3).
>>
>> And I guess at:is: can do the Association asDictionary thing?
>>
>> But I thought Neo might give me something like that, as it must be terribly common?
>>
>> Tim
>>
>>> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>>>
>>> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
>>>
>>> JSON cannot deal with Associations by themselves.
>>>
>>>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
>>>>
>>>> I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like:
>>>>
>>>> { 'id'-> self id. 'name' -> self name }
>>>>
>>>> gives an error about the association. I think you have to do: { ('id'-> self id) asDictionary. ('name' -> self name) asDictionary } everywhereâ¦.
>>>>
>>>> But when I switch over to NeoJsonWriter it also complains about Assocations too. I just want a simple output like:
>>>> { "id" : 12, "name" : "timâ }
>>>>
>>>> I thought it was simple to do this? Am I missing something obvious.
>>>>
>>>> Tim
>>>
>>>
>>
>>
>
>
Feb. 28, 2019
Re: [Pharo-users] How to write out simple Json?
by Tim Mackinnon
Just to add more flavour to this - it seems quite wordy that we have to do this (or equivalent) to write some config.
ex := OrderedDictionary new
at: 'track' put: 'pharo';
at: 'language' put: 'smalltalk';
at: 'exercises' put: (
OrderedDictionary new
at: 'slug' put: 'hello';
at: 'id' put: 55;
at: 'topics' put: #('a' 'b' 'c');
yourself );
yourself.
String streamContents: [ :stream |
(NeoJSONWriter on: (stream)) prettyPrint: true;
mapInstVarsFor: Association;
nextPut: ex ].
So Iâm still wondering the NeoJSONObjectMapping can do something easy for Association other than simply mapInstVars?
> On 28 Feb 2019, at 13:36, Tim Mackinnon <tim(a)testit.works> wrote:
>
> Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it?
>
> E.g. the following is very convenient to write - but doesnât work (as you have $â and not $â )
>
> ex := { 'track'-> 'pharo'.
> 'language' -> 'smalltalk'.
> 'exercises' ->
> {'slug' -> 'hello'.
> 'id' -> 55.
> 'topics' -> #('a' 'b' 'c') }
> }.
>
> String streamContents: [ :stream |
> (STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
>
> I had thought maybe NeoJSON might help and put:
>
> String streamContents: [ :stream |
> (NeoJSONWriter on: (stream)) prettyPrint: true;
> "mapInstVarsFor: Association;"
> nextPut: ex ].
>
> But I get the error about missing an association mapping. If I uncomment that bit - I get things like: { "value" : âpharo" },
>
> So is there a way I can write a simple mapper for Association that will write out the key in a string and the value in a string?
>
> Iâm quite suprised we canât easily write out fragments of Json in our code in a light weight way? Or do I need to make a proper Config object and then teach it how to map properly such that rather than fiddling with our { x->y } dictionary sugar I do something like:
>
> Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is: #(1 2 3).
>
> And I guess at:is: can do the Association asDictionary thing?
>
> But I thought Neo might give me something like that, as it must be terribly common?
>
> Tim
>
>> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>>
>> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
>>
>> JSON cannot deal with Associations by themselves.
>>
>>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
>>>
>>> I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like:
>>>
>>> { 'id'-> self id. 'name' -> self name }
>>>
>>> gives an error about the association. I think you have to do: { ('id'-> self id) asDictionary. ('name' -> self name) asDictionary } everywhereâ¦.
>>>
>>> But when I switch over to NeoJsonWriter it also complains about Assocations too. I just want a simple output like:
>>> { "id" : 12, "name" : "timâ }
>>>
>>> I thought it was simple to do this? Am I missing something obvious.
>>>
>>> Tim
>>
>>
>
>
Feb. 28, 2019
Re: [Pharo-users] How to write out simple Json?
by Tim Mackinnon
Hi Sven - is there no convenience shortcut we can use in our code to make this less wordy when we are specifying it?
E.g. the following is very convenient to write - but doesnât work (as you have $â and not $â )
ex := { 'track'-> 'pharo'.
'language' -> 'smalltalk'.
'exercises' ->
{'slug' -> 'hello'.
'id' -> 55.
'topics' -> #('a' 'b' 'c') }
}.
String streamContents: [ :stream |
(STONWriter on: (stream)) prettyPrint: true; writeList: ex ].
I had thought maybe NeoJSON might help and put:
String streamContents: [ :stream |
(NeoJSONWriter on: (stream)) prettyPrint: true;
"mapInstVarsFor: Association;"
nextPut: ex ].
But I get the error about missing an association mapping. If I uncomment that bit - I get things like: { "value" : âpharo" },
So is there a way I can write a simple mapper for Association that will write out the key in a string and the value in a string?
Iâm quite suprised we canât easily write out fragments of Json in our code in a light weight way? Or do I need to make a proper Config object and then teach it how to map properly such that rather than fiddling with our { x->y } dictionary sugar I do something like:
Config new at: âidâ is: 123; at: ânameâ is: âTimâ; at: âexercisesâ is: #(1 2 3).
And I guess at:is: can do the Association asDictionary thing?
But I thought Neo might give me something like that, as it must be terribly common?
Tim
> On 28 Feb 2019, at 13:16, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>
> STONJSON toString: { #id->1. #name->'tim' } asDictionary.
>
> JSON cannot deal with Associations by themselves.
>
>> On 28 Feb 2019, at 14:05, Tim Mackinnon <tim(a)testit.works> wrote:
>>
>> I am stumped about how to write out some simple json (for a config file). I didn't think I need Neo, and STONJSON would be fine but it seems like creating items like:
>>
>> { 'id'-> self id. 'name' -> self name }
>>
>> gives an error about the association. I think you have to do: { ('id'-> self id) asDictionary. ('name' -> self name) asDictionary } everywhereâ¦.
>>
>> But when I switch over to NeoJsonWriter it also complains about Assocations too. I just want a simple output like:
>> { "id" : 12, "name" : "timâ }
>>
>> I thought it was simple to do this? Am I missing something obvious.
>>
>> Tim
>
>
Feb. 28, 2019
Re: [Pharo-users] Repeateble URLs - REST?
by sergio ruiz
I like that http://www.bagelconcertfinder.com uses Seaside and also my
Twitter Bootstrap Library.
Thanks so much for your library!
I have built several applications in seaside, and always dig using it..
itâs my go to framework when I do a project on my own..
Seaside by default works with stateful (web) components - making it easy to
develop - but possibly hard to scale to be the next Twitter, Amazon, ... ;)
most everything I work on will never be the next twitter or amazon.. so i
am fine tweaking here or there..
I have thought about doing exactly what you are talking about..
In my day job, we use LOTS of Angular. I thought about setting up a REST
interface using Teapot, and using angular for the web part..
This provides for a much more interactive user experience, but I also
totally love how seaside works..
Maybe for my CMS type project, Iâll use Teapot/Angular..
I will have to think about this for a bitâ¦
I did a project last year where I used teapot in conjunction with an SMS
interface to create a very useful bot..
This was incredibly handy..
----
peace,
sergio
photographer, journalist, visionary
Public Key: http://bit.ly/29z9fG0
#BitMessage BM-NBaswViL21xqgg9STRJjaJaUoyiNe2dV
http://www.codeandmusic.com
http://www.twitter.com/sergio_101
http://www.facebook.com/sergio101
Feb. 28, 2019