Recursion and anonymous functions in elixir

anonymous-function, elixir, recursion

Solution

It is not possible to recur on anonymous functions in Elixir.

Erlang 17 (currently a release candidate) adds this possibility to Erlang and we plan to leverage it soon. Right now, the best approach is to define a module function and pass it around:

def neural_bias([i|input],[w|weights], acc) do
  neural(input,weights,i*w+acc)
end

def neural_bias([], [bias], acc) do
  acc + bias
end

And then:

&neural_bias/3

Problem

I'm trying to define an anonymous function to do a dot product, I can code this as a private function without any problem but I am struggling with the anonymous function syntax. I know I could implement this differently but I am trying to understand how to define anonymous functions with pattern matching and recursion. This is my current implementation ``` dot = fn [i|input],[w|weights], acc -> dot.(input,weights,i*w+acc) [],[bias],acc -> acc + bias end ``` And I get this error on compile: ``` function dot/0 undefined ``` Any hints? Is this just not possible?

Original source