<div dir="ltr"><div>I think that renaming it to #findPositiveInteger is a good idea. Let's go that way.</div><div><br></div><div>Cheers!</div><div>Hernan.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 6, 2021 at 10:27 AM Juan Vuletich <<a href="mailto:juan@jvuletich.org">juan@jvuletich.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
    
    
  
  <div bgcolor="#ffffff">
    On 1/6/2021 9:44 AM, Hernan Wilkinson via Cuis-dev wrote:
    <blockquote type="cite">
      <div dir="ltr">
        <div>Definitely a bug.</div>
      </div>
    </blockquote>
    <br>
    I think whoever wrote that method was thinking #asPositiveInteger,
    which might have been a better name. Besides, I think that something
    like #findPositiveInteger would have been much better.<br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div>Attached is a change set that fixes it with tests to verify
          the behavior of String>>asInteger</div>
        <div>I think we should think the behavior a little bit
          through... for example '---1' signals an error but '+++1' does
          not, or '.1' returns 1 but '0.1' returns 0...</div>
        <div> I thinks this are rare cases and the solution is not what
          we would expect.</div>
        <div><br>
        </div>
        <div>Cheers!</div>
        <div>Hernan.<br>
        </div>
      </div>
    </blockquote>
    <br>
    What about the below? It gives what I think are the correct answers
    for '--1', '- 1', '---1' and '-+1'. To me, the correct answer is
    "seach for the first well formed integer number, ignoring all the
    rest'. It breaks your test, though.<br>
    <br>
    Anyway, looking at what the comment says, I'm more convinced that
    we'd leave as it was, but rename it as #findPositiveInteger.<br>
    <br>
    asInteger <br>
        "Answer the Integer created by interpreting the receiver as the
    string representation of an integer.  Answer nil if no digits, else
    find the first digit and then all consecutive digits after that"<br>
    <br>
        | startPosition tail endPosition answer |<br>
        startPosition _ self findFirst: [:ch | ch isDigit].<br>
        startPosition = 0 ifTrue: [^ nil].<br>
        tail _ self copyFrom: startPosition to: self size.<br>
        endPosition _ tail findFirst: [:ch | ch isDigit not].<br>
        endPosition _ endPosition = 0<br>
            ifFalse: [endPosition-1]<br>
            ifTrue: [tail size].<br>
        answer _ Number readFrom: (tail copyFrom: 1 to: endPosition)
    readStream.<br>
        (startPosition > 1 and: [ (self at: startPosition-1) = $- ])<br>
            ifTrue: [ answer _ answer negated].<br>
        ^answer<br>
    <br>
    "<br>
    '1796exportFixes-tkMX' asInteger<br>
    '1848recentLogFile-sw'  asInteger<br>
    'donald' asInteger<br>
    'abc234def567' asInteger<br>
    '-1' asInteger<br>
    '--1' asInteger<br>
    '---1' asInteger<br>
    "<br>
    <br>
    <br>
    <blockquote type="cite">
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Wed, Jan 6, 2021 at 6:27 AM
          Philip Bernhart via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st" target="_blank">cuis-dev@lists.cuis.st</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
          <br>
          I just noticed that #asInteger has an unexpected behaviour.<br>
          That I thought is worth pointing out. Depending on what<br>
          someone could interpret as an integer (all unsigned numbers or<br>
          including negative numbers).<br>
          <br>
          I found out while looking at some Pharo code that:<br>
          <br>
          '-1' asInteger => -1 (in Pharo)<br>
          '-1' asInteger => 1 (in Cuis)<br>
          <br>
          'Mötör-45heäd' asInteger => -45 (in Pharo)<br>
          'Mötör-45heäd' asInteger => 45 (in Cuis)<br>
          <br>
          So the sign is lost.<br>
          <br>
          Was this intentional? Bug or feature?<br>
          <br>
          <br>
          Thanks,<br>
          Philip<br>
          -- <br>
          -- <br>
          Cuis-dev mailing list<br>
          <a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
          <a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
        </blockquote>
      </div>
      <br clear="all">
      <br>
      -- <br>
      <div dir="ltr">
        <div dir="ltr">
          <div>
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div dir="ltr">
                          <div dir="ltr">
                            <div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal"><span style="font-weight:bold">Hernán
                                              Wilkinson</span><br>
                                            Agile Software Development,
                                            Teaching & Coaching</span></font></span></span></span></strong></span></div>
                            <div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">Phone:
                                            +54-011</span></font></span></span></span></strong></span><font size="2" face="tahoma, sans-serif">-4893-2057</font></div>
                            <div><strong style="font-family:tahoma,sans-serif;font-size:xx-small"><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Twitter:
                                        @HernanWilkinson</span></font></span></span></strong></div>
                            <div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">site: <a href="http://www.10pines.com/" style="color:rgb(17,65,112)" target="_blank">http://www.10Pines.com</a></span></font></span></span></span></strong></span></div>
                            <div><font face="tahoma, sans-serif"><span style="border-collapse:collapse">Address:
                                  Alem 896</span></font>, Floor 6,
                              Buenos Aires, Argentina</div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Thanks,<br>
    <pre cols="72">-- 
Juan Vuletich
<a href="http://www.cuis-smalltalk.org" target="_blank">www.cuis-smalltalk.org</a>
<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a href="https://github.com/jvuletich" target="_blank">https://github.com/jvuletich</a>
<a href="https://www.linkedin.com/in/juan-vuletich-75611b3" target="_blank">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
  </div>

</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal"><span style="font-weight:bold">Hernán Wilkinson</span><br>Agile Software Development, Teaching & Coaching</span></font></span></span></span></strong></span></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">Phone: +54-011</span></font></span></span></span></strong></span><font size="2" face="tahoma, sans-serif">-4893-2057</font></div><div><strong style="font-family:tahoma,sans-serif;font-size:xx-small"><span style="font-size:8pt"><span style="font-size:small"><font size="2"><span style="font-weight:normal">Twitter: @HernanWilkinson</span></font></span></span></strong></div><div><span style="font-family:tahoma,sans-serif;font-size:xx-small;border-collapse:collapse"><strong><span style="font-size:8pt"><span><span style="font-size:small"><font size="2"><span style="font-weight:normal">site: <a href="http://www.10pines.com/" style="color:rgb(17,65,112)" target="_blank">http://www.10Pines.com</a></span></font></span></span></span></strong></span></div><div><font face="tahoma, sans-serif"><span style="border-collapse:collapse">Address: Alem 896</span></font>, Floor 6, Buenos Aires, Argentina</div></div></div></div></div></div></div></div></div></div></div></div>