从 Elixir 调用 :wxFrame.new 时出现 FunctionClauseError

FunctionClauseError when calling :wxFrame.new from Elixir

我只有两个问题:)

  1. 怎么了?
  2. 如何在不询问 Whosebug 的情况下了解问题所在?

长生不老药代码:

import WxConstants
...
wx = :wx.new
frame = :wxFrame.new(wx, wxID_ANY, "Game of Life", size: {500, 500})

输出:

** (FunctionClauseError) no function clause matching in :wxFrame.new/4
    gen/wxFrame.erl:111: :wxFrame.new({:wx_ref, 0, :wx, []}, -1, "Game of Life", [size: {500, 500}])

WxConstants 模块:https://github.com/ElixirWin/wxElixir

Dogbert 已经回答了第一个问题,我会回答第二个问题。

** (FunctionClauseError) no function clause matching in ...

是 Elixir 以及任何其他支持函数子句模式匹配的语言中最常发生的错误之一。考虑这个人为的例子:

defmodule M do
  def test(param) when is_binary(param), do: "binary"
  def test(param) when is_list(param), do: "list"
end
M.test("Hello, world")
#⇒ "binary"
M.test([1, 2, 3])
#⇒ "list"

当没有函数子句时,可以匹配给定的参数,出现上面的错误:

M.test(42)
#⇒ ** (FunctionClauseError) no function clause matching in M.test/1

就是说,您正在使用的库需要一个或多个参数的其他类型。让我们检查一下::wxFrame.new/4 预计:

Parent = wxWindow:wxWindow()
Id = integer()
Title = unicode:chardata()
Option = {pos, {X::integer(), Y::integer()}} | 
         {size, {W::integer(), H::integer()}} | 
         {style, integer()}

第三个参数应该是 unicode:chardata(),它又是 Erlang charlist,在 Elixir 中用单引号表示。因此 @Dogbert 的评论:在 'Game of Life'.

周围使用单引号