Arc Forumnew | comments | leaders | submitlogin
Bug in codelines function in code.arc
12 points by kostas 6144 days ago | 4 comments
While looking at various examples of the use of w/infile, I noticed there is a bug in the codelines function in the file code.arc. The function is defined as:

  (def codelines (file)
    (w/infile in file
      (summing test
        (whilet line (readline in)
          (test (aand (pos nonwhite line) (isnt it #\;)))))))
The problem is that the captured variable "it" in aand has the position of the first nonwhite character, which is compared to #\;. What should actually be compared to #\; is the first nonwhite character (rather than its position). This bug causes the function to erroneously count commented out lines. Changing "it" to "line.it" corrects the bug.

  (def codelines (file)
    (w/infile in file
      (summing test
        (whilet line (readline in)
          (test (aand (pos nonwhite line) (isnt line.it #\;)))))))


5 points by nex3 6143 days ago | link

Interestingly, this shows that News.YC is actually only 1275 lines.

-----

3 points by pg 6140 days ago | link

Holy cow. Thanks for finding that. Originally that pos was a find. I think it got changed in a global replace, and since I normally used codetree I never noticed that the return values suddenly leaped.

-----

4 points by wfarr 6144 days ago | link

Your patch is now added to Anarki (http://git.nex-3.com/arc-wiki.git) as of now. =)

-----

1 point by kostas 6143 days ago | link

Thanks. Learning to use git is next on the priority list.

-----