~technomancy/fennel#171: 
case and match doesn't use __fennelrest when destructuring patterns

Only the let and fn destructuring uses the __fennelrest metamethod:

-- (fn f [[x & xs]] xs)
local function f(_1_)
  local _arg_2_ = _1_
  local x = _arg_2_[1]
  local xs = (function (t, k, e)
      local mt = getmetatable(t)
      if 'table' == type(mt) and mt.__fennelrest then
        return mt.__fennelrest(t, k)
      elseif e then
        local rest = {}
        for k, v in pairs(t) do
          if not e[k] then
            rest[k] = v
          end
        end
        return rest
      else
        return {(table.unpack or unpack)(t, k)}
      end
  end)(_arg_2_, 2)
  return xs
end
-- (let [[x & xs] (_G.foo)] xs)
do
  local _let_1_ = _G.foo()
  local x = _let_1_[1]
  local xs = (function (t, k, e)
      local mt = getmetatable(t)
      if 'table' == type(mt) and mt.__fennelrest then
        return mt.__fennelrest(t, k)
      elseif e then
        local rest = {}
        for k, v in pairs(t) do
          if not e[k] then
            rest[k] = v
          end
        end
        return rest
      else
        return {(table.unpack or unpack)(t, k)}
      end
  end)(_let_1_, 2)
end
-- (case (_G.foo) [x & xs] xs)
do
  local _2_ = _G.foo()
  if ((_G.type(_2_) == "table") and (nil ~= (_2_)[1])) then
    local x = (_2_)[1]
    local xs = {select(2, (table.unpack or _G.unpack)(_2_))}
  else
  end
end
-- (match (_G.foo) [x & xs] xs)
local _4_ = _G.foo()
if ((_G.type(_4_) == "table") and (nil ~= (_4_)[1])) then
  local x = (_4_)[1]
  local xs = {select(2, (table.unpack or _G.unpack)(_4_))}
  return xs
else
  return nil
end

Not sure if this is a regression or it was never there.

Status
REPORTED
Submitter
~andreyorst
Assigned to
No-one
Submitted
4 months ago
Updated
3 months ago
Labels
No labels applied.

~andreyorst 4 months ago

It also doesn't support kv-table & destructuring, like let:

(let [{: a : b & rest} {:a 1 :b 2 :c 3 :d 4}] rest) ;=> {:c 3 :d 4}

~andreyorst 3 months ago

There's a patch pending to fix this:

https://lists.sr.ht/~technomancy/fennel/patches/41255

Register here or Log in to comment, or comment via email.