cannot invoke function inside match ?

1,142 views
Skip to first unread message

Low Kian Seong

unread,
Apr 29, 2014, 4:14:54 AM4/29/14
to elixir-l...@googlegroups.com
Can someone help me with this? I really don't understand what is wrong here:

defmodule Protobuf.Parse do

  defexception ParseError, error: nil do
    def message(ParseError[error: error]) do
      inspect(error)
    end
  end

  def parse(msgs), do: parse(msgs, [])

  def parse(defs, options) when is_list(defs) do
    :gpb_parse.post_process(defs, options)
  end

  def parse(string, options) do
    case :gpb_scan.string('#{string}') do
      {:ok, tokens, _} ->
        case :gpb_parse.parse(tokens ++ [{:'$end', 999}]) do
          {:ok, defs} ->
            parse(defs, options)
          error ->
            error
        end
      error ->
        error
    end
  end

  def parse!(string, options // []) do
    case parse(string, options) do
      {:ok, defs} -> defs
      {:error, error} ->
        raise(ParseError, error: error)
    end
  end
end

it complains :

** (CompileError) lib/protobuf/parse.ex:29: cannot invoke function options/1 inside match
    (stdlib) lists.erl:1352: :lists.mapfoldl/3
    (stdlib) lists.erl:1353: :lists.mapfoldl/3
    (elixir) src/elixir_clauses.erl:26: :elixir_clauses.match/3
    (elixir) src/elixir_clauses.erl:35: :elixir_clauses.clause/7
    (elixir) src/elixir_def.erl:182: :elixir_def.translate_clause/7
    (elixir) src/elixir_def.erl:171: :elixir_def.translate_definition/8
    (elixir) src/elixir_def.erl:89: :elixir_def.store_definition/9

Why does it think that options is a function ? A little pointer here would be superb.

Eric Meadows-Jönsson

unread,
Apr 29, 2014, 4:17:55 AM4/29/14
to elixir-l...@googlegroups.com

The default argument operator was changed from // to \\.



--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson

Low Kian Seong

unread,
Apr 29, 2014, 4:27:03 AM4/29/14
to elixir-l...@googlegroups.com
Does "//" mean something ?

Eric Meadows-Jönsson

unread,
Apr 29, 2014, 4:29:03 AM4/29/14
to elixir-l...@googlegroups.com

// doesn’t mean anything anymore. \\ on the other hand is the default argument operator. It sets a default value for the parameter if the argument is missing when calling the function.

Low Kian Seong

unread,
Apr 29, 2014, 5:56:07 AM4/29/14
to elixir-l...@googlegroups.com
Thanks.
Reply all
Reply to author
Forward
0 new messages