In LFE one function definition (
defun) only defines one function and each function has a fixed number of arguments. This is the same as for vanilla Erlang. The compiler is doing the "right thing" here in that it seriously checks the
match-lambda definition. The interpreter, however, which is used when you slurp, is lazy and cheats and uses the number of args in the first clause as the number of args for the match-lambda. This is why it works when you call it with one argument but not two. I will fix it so when we slurp we run lint on the code.
If the return value from
make-client is always called with
send then you could do (not tested):
(defun make-client (host port database password)
(let (((tuple 'ok client) (eredis-start host port database password)))
(lambda (command)
(match-lambda
(((list arg))
(do-query client command arg))
(((list arg1 arg2))
(do-query client command arg1 arg2))))))
(defun send (client-maker command arg)
(funcall (get-method client-maker command) (list arg)))
(defun send (client-maker command arg1 arg2)
(funcall (get-method client-maker command) (list arg1 arg2)))
Or if you want to go even further, but still in the same way of list of args:
(defun make-client (host port database password)
(let (((tuple 'ok client) (eredis-start host port database password)))
(lambda (command)
(lambda (args) (do-query client command args)))))
(defun do-query (client command args)
(let (((tuple 'ok response) (eredis-query client (cons command args))))
(format-response response)))
(defun send (client-maker command arg)
(funcall (get-method client-maker command) (list arg)))
(defun send (client-maker command arg1 arg2)
(funcall (get-method client-maker command) (list arg1 arg2)))
Again not tested. This is fun! What does it do?