Convert Literal array into Dynamic array
HI, friends! Can anyone help me how to convert literal array: #(2 3 4) into the dynamic array: {2. 3. 4}? Thanks a lot, Khrystyna! -- View this message in context: http://forum.world.st/Convert-Literal-array-into-Dynamic-array-tp4942305.htm... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 16 Apr 2017, at 16:37, chrismihaylyk <chrismihaylyk@gmail.com> wrote:
HI, friends!
Can anyone help me how to convert literal array: #(2 3 4) into the dynamic array: {2. 3. 4}?
this is not a dynamic array (that does not exist on Pharo). check, if you do: #(2 3 4) = {2. 3. 4} ==> true and: #(2 3 4) class = {2. 3. 4} class ==> true in fact, the only difference between them is that the first is literal (it will be as is in the compiled code) and the second is a runtime array (it will be evaluated on execution). Now, perhaps what you want is to transform an Array into a Collection that accepts additions (that would be a âdynamicâ collection on Pharo).. For that you can do: a := #(2 3 4) asOrderedCollection. a add: 5. a ==> anOrderedCollection(2 3 4 5). (note that you could want a Set⦠or whatever⦠but the most common transformation is an array into an OrderedCollection (because it preserves order, etc.) cheers, Esteban
Thanks a lot, Khrystyna!
-- View this message in context: http://forum.world.st/Convert-Literal-array-into-Dynamic-array-tp4942305.htm... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Thank you very much! Now I understand. Actually, I need this interpretation {7. 8. "f"} for writing parser of javascript queries which is used in MongoDB shell, to be able to execute this with MongoQuery Pharo class. Maybe, you could help me how to implement it? 2017-04-16 18:19 GMT+03:00 Esteban Lorenzano <estebanlm@gmail.com>:
On 16 Apr 2017, at 16:37, chrismihaylyk <chrismihaylyk@gmail.com> wrote:
HI, friends!
Can anyone help me how to convert literal array: #(2 3 4) into the dynamic array: {2. 3. 4}?
this is not a dynamic array (that does not exist on Pharo). check, if you do:
#(2 3 4) = {2. 3. 4} ==> true
and:
#(2 3 4) class = {2. 3. 4} class ==> true
in fact, the only difference between them is that the first is literal (it will be as is in the compiled code) and the second is a runtime array (it will be evaluated on execution).
Now, perhaps what you want is to transform an Array into a Collection that accepts additions (that would be a âdynamicâ collection on Pharo)..
For that you can do:
a := #(2 3 4) asOrderedCollection. a add: 5.
a ==> anOrderedCollection(2 3 4 5).
(note that you could want a Set⦠or whatever⦠but the most common transformation is an array into an OrderedCollection (because it preserves order, etc.)
cheers, Esteban
Thanks a lot, Khrystyna!
-- View this message in context: http://forum.world.st/Convert-
Literal-array-into-Dynamic-array-tp4942305.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On Mon, Apr 17, 2017 at 1:30 AM, Ð¥ÑиÑÑина ÐÐ¸Ñ Ð°Ð¹Ð»Ñк <chrismihaylyk@gmail.com> wrote:
Actually, I need this interpretation {7. 8. "f"} for writing parser of javascript queries which is used in MongoDB shell, to be able to execute this with MongoQuery Pharo class. Maybe, you could help me how to implement it?
Do you mean parsing Json syntax? <https://www.mongodb.com/json-and-bson> https://www.mongodb.com/json-and-bson Maybe this is useful https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBo ok/lastSuccessfulBuild/artifact/book-result/NeoJSON/NeoJSON.html cheers -ben
Thanks! But I've just handled it by using STON fromString: Khrystyna. 2017-04-17 19:14 GMT+03:00 Ben Coman <btc@openinworld.com>:
On Mon, Apr 17, 2017 at 1:30 AM, Ð¥ÑиÑÑина ÐÐ¸Ñ Ð°Ð¹Ð»Ñк < chrismihaylyk@gmail.com> wrote:
Actually, I need this interpretation {7. 8. "f"} for writing parser of javascript queries which is used in MongoDB shell, to be able to execute this with MongoQuery Pharo class. Maybe, you could help me how to implement it?
Do you mean parsing Json syntax? <https://www.mongodb.com/json-and-bson> https://www.mongodb.com/json-and-bson
Maybe this is useful https://ci.inria.fr/pharo-contribution/job/EnterprisePharoBo ok/lastSuccessfulBuild/artifact/book-result/NeoJSON/NeoJSON.html cheers -ben
participants (4)
-
Ben Coman -
chrismihaylyk -
Esteban Lorenzano -
Ð¥ÑиÑÑина ÐÐ¸Ñ Ð°Ð¹Ð»Ñк