呵呵,是關於lua stdlib 庫的set模組的bug,其實作者好像確認很久了。。。。但是我這段時間一直沒有上gmail,所以沒有看到。。。作者說,在新版中已經修改此bug...今天下了最新版,發現真是這樣:)呵呵,真高興啊,吸收了開源社區的那麼多營養。。。總算有點報答了。。。當然,這僅僅是起步:)
實際流程貼一下。。。滿足一下虛榮心。。。其實僅僅是一個很小的很容易發現的bug。。。呵呵,我當時學lua才一兩周。。也不可能發現多麼難的bug....lol
原來的lua stdlib set中某段程式如下:
- -- @func propersubset: Find whether one set
is
a proper subset of
- -- another
- -- @param s, t: sets
- -- @returns
- -- @param r: true
if
s
is
a proper subset of t, false otherwise
- function propersubset (s, t)
-
return
subset (s, t)
and
not
subset (t, s)
- end
- -- @func equal: Find whether two sets are equal
- -- @param s, t: sets
- -- @returns
- -- @param r: true
if
sets are equal, false otherwise
- function equal (s, t)
-
return
subset (s, t)
and
subset (s, t)
- end
- -- @head Metamethods
for
sets
- -- set + table = union
- metatable.__add = union
- -- set - table = set difference
- metatable.__sub = difference
- -- set / table = intersection
- metatable.__div = intersection
- -- set <= table = subset
- 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 的“/”符號表示交集也改了:)
- -- @func intersection: Find the intersection of two sets
- -- @param s, t: sets
- -- @returns
- -- @param r: set intersection of s
and
t
- function intersection (s, t)
- local r = new {}
-
for
e
in
elements (s) do
-
if
member (t, e) then
- insert (r, e)
- end
- end
-
return
r
- end
- -- @func union: Find the union of two sets
- -- @param s, t: sets
- -- @returns
- -- @param r: set union of s
and
t
- function union (s, t)
- local r = new {}
-
for
e
in
elements (s) do
- insert (r, e)
- end
-
for
e
in
elements (t) do
- insert (r, e)
- end
-
return
r
- end
- -- @func subset: Find whether one set
is
a subset of another
- -- @param s, t: sets
- -- @returns
- -- @param r: true
if
s
is
a subset of t, false otherwise
- function subset (s, t)
-
for
e
in
elements (s) do
-
if
not
member (t, e) then
-
return
false
- end
- end
-
return
true
- end
- -- @func propersubset: Find whether one set
is
a proper subset of
- -- another
- -- @param s, t: sets
- -- @returns
- -- @param r: true
if
s
is
a proper subset of t, false otherwise
- function propersubset (s, t)
-
return
subset (s, t)
and
not
subset (t, s)
- end
- -- @func equal: Find whether two sets are equal
- -- @param s, t: sets
- -- @returns
- -- @param r: true
if
sets are equal, false otherwise
- function equal (s, t)
-
return
subset (s, t)
and
subset (t, s)
- end
- -- @head Metamethods
for
sets
- -- set + table = union
- metatable.__add = union
- -- set - table = set difference
- metatable.__sub = difference
- -- set * table = intersection
- metatable.__mul = intersection
- -- set / table = symmetric difference
- metatable.__div = symmetric_difference
- -- set <= table = subset
- metatable.__le = subset
- -- set < table = proper subset
- metatable.__lt = propersubset
這雖然是一件芝麻一樣的小事,但卻是我個人第一次真正的為開源社區做貢獻。。。。雖然僅僅是以bug report的形式:)立此存照:)