# 真高兴啊。。。。实际的为开源事业做了点点贡献：），很久前指出的一个lua stdlib的bug得到确认

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
for
sets
17. -- set + table = 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.
JTianLing from jtianling{at}gmail.com

luaforwindows的作者回信

Andrew Wilson to me, rrt, luaforwindows

Thanks for the bug report JTianLing, this particular module comes from
the stdlib library , I'll copy your report of this issue to the
.

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

Andrew Wilson

Reuben Thomas to Andrew, me, luaforwindows

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.

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
for
sets
56. -- set + table = 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

Posted By 九天雁翎 at 九天雁翎的博客 on 2008年10月27日