8

**つまり、私は以前に Erlang を使用したことがあり、かなり快適に使用できます。私はちょうどエリクサーを学ぼうとしています。

私は最近、「怠惰な仕出し屋」の例をエリクサーに翻訳しようとしていましたが、なぜそれがコンパイルされないのか、または警告付きでコンパイルされて機能しないのかについて困惑しています。ここで何が欠けていますか。何か案は?Erlang コードと「実行」は次のとおりです:**

jps@GRASSKEET ~/dev/erlang
$ cat cater.erl

    -module(cater).
    -export([cater/1]).
    cater(0) -> 1;
    cater(N) when N>0 -> N + cater(N-1).

jps@GRASSKEET ~/dev/erlang
$ erl
Eshell V6.3  (abort with ^G)
1> c("cater.erl").
{ok,cater}
2> cater:cater(10).
56
3>*

Cater.ex をそのように書くと、意味をなさないエラーが発生します。

jps@GRASSKEET ~/dev/elix
$ cat Cater.ex

    defmodule Cater do
      def cut(0), do: 1
      def cut(N) when N>0, do: N + cut(N-1)
    end

jps@GRASSKEET ~/dev/elix
$ iex
Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c("Cater.ex")
Cater.ex:1: warning: redefining module Cater
Cater.ex:3: warning: this expression will fail with ArithmeticError
[Cater]
iex(2)> Cater.cut(10)
** (FunctionClauseError) no function clause matching in Cater.cut/1
    Cater.ex:2: Cater.cut(10)
iex(2)>
4

1 に答える 1