真高興啊。。。。實際的為開源事業做了點點貢獻:),很久前指出的一個lua stdlib的bug得到確認

來源:互聯網
上載者:User

呵呵,是關於lua stdlib 庫的set模組的bug,其實作者好像確認很久了。。。。但是我這段時間一直沒有上gmail,所以沒有看到。。。作者說,在新版中已經修改此bug...今天下了最新版,發現真是這樣:)呵呵,真高興啊,吸收了開源社區的那麼多營養。。。總算有點報答了。。。當然,這僅僅是起步:)

實際流程貼一下。。。滿足一下虛榮心。。。其實僅僅是一個很小的很容易發現的bug。。。呵呵,我當時學lua才一兩周。。也不可能發現多麼難的bug....lol

 

原來的lua stdlib set中某段程式如下:

  1. -- @func propersubset: Find whether one set 
    is
     a proper subset of
  2. -- another
  3. --   @param s, t: sets
  4. -- @returns
  5. --   @param r: true 
    if
     s 
    is
     a proper subset of t, false otherwise
  6. function propersubset (s, t)
  7.   
    return
     subset (s, t) 
    and
     
    not
     subset (t, s)
  8. end
  9. -- @func equal: Find whether two sets are equal
  10. --   @param s, t: sets
  11. -- @returns
  12. --   @param r: true 
    if
     sets are equal, false otherwise
  13. function equal (s, t)
  14.   
    return
     subset (s, t) 
    and
     subset (s, t)
  15. end
  16. -- @head Metamethods 
    for
     sets
  17. -- set + table = union
  18. metatable.__add = union
  19. -- set - table = set difference
  20. metatable.__sub = difference
  21. -- set / table = intersection
  22. metatable.__div = intersection
  23. -- set <= table = subset
  24. metatable.__le = subset

 

於是我發郵件給作者

 

hi all,
Thank you very much for your hard working with the LuaForWindows,I enjoy it so mush.
there is a bug to report as my return.
the set.lua file in the lualibs, 117th line.
source as this code:"return subset (s, t) and subset (s, t)"
it obviously should be "return subset (s,t) and subset(t, s)"
which means they are equal when s is the subset t and t is the subset s.
I hope I'm right and didn't disturb you.
BTW,there is a surprising attribute.
In the set's operations,div(/) mean intersection that is different from custom.
In the custom mul(*) denotes it,just like the <<programming in Lua>> writes in the 13th captial named "metatable and meatmethod"
Thank you for reading my poor Chinglish. lol,I'm Chinese.
Best wishes.
                                                                               your honest
                                                                               JTianLing from jtianling{at}gmail.com

 

 

luaforwindows的作者回信

Andrew Wilson to me, rrt, luaforwindows
show details Sep 3 Reply

 


Thanks for the bug report JTianLing, this particular module comes from
the stdlib library , I'll copy your report of this issue to the
administrator of that project http://luaforge.net/projects/stdlib/
.

Your English is great,  you wouldn't want to even hear my Mandarin.
關心
Andrew Wilson

 

 

呵呵,不知道他這裡說關心是什麼意思......,驚奇的是。。。。他竟然還真能打中文字。。。。E文系統應該是沒有中文IME的吧。。。。

 

最後lua stdlib的作者回信:

Reuben Thomas to Andrew, me, luaforwindows
show details Sep 4 Reply

Thanks, this is quite correct. I've made a new release with this fix.

 

I see, I had actually forgotten that * is used in Modula-3 in the same way. I am happy to change this so that * is intersection and / is symmetric difference.

Thanks, I've made another release with these changes, and coincidentally fixed set.difference, which was also broken.

 

 

呵呵,最新版的set如下,可見已經修複,並且連那個我稱為surprising attribute 的“/”符號表示交集也改了:)

 

  1. -- @func intersection: Find the intersection of two sets
  2. --   @param s, t: sets
  3. -- @returns
  4. --   @param r: set intersection of s 
    and
     t
  5. function intersection (s, t)
  6.   local r = new {}
  7.   
    for
     e 
    in
     elements (s) do
  8.     
    if
     member (t, e) then
  9.       insert (r, e)
  10.     end
  11.   end
  12.   
    return
     r
  13. end
  14. -- @func union: Find the union of two sets
  15. --   @param s, t: sets
  16. -- @returns
  17. --   @param r: set union of s 
    and
     t
  18. function union (s, t)
  19.   local r = new {}
  20.   
    for
     e 
    in
     elements (s) do
  21.     insert (r, e)
  22.   end
  23.   
    for
     e 
    in
     elements (t) do
  24.     insert (r, e)
  25.   end
  26.   
    return
     r
  27. end
  28. -- @func subset: Find whether one set 
    is
     a subset of another
  29. --   @param s, t: sets
  30. -- @returns
  31. --   @param r: true 
    if
     s 
    is
     a subset of t, false otherwise
  32. function subset (s, t)
  33.   
    for
     e 
    in
     elements (s) do
  34.     
    if
     
    not
     member (t, e) then
  35.       
    return
     false
  36.     end
  37.   end
  38.   
    return
     true
  39. end
  40. -- @func propersubset: Find whether one set 
    is
     a proper subset of
  41. -- another
  42. --   @param s, t: sets
  43. -- @returns
  44. --   @param r: true 
    if
     s 
    is
     a proper subset of t, false otherwise
  45. function propersubset (s, t)
  46.   
    return
     subset (s, t) 
    and
     
    not
     subset (t, s)
  47. end
  48. -- @func equal: Find whether two sets are equal
  49. --   @param s, t: sets
  50. -- @returns
  51. --   @param r: true 
    if
     sets are equal, false otherwise
  52. function equal (s, t)
  53.   


    return
     subset (s, t) 
    and
     subset (t, s)
  54. end
  55. -- @head Metamethods 
    for
     sets
  56. -- set + table = union
  57. metatable.__add = union
  58. -- set - table = set difference
  59. metatable.__sub = difference
  60. -- set * table = intersection
  61. metatable.__mul = intersection
  62. -- set / table = symmetric difference
  63. metatable.__div = symmetric_difference
  64. -- set <= table = subset
  65. metatable.__le = subset
  66. -- set < table = proper subset
  67. metatable.__lt = propersubset

 

這雖然是一件芝麻一樣的小事,但卻是我個人第一次真正的為開源社區做貢獻。。。。雖然僅僅是以bug report的形式:)立此存照:)

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.