lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm not sure Steve Donovan and Gavin Wraith understood the idea of my
post.  I appreciate that the beauty of Lua is how much expressive
power it achieves from such simple syntax and semantics.  As far as I
can tell, my suggestion requires no change to the Lua language at all.
The use of efficient bit ops to perform high-level operations on bool
arrays would happen behind the scenes, invisible to the user.  And the
library functions to operate on these arrays would be more general
than those of bit32, not restricted to 32 bits, and in my opinion less
"kludgy".

The problem with my idea is not that it clutters up the language, but
that it requires another internal representation of a certain kind of
array, and it may simply not be worth the effort to write the code to
deal with this representation.


On Thu, 30 Dec 2010 17:33:02 +0200 steve donovan <steve.j.donovan@gmail.com> wrote:

> On Thu, Dec 30, 2010 at 5:14 PM, David J. Slate <dslate@speakeasy.net> wrote:
> > Any thoughts on the desirability or feasibility of this idea?
> 
> It's a cool thing to have around, but much better to make it a C
> extension.  Otherwise Lua ends up supporting everything like PL/1, the
> classic big-committee language.
> 
> steve d.


On Thu, 30 Dec 2010 16:25:16 GMT Gavin Wraith <gavin@wra1th.plus.com> wrote:

> In message <AANLkTinTu7P0jKdsYA4j36tbvGk555DHU4yWYMXmBX0o@mail.gmail.com> you wrote:
> 
> > On Thu, Dec 30, 2010 at 5:14 PM, David J. Slate <dslate@speakeasy.net> wrote:
> > > Any thoughts on the desirability or feasibility of this idea?
> 
> Is this the sort of thing envisaged? OK it is RiscLua, not pure Lua, but
> I guess the syntactic differences are not hard to swallow.
> 
> #! lua
> -- library for tables with value true
> do
> local metabool
> bool = \(t) => setmetatable(t,metabool) end
> local paren = "(%s)"
> local boolmeths = {
> tostring = \(self)
>         local o = {}
>         for a,v in pairs(self) do
>           if v then o[1+#o] = tostring(a) end -- if
>          end -- for
>          local s = table.concat(o,",")
>          => paren:format(s)
>          end;
> }
> metabool = {
> __bit_and = \(x,y)
>      local o = bool {}
>        for a,v in pairs(x) do
>          if v and y[a] then o[a] = true end -- if
>        end -- for
>        => o
>      end;
> __bit_or = \(x,y)
>      local o = bool {}
>      for a,v in pairs(x) do
>        if v then o[a] = true end -- if
>      end -- for
>      for a,v in pairs(y) do
>        if v then o[a] = true end -- if
>      end -- for
>      => o
>     end;
> __bit_xor = \(x,y)
>       local o = bool {}
>       for a,v in pairs(x) do
>         if v and not y[a] then o[a] = true end -- if
>       end -- for
>       for a,v in pairs(y) do
>         if v and not x[a] then o[a] = true end -- if
>       end -- for
>       => o
>     end;
> __index = boolmeths;
> }
> 
> end
> 
> x = bool { a = true, b = true, c = true }
> y = bool { b = true, c = true, d = true }
> 
> print((x&y):tostring())   --> (c,b)
> print((x|y):tostring())   --> (a,d,c,b)
> print((x^^y):tostring())  --> (a,d)
> 
> -- 
> Gavin Wraith (gavin@wra1th.plus.com)
> Home page: http://www.wra1th.plus.com/