rvirding/lfe — Issue #7: pattern matching in function head doesn't work for lambdas
Author: KlausTrainer
Created: 2011-10-19 20:27:35+00:00
State: open

Pattern matching in the head of a named function works fine both in compiled and interpreted mode. However, it doesn't work for lambdas (compiled and interpreted).

This one works fine:

```lisp
(defmodule foo (export (a_and_c 1)))
(defun a_and_c ([(tuple a b c)] (tuple a c)))
```

```lisp
(a_and_c (tuple 'a 'b 'c)) ; returns #(a c)
```

But that one does not work at all:

```lisp
(defmodule bar (export (a_and_b 1)))
(defun a_and_b (t)
(let ((issue_7 (lambda ([(tuple a b c)] (tuple a b)))))
(funcall issue_7 t)))
```

When slurping the function, everything looks alright, but when it is invoked, a badarity error occurs:

```lisp
(a_and_b (tuple 'a 'b 'c)) ; should return `#(a b)`, but does not
```

```
exception error: #(badarity #(#Fun (#(a b c))))
```

Instead of the correct arity of one (like it applies to the named function), the lambda function has an incorrect arity of 2:

```lisp
(: lists keyfind 'arity 1 (: erlang fun_info (fun a_and_b 1))))) ; returns #(arity 2)
```

Compiling it does not work, too:

```lisp
(: lfe_comp file '"/tmp/bar.lfe")
```

```
/tmp/bar.lfe:2: bad form: lambda
error
```