From joseph.alotta at gmail.com Fri Jul 1 16:40:37 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Fri Jul 1 16:40:45 2016 Subject: [Newbies] '($1,925.46)' asNumber Message-ID: <44BAFECC-AF27-46FC-A402-FCEF4975369F@gmail.com> Greetings, I want to convert a String with parenthesis and dollar sign to a Number or Float. '($1,925.46)? asNumber Is there something out of the box that does this, or do I have to write it myself, character by character? Should I use a ReadStream? Sincerely, Joe. From ron at usmedrec.com Fri Jul 1 17:25:00 2016 From: ron at usmedrec.com (Ron Teitelbaum) Date: Fri Jul 1 17:24:51 2016 Subject: [Newbies] '($1,925.46)' asNumber In-Reply-To: <44BAFECC-AF27-46FC-A402-FCEF4975369F@gmail.com> References: <44BAFECC-AF27-46FC-A402-FCEF4975369F@gmail.com> Message-ID: <315101d1d3bd$7fcf5970$7f6e0c50$@usmedrec.com> Hi Joe, If you know the format is consistent and you don't really need much error handling then something like this would work ('($1,925.46)' reject: [:e | '($),' includes: e]) asNumber All the best, Ron Teitelbaum > -----Original Message----- > From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners- > bounces@lists.squeakfoundation.org] On Behalf Of Joseph Alotta > Sent: Friday, July 01, 2016 12:41 PM > To: beginners@lists.squeakfoundation.org > Subject: [Newbies] '($1,925.46)' asNumber > > Greetings, > > I want to convert a String with parenthesis and dollar sign to a Number or > Float. > > '($1,925.46)? asNumber > > Is there something out of the box that does this, or do I have to write it > myself, character by character? > > Should I use a ReadStream? > > > Sincerely, > > Joe. > > > _______________________________________________ > Beginners mailing list > Beginners@lists.squeakfoundation.org > http://lists.squeakfoundation.org/mailman/listinfo/beginners From joseph.alotta at gmail.com Fri Jul 1 18:59:03 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Fri Jul 1 19:40:17 2016 Subject: [Newbies] Re: '($1,925.46)' asNumber In-Reply-To: <315101d1d3bd$7fcf5970$7f6e0c50$@usmedrec.com> References: <44BAFECC-AF27-46FC-A402-FCEF4975369F@gmail.com> <315101d1d3bd$7fcf5970$7f6e0c50$@usmedrec.com> Message-ID: <826872AD-62B1-45A5-BE67-6242B5281E4D@gmail.com> Thanks, Ron. I needed to preserve the negative, so I append a minus sign, then use your snippet. , str := '($1,925.46)' . ('(*)' match: str ) ifTrue: [str := '-', str]. str := str reject: [:e | '($,)' includes: e]. num := str asNumber => -1925.46 Sincerely, Joe. -- View this message in context: http://forum.world.st/1-925-46-asNumber-tp4904523p4904534.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160701/0ce91a79/attachment.htm From ron at usmedrec.com Fri Jul 1 21:36:20 2016 From: ron at usmedrec.com (Ron Teitelbaum) Date: Fri Jul 1 21:36:11 2016 Subject: [Newbies] Re: '($1,925.46)' asNumber In-Reply-To: <826872AD-62B1-45A5-BE67-6242B5281E4D@gmail.com> References: <44BAFECC-AF27-46FC-A402-FCEF4975369F@gmail.com> <315101d1d3bd$7fcf5970$7f6e0c50$@usmedrec.com> <826872AD-62B1-45A5-BE67-6242B5281E4D@gmail.com> Message-ID: <321901d1d3e0$9b978ab0$d2c6a010$@usmedrec.com> From: Joseph Alotta Sent: Friday, July 01, 2016 2:59 PM Thanks, Ron. I needed to preserve the negative, so I append a minus sign, then use your snippet. [Ron Teitelbaum] Excellent! Well done! , str := '($1,925.46)' . ('(*)' match: str ) ifTrue: [str := '-', str]. str := str reject: [:e | '($,)' includes: e]. num := str asNumber => -1925.46 Sincerely, Joe. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160701/1ac7370c/attachment.htm From joseph.alotta at gmail.com Thu Jul 7 02:58:30 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Thu Jul 7 02:58:35 2016 Subject: [Newbies] sorting by key1 inside of key2 Message-ID: Greetings, I have a collection of Transaction objects. They have instance variables of category and payee. A category might be ?Office Expense? and a payee might be ?Costco? or ?Amazon?. I want to sort by categories and then payees. Office Expense, Amazon?.. ?.. ?. ?. Office Expense, Costco ?. ? ? Here is some of my code: sorted := trans asSortedCollection: [:a :b | (a category) < (b category)]. sorted do: [ :tr | | cat pay | cat := tr category. pay := tr payee. stream nextPutAll: (tr myPrintFormat2). How do I make the sort block sort on both keys? Sincerely, Joe. From btc at openinworld.com Thu Jul 7 04:58:50 2016 From: btc at openinworld.com (Ben Coman) Date: Thu Jul 7 04:59:13 2016 Subject: [Newbies] sorting by key1 inside of key2 In-Reply-To: References: Message-ID: On Thu, Jul 7, 2016 at 10:58 AM, Joseph Alotta wrote: > Greetings, > > I have a collection of Transaction objects. They have instance variables of category and payee. > > A category might be ?Office Expense? and a payee might be ?Costco? or ?Amazon?. > > I want to sort by categories and then payees. > > Office Expense, Amazon?.. > ?.. > ?. > ?. > Office Expense, Costco > ?. > ? > ? > > Here is some of my code: > > > > sorted := trans asSortedCollection: [:a :b | (a category) < (b category)]. Just guessing... [:a :b | (a category) = (b category) ifFalse: [ (a category) < (b category) ] ifTrue: [ (a payee) < (b payee)]]. cheers -ben > > sorted do: [ :tr | | cat pay | > cat := tr category. > pay := tr payee. > > stream nextPutAll: (tr myPrintFormat2). > > > > How do I make the sort block sort on both keys? > > Sincerely, > > Joe. > > > > > > _______________________________________________ > Beginners mailing list > Beginners@lists.squeakfoundation.org > http://lists.squeakfoundation.org/mailman/listinfo/beginners From joseph.alotta at gmail.com Thu Jul 7 12:37:47 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Thu Jul 7 13:19:42 2016 Subject: [Newbies] Re: sorting by key1 inside of key2 In-Reply-To: References: Message-ID: thank you, ben!! > On Jul 6, 2016, at 11:17 PM, Ben Coman [via Smalltalk] wrote: > > [:a :b | (a category) = (b category) > ifFalse: [ (a category) < (b category) ] > ifTrue: [ (a payee) < (b payee)]]. -- View this message in context: http://forum.world.st/sorting-by-key1-inside-of-key2-tp4905286p4905348.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160707/620ecbba/attachment.htm From joseph.alotta at gmail.com Mon Jul 11 16:13:41 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Mon Jul 11 16:13:47 2016 Subject: [Newbies] evaluating strings as blocks Message-ID: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> Greetings, For debuting purposes, I want to build a string with calculations and then evaluate it. Something like: string := ?2 + 2 - 5?; and then do: string asBlock value => -1 How can I get this to work? Sincerely, Joe. From ron at usmedrec.com Mon Jul 11 16:59:50 2016 From: ron at usmedrec.com (Ron Teitelbaum) Date: Mon Jul 11 16:59:53 2016 Subject: [Newbies] evaluating strings as blocks In-Reply-To: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> References: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> Message-ID: <015101d1db95$a3f35ba0$ebda12e0$@usmedrec.com> Hi Joe, Have a look at Complier. Then try Complier evaluate: '1+1' All the best, Ron Teitelbaum From: Joseph Alotta Sent: Monday, July 11, 2016 12:14 PM Greetings, For debuting purposes, I want to build a string with calculations and then evaluate it. Something like: string := ?2 + 2 - 5?; and then do: string asBlock value => -1 How can I get this to work? Sincerely, Joe. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners From david.mitchell at gmail.com Mon Jul 11 16:59:47 2016 From: david.mitchell at gmail.com (David Mitchell) Date: Mon Jul 11 16:59:59 2016 Subject: [Newbies] evaluating strings as blocks In-Reply-To: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> References: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> Message-ID: Look at Compiler On Mon, Jul 11, 2016 at 11:13 AM Joseph Alotta wrote: > Greetings, > > For debuting purposes, I want to build a string with calculations and then > evaluate it. > > Something like: > > string := ?2 + 2 - 5?; > > and then do: > > > string asBlock value => -1 > > > How can I get this to work? > > > Sincerely, > > Joe. > > > _______________________________________________ > Beginners mailing list > Beginners@lists.squeakfoundation.org > http://lists.squeakfoundation.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160711/25dadd09/attachment.htm From joseph.alotta at gmail.com Mon Jul 11 16:22:19 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Mon Jul 11 17:04:43 2016 Subject: [Newbies] Re: evaluating strings as blocks In-Reply-To: References: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> Message-ID: thank you. > On Jul 11, 2016, at 11:18 AM, David Mitchell-10 [via Smalltalk] wrote: > > Look at Compiler > > On Mon, Jul 11, 2016 at 11:13 AM Joseph Alotta <[hidden email]> wrote: > Greetings, > > For debuting purposes, I want to build a string with calculations and then evaluate it. > > Something like: > > string := ?2 + 2 - 5?; > > and then do: > > > string asBlock value => -1 > > > How can I get this to work? > > > Sincerely, > > Joe. > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/evaluating-strings-as-blocks-tp4906034p4906041.html > To start a new topic under Squeak - Beginners, email ml-node+s1294792n107673h12@n4.nabble.com > To unsubscribe from Squeak - Beginners, click here. > NAML -- View this message in context: http://forum.world.st/evaluating-strings-as-blocks-tp4906034p4906042.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160711/1a27c2a0/attachment.htm From joseph.alotta at gmail.com Mon Jul 11 16:22:29 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Mon Jul 11 17:04:52 2016 Subject: [Newbies] Re: evaluating strings as blocks In-Reply-To: <015101d1db95$a3f35ba0$ebda12e0$@usmedrec.com> References: <780143BC-B9E4-456B-9A64-68B1C70873AC@gmail.com> <015101d1db95$a3f35ba0$ebda12e0$@usmedrec.com> Message-ID: <939FCA95-4896-411E-B6A1-B6EB4D91F646@gmail.com> thank you. > On Jul 11, 2016, at 11:17 AM, Ron Teitelbaum [via Smalltalk] wrote: > > Hi Joe, > > Have a look at Complier. > > Then try > > Complier evaluate: '1+1' > > All the best, > > Ron Teitelbaum > > > From: Joseph Alotta > Sent: Monday, July 11, 2016 12:14 PM > > > Greetings, > > For debuting purposes, I want to build a string with calculations and then evaluate it. > > Something like: > > string := ?2 + 2 - 5?; > > and then do: > > > string asBlock value => -1 > > > How can I get this to work? > > > Sincerely, > > Joe. > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/evaluating-strings-as-blocks-tp4906034p4906040.html > To start a new topic under Squeak - Beginners, email ml-node+s1294792n107673h12@n4.nabble.com > To unsubscribe from Squeak - Beginners, click here. > NAML -- View this message in context: http://forum.world.st/evaluating-strings-as-blocks-tp4906034p4906043.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160711/19c45888/attachment.htm From joseph.alotta at gmail.com Mon Jul 18 15:47:21 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Mon Jul 18 15:47:25 2016 Subject: [Newbies] Transcript Message-ID: Why is it slow to write on the Transcript. I thought with a powerful computer like this, it would be fast. Is it really doing that much or is there something in the code sleeping to a clock? Sincerely, Joe. From ron at usmedrec.com Mon Jul 18 16:48:31 2016 From: ron at usmedrec.com (Ron Teitelbaum) Date: Mon Jul 18 16:49:05 2016 Subject: [Newbies] Transcript In-Reply-To: References: Message-ID: <021801d1e114$37d73020$a7859060$@usmedrec.com> Hi Joe, It's probably not the transcript but everything else that is happening on your image. I'm not sure at what priority the transcript runs but if you have threads at higher priority running they have to finish first and then yield so that a lower priority thread can take over. That's when your transcript messages will show up. The transcript can also get you in trouble with threading, having multiple threads trying to write to the transcript. Make sure you are controlling access to the transcript if you are using it with multiple threads. All the best, Ron Teitelbaum -----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Joseph Alotta Sent: Monday, July 18, 2016 11:47 AM To: beginners@lists.squeakfoundation.org Subject: [Newbies] Transcript Why is it slow to write on the Transcript. I thought with a powerful computer like this, it would be fast. Is it really doing that much or is there something in the code sleeping to a clock? Sincerely, Joe. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners From Das.Linux at gmx.de Mon Jul 18 16:55:49 2016 From: Das.Linux at gmx.de (Tobias Pape) Date: Mon Jul 18 16:55:52 2016 Subject: [Newbies] Transcript In-Reply-To: <021801d1e114$37d73020$a7859060$@usmedrec.com> References: <021801d1e114$37d73020$a7859060$@usmedrec.com> Message-ID: <8E211949-35E0-4A67-BF86-8F695A8819F4@gmx.de> Hi Joseph On 18.07.2016, at 18:48, Ron Teitelbaum wrote: > Hi Joe, > > It's probably not the transcript but everything else that is happening on > your image. I'm not sure at what priority the transcript runs but if you > have threads at higher priority running they have to finish first and then > yield so that a lower priority thread can take over. That's when your > transcript messages will show up. > > The transcript can also get you in trouble with threading, having multiple > threads trying to write to the transcript. Make sure you are controlling > access to the transcript if you are using it with multiple threads. > Also, Writing to the Transcript is I/O. You'll have a similar effect if you use a low-level language like C and write to stdout. You should use the message Tally and look at what actually is slow. I bet it is the transcript writing; getting characters on screen is typically expensive, in most environments. Best regards -Tobias > All the best, > > Ron Teitelbaum From joseph.alotta at gmail.com Tue Jul 26 19:03:39 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Tue Jul 26 21:41:54 2016 Subject: [Newbies] indexing into a collection Message-ID: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> Greetings, I have a OrderedCollection of DrivingDays. an OrderedCollection(2016-01-02| quigley s| nil|18? 2016-01-03| marianos fresh| nil|5? 2016-01-04| fresh thyme| nil|5? 2016-01-05| panda express| nil|3? 2016-01-06| peets| nil|7? 2016-01-07| starbucks| nil|3?) I want to select aDrivingDay object from the list by date, update it by adding mileage and places visited and put it back into the list. If I #select the OrderedCollection, I get a copy of the item, not the same one in the OrderedCollection. How do I select an item in the list for update? Sincerely, Joe. From ron at usmedrec.com Tue Jul 26 21:53:58 2016 From: ron at usmedrec.com (Ron Teitelbaum) Date: Tue Jul 26 21:54:01 2016 Subject: [Newbies] indexing into a collection In-Reply-To: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> References: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> Message-ID: <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> Hi Joe, If the orderedCollection contains your object DrivingDays then select should give you the object and not a copy. You don't need to add it back to the collection just update the object. Check your code for anything that might be making a copy. All the best, Ron Teitelbaum -----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Joseph Alotta Sent: Tuesday, July 26, 2016 3:04 PM To: beginners@lists.squeakfoundation.org Subject: [Newbies] indexing into a collection Greetings, I have a OrderedCollection of DrivingDays. an OrderedCollection(2016-01-02| quigley s| nil|18? 2016-01-03| marianos fresh| nil|5? 2016-01-04| fresh thyme| nil|5? 2016-01-05| panda express| nil|3? 2016-01-06| peets| nil|7? 2016-01-07| starbucks| nil|3?) I want to select aDrivingDay object from the list by date, update it by adding mileage and places visited and put it back into the list. If I #select the OrderedCollection, I get a copy of the item, not the same one in the OrderedCollection. How do I select an item in the list for update? Sincerely, Joe. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners From btc at openinworld.com Wed Jul 27 00:09:03 2016 From: btc at openinworld.com (Ben Coman) Date: Wed Jul 27 00:09:25 2016 Subject: [Newbies] indexing into a collection In-Reply-To: <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> References: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> Message-ID: Hi Joe, As Ron said, you should not be getting a copy. If you still have a problem, perhaps best if you post code for a complete example: * class definition (with just two instance variables) * instance variable accessor methods * instance creation & adding to collection * select statement * updating object cheers -ben On Wed, Jul 27, 2016 at 5:53 AM, Ron Teitelbaum wrote: > Hi Joe, > > If the orderedCollection contains your object DrivingDays then select should give you the object and not a copy. > > You don't need to add it back to the collection just update the object. > > Check your code for anything that might be making a copy. > > All the best, > > Ron Teitelbaum > > > -----Original Message----- > From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Joseph Alotta > Sent: Tuesday, July 26, 2016 3:04 PM > To: beginners@lists.squeakfoundation.org > Subject: [Newbies] indexing into a collection > > Greetings, > > I have a OrderedCollection of DrivingDays. > > > an OrderedCollection(2016-01-02| quigley s| nil|18? > 2016-01-03| marianos fresh| nil|5? > 2016-01-04| fresh thyme| nil|5? > 2016-01-05| panda express| nil|3? > 2016-01-06| peets| nil|7? > 2016-01-07| starbucks| nil|3?) > > I want to select aDrivingDay object from the list by date, update it by adding mileage and places visited and put it back into the list. > > If I #select the OrderedCollection, I get a copy of the item, not the same one in the OrderedCollection. > > How do I select an item in the list for update? > > Sincerely, > > Joe. From joseph.alotta at gmail.com Wed Jul 27 00:13:48 2016 From: joseph.alotta at gmail.com (Joseph Alotta) Date: Wed Jul 27 00:57:59 2016 Subject: [Newbies] Re: indexing into a collection In-Reply-To: References: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> Message-ID: <948A6239-24C6-4C50-986C-E082C7220DB7@gmail.com> Ben, Ron, I made a small example, and it works as you said it would: a := #( #(1 2) #(3 4)). b := a asOrderedCollection. b => an OrderedCollection(#(1 2) #(3 4)) c := b select: [ :i | (i first) = 3 ]. c => an OrderedCollection(#(3 4)) d := c first d => #(3 4) d at: 2 put: 5 d => #(3 5) b => an OrderedCollection(#(1 2) #(3 5)) Okay, I will check my other code. Sincerely, Joe. > On Jul 26, 2016, at 6:25 PM, Ben Coman [via Smalltalk] wrote: > > Hi Joe, > > As Ron said, you should not be getting a copy. If you still have a > problem, perhaps best if you post code for a complete example: > * class definition (with just two instance variables) > * instance variable accessor methods > * instance creation & adding to collection > * select statement > * updating object > > cheers -ben > > On Wed, Jul 27, 2016 at 5:53 AM, Ron Teitelbaum <[hidden email]> wrote: > > > Hi Joe, > > > > If the orderedCollection contains your object DrivingDays then select should give you the object and not a copy. > > > > You don't need to add it back to the collection just update the object. > > > > Check your code for anything that might be making a copy. > > > > All the best, > > > > Ron Teitelbaum > > > > > > -----Original Message----- > > From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta > > Sent: Tuesday, July 26, 2016 3:04 PM > > To: [hidden email] > > Subject: [Newbies] indexing into a collection > > > > Greetings, > > > > I have a OrderedCollection of DrivingDays. > > > > > > an OrderedCollection(2016-01-02| quigley s| nil|18? > > 2016-01-03| marianos fresh| nil|5? > > 2016-01-04| fresh thyme| nil|5? > > 2016-01-05| panda express| nil|3? > > 2016-01-06| peets| nil|7? > > 2016-01-07| starbucks| nil|3?) > > > > I want to select aDrivingDay object from the list by date, update it by adding mileage and places visited and put it back into the list. > > > > If I #select the OrderedCollection, I get a copy of the item, not the same one in the OrderedCollection. > > > > How do I select an item in the list for update? > > > > Sincerely, > > > > Joe. > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/indexing-into-a-collection-tp4908090p4908113.html > To start a new topic under Squeak - Beginners, email ml-node+s1294792n107673h12@n4.nabble.com > To unsubscribe from Squeak - Beginners, click here. > NAML -- View this message in context: http://forum.world.st/indexing-into-a-collection-tp4908090p4908114.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160726/fb304d67/attachment.htm From btc at openinworld.com Wed Jul 27 07:51:44 2016 From: btc at openinworld.com (Ben Coman) Date: Wed Jul 27 07:52:07 2016 Subject: [Newbies] Re: indexing into a collection In-Reply-To: <948A6239-24C6-4C50-986C-E082C7220DB7@gmail.com> References: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> <948A6239-24C6-4C50-986C-E082C7220DB7@gmail.com> Message-ID: On Wed, Jul 27, 2016 at 8:13 AM, Joseph Alotta wrote: > Ben, Ron, I made a small example, and it works as you said it would: > > a := #( #(1 2) #(3 4)). > b := a asOrderedCollection. > b => an OrderedCollection(#(1 2) #(3 4)) > c := b select: [ :i | (i first) = 3 ]. Ahh. Code examples help. Maybe what you need is #detect: which returns an element rather than a collection of elements. > c => an OrderedCollection(#(3 4)) > d := c first > d => #(3 4) > d at: 2 put: 5 > d => #(3 5) > b => an OrderedCollection(#(1 2) #(3 5)) > > Okay, I will check my other code. > > Sincerely, > > Joe. Here's a domain specific example... Object subclass: #DrivingDays instanceVariables: 'date store mileage"?" ' ...etc... oc := OrderedCollection new. oc add: (DrivingDays new date: '2016-01-02' ; store: 'quigley' ; mileage: 18). oc add: (DrivingDays new date: '2016-01-03' ; store: 'marianos' ; mileage: 5). oc printString. >> > an OrderedCollection(2016-01-02| quigley | 18, >> > 2016-01-03| marianos | 5) drivingDayToUpdate := oc detect: [ :dd | dd store = 'marianos' ]. drivingDayToUpdate mileage: 7. oc printString. >> > an OrderedCollection(2016-01-02| quigley | 18, >> > 2016-01-03| marianos | 7) (disclaimer, I am not somewhere I can run this. Its just off the top of my head.) cheers -ben > > > > >> On Jul 26, 2016, at 6:25 PM, Ben Coman [via Smalltalk] <[hidden email]> >> wrote: >> >> Hi Joe, >> >> As Ron said, you should not be getting a copy. If you still have a >> problem, perhaps best if you post code for a complete example: >> * class definition (with just two instance variables) >> * instance variable accessor methods >> * instance creation & adding to collection >> * select statement >> * updating object >> >> cheers -ben >> >> On Wed, Jul 27, 2016 at 5:53 AM, Ron Teitelbaum <[hidden email]> wrote: >> >> > Hi Joe, >> > >> > If the orderedCollection contains your object DrivingDays then select >> > should give you the object and not a copy. >> > >> > You don't need to add it back to the collection just update the object. >> > >> > Check your code for anything that might be making a copy. >> > >> > All the best, >> > >> > Ron Teitelbaum >> > >> > >> > -----Original Message----- >> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta >> > Sent: Tuesday, July 26, 2016 3:04 PM >> > To: [hidden email] >> > Subject: [Newbies] indexing into a collection >> > >> > Greetings, >> > >> > I have a OrderedCollection of DrivingDays. >> > >> > >> > an OrderedCollection(2016-01-02| quigley s| nil|18? >> > 2016-01-03| marianos fresh| nil|5? >> > 2016-01-04| fresh thyme| nil|5? >> > 2016-01-05| panda express| nil|3? >> > 2016-01-06| peets| nil|7? >> > 2016-01-07| starbucks| nil|3?) >> > >> > I want to select aDrivingDay object from the list by date, update it by >> > adding mileage and places visited and put it back into the list. >> > >> > If I #select the OrderedCollection, I get a copy of the item, not the >> > same one in the OrderedCollection. >> > >> > How do I select an item in the list for update? >> > >> > Sincerely, >> > >> > Joe. From Lou at Keystone-Software.com Wed Jul 27 12:12:53 2016 From: Lou at Keystone-Software.com (Louis LaBrunda) Date: Wed Jul 27 12:13:04 2016 Subject: [Newbies] indexing into a collection References: <57F856BA-49ED-4478-BE0C-B27224178DF0@gmail.com> <082401d1e788$36a50d10$a3ef2730$@usmedrec.com> <948A6239-24C6-4C50-986C-E082C7220DB7@gmail.com> Message-ID: Hi Joe & Ben, Ben's example is a good one. If there will be only one instance of DrivingDays in the collection for a given date then you should look at Dictionary and LookupTable. You could then add items to the collection with: collection at: aDrivingDays date put: aDrivingDays. and then use: item := collection at: aDate. to fetch the instance you want. Lou On Wed, 27 Jul 2016 15:51:44 +0800, Ben Coman wrote: >On Wed, Jul 27, 2016 at 8:13 AM, Joseph Alotta wrote: >> Ben, Ron, I made a small example, and it works as you said it would: >> >> a := #( #(1 2) #(3 4)). >> b := a asOrderedCollection. >> b => an OrderedCollection(#(1 2) #(3 4)) >> c := b select: [ :i | (i first) = 3 ]. > >Ahh. Code examples help. Maybe what you need is #detect: >which returns an element rather than a collection of elements. > >> c => an OrderedCollection(#(3 4)) >> d := c first >> d => #(3 4) >> d at: 2 put: 5 >> d => #(3 5) >> b => an OrderedCollection(#(1 2) #(3 5)) >> >> Okay, I will check my other code. >> >> Sincerely, >> >> Joe. > >Here's a domain specific example... > >Object subclass: #DrivingDays > instanceVariables: 'date store mileage"?" ' > ...etc... > >oc := OrderedCollection new. >oc add: (DrivingDays new date: '2016-01-02' ; store: 'quigley' ; mileage: 18). >oc add: (DrivingDays new date: '2016-01-03' ; store: 'marianos' ; mileage: 5). > >oc printString. >>> > an OrderedCollection(2016-01-02| quigley | 18, >>> > 2016-01-03| marianos | 5) > >drivingDayToUpdate := oc detect: [ :dd | dd store = 'marianos' ]. >drivingDayToUpdate mileage: 7. > >oc printString. >>> > an OrderedCollection(2016-01-02| quigley | 18, >>> > 2016-01-03| marianos | 7) > >(disclaimer, I am not somewhere I can run this. Its just off the top >of my head.) >cheers -ben > >> >> >> >> >>> On Jul 26, 2016, at 6:25 PM, Ben Coman [via Smalltalk] <[hidden email]> >>> wrote: >>> >>> Hi Joe, >>> >>> As Ron said, you should not be getting a copy. If you still have a >>> problem, perhaps best if you post code for a complete example: >>> * class definition (with just two instance variables) >>> * instance variable accessor methods >>> * instance creation & adding to collection >>> * select statement >>> * updating object >>> >>> cheers -ben >>> >>> On Wed, Jul 27, 2016 at 5:53 AM, Ron Teitelbaum <[hidden email]> wrote: >>> >>> > Hi Joe, >>> > >>> > If the orderedCollection contains your object DrivingDays then select >>> > should give you the object and not a copy. >>> > >>> > You don't need to add it back to the collection just update the object. >>> > >>> > Check your code for anything that might be making a copy. >>> > >>> > All the best, >>> > >>> > Ron Teitelbaum >>> > >>> > >>> > -----Original Message----- >>> > From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta >>> > Sent: Tuesday, July 26, 2016 3:04 PM >>> > To: [hidden email] >>> > Subject: [Newbies] indexing into a collection >>> > >>> > Greetings, >>> > >>> > I have a OrderedCollection of DrivingDays. >>> > >>> > >>> > an OrderedCollection(2016-01-02| quigley s| nil|18? >>> > 2016-01-03| marianos fresh| nil|5? >>> > 2016-01-04| fresh thyme| nil|5? >>> > 2016-01-05| panda express| nil|3? >>> > 2016-01-06| peets| nil|7? >>> > 2016-01-07| starbucks| nil|3?) >>> > >>> > I want to select aDrivingDay object from the list by date, update it by >>> > adding mileage and places visited and put it back into the list. >>> > >>> > If I #select the OrderedCollection, I get a copy of the item, not the >>> > same one in the OrderedCollection. >>> > >>> > How do I select an item in the list for update? >>> > >>> > Sincerely, >>> > >>> > Joe. -- Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon