<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 10 mai 2019 à 08:04, Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_7276301462761470353__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)">
                                        
                                        
                                            
                                        
                                        
                                        Hmmm...<div><div><br></div><div>(Set withAll: (1 to: 11)) take: 4 "-> e.g. #(1 2 3 4)"</div><div>(Set withAll: (1 to: 11)) size take: 4 "-> 330"</div></div><div><br></div><div>Well, the difference is that Integer >> #take: considers duplicate elements,too.</div><div><br></div></div></blockquote><div><br>| count |<br>count := 0.<br>(1 to: 11) combinations: 4 atATimeDo:</div><div>    [:p |</div><div>    (p asSet size = p size)</div><div>        ifFalse: [self halt: 'duplicate'].<br>    count := count + 1].<br>^count<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_7276301462761470353__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)"><div></div><div>Anyway, could such false polymorphism be a problem in a way that it would be hard to debug? </div><div><br></div></div></blockquote><div><br></div><div>I don't think so.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-m_7276301462761470353__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0)"><div></div><div>Best,</div><div>Marcel</div><div class="gmail-m_7276301462761470353mb_sig"></div>
                                        
                                        <blockquote class="gmail-m_7276301462761470353history_container" type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 09.05.2019 16:08:47 schrieb Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">
<div dir="ltr"><div dir="ltr"><div>I note false polymorphism with Integer>>take:</div><div>of course both are related, since Integer>>take: (11 take: 4) tells how many different ways you can #take: 4 elements from a Set of size 11...<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 9 mai 2019 à 15:27, <<a href="mailto:commits@source.squeak.org" target="_blank">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px">A new version of Collections was added to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Collections-mt.832.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Collections-mt.832.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Collections-mt.832<br>
Author: mt<br>
Time: 9 May 2019, 3:27:06.069782 pm<br>
UUID: b3c087f4-c2bc-d542-91d7-9c214ae3a97f<br>
Ancestors: Collections-nice.831<br>
<br>
Adds #take: to create a sub-collection from any collection by specifying the number of elements. Works like #first: for sequenceable collections but does not fail if collection is too small.<br>
<br>
=============== Diff against Collections-nice.831 ===============<br>
<br>
Item was added:<br>
+ ----- Method: CharacterSet>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       self shouldNotImplement.!<br></blockquote><div>Why? a simple do: loop seems feasible.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px">
<br>
Item was added:<br>
+ ----- Method: Collection>>take: (in category 'accessing') -----<br>
+ take: n<br>
+       "Enumerate this collection and return the first n elements or less."<br>
+ <br>
+       | index result |<br>
+       index := 1.     <br>
+       result := self species new: (n min: self size).<br>
+       self associationsDo: [:each | <br>
+               result add: each.<br>
+               (index := index + 1) > n ifTrue: [^ result]]. <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px">
+       ^ result!<br></blockquote><div>First reaction: I did not understand associationsDo:... Why not just do:?</div><div>After verification: I see that default Behavior of associationsDo: is to do: and this avoids a redefinition of take: in Dictionary...</div><div>I don't find it unsurprising, but if it works...<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;min-width:500px">
<br>
Item was added:<br>
+ ----- Method: SequenceableCollection>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       ^ self first: (n min: self size)!<br>
<br>
Item was added:<br>
+ ----- Method: Stream>>take: (in category 'accessing') -----<br>
+ take: n<br>
+ <br>
+       ^ self next: n!<br>
<br>
<br>
</blockquote></div></div>
</div></blockquote></div><br>
</blockquote></div></div></div>