lua-users home
lua-l archive

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

On Sun, Sep 26, 2010 at 9:45 AM, Henning Diedrich <> wrote:
> Find some brilliant, free enlightenment here:
> and here:
   The pattern matching in tamale is closest to the PM in Erlang's
receive or case clauses (like the "In Case ... of" section in the
Erlang example), since tamale doesn't work at the top
function-definition scope* , and Haskell's static typing makes things
a bit different as well.
   It may also help to note that in Erlang syntax, lowercase IDs is
atoms (interned strings / symbols) and uppercase IDs are variables, so
the beach example would look like this:
   local function between(key, x, y)
      return function(cs)
                local v = cs[key]
                return v >= x and v <= y

   local beach = tamale.matcher {
      { {"celsius", V"N"}, when=between(20, 45),
        "favorable" },
      { {"kelvin", V"N"}, when=between(293, 318),
        "scientifically favorable" },
      { {"fahrenheit", V"N"}, when=between(68, 113),
        "favorable in the US" },
      { V"_", "avoid beach" },
(and it looks this caught a bug in recent changes to the way guards
work with indexing, so I'm adding this to the test suite...)

* which is too bad, it's really nice syntax IMHO, but that would
probably require a LOT of syntactic sugar to make it work in Lua.