Recursion and anonymous functions in elixir

前端 未结 4 1939
我寻月下人不归
我寻月下人不归 2021-02-03 19:52

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

4条回答
  •  花落未央
    2021-02-03 20:51

    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
    

提交回复
热议问题