2016-11-30 45 views
1

我刚才两个问题:)FunctionClauseError打电话时:从wxFrame.new药剂

  1. 有什么不对?
  2. 如何在不询问Stackoverflow的情况下了解问题所在?

药剂代码:

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

+4

尝试围绕'生命游戏'而不是双重单引号。 – Dogbert

+0

哇,没有人认为任何人甚至知道github回购除了我之外。 –

+0

@OnorioCatenacci Google做他的工作;)感谢模块。 – raacer

回答

5

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

**(FunctionClauseError)无功能的语句匹配...

在药剂中最频繁发生的错误之一,以及任何其他语言的支持图案在功能项匹配。考虑这个人为的例子:

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()这又二郎charlist,即在药剂单引号表示。因此,@Dogbert的评论:在'Game of Life''周围使用单引号。

+2

但是'unicode:chardata()'确实允许'binary()',所以它看起来像一个bug在文档中:http://erlang.org/doc/man/unicode.html#type-chard。 – Dogbert

+1

@Dogbert确实;在任何情况下['new/4'都有'is_chardata' guard](https://github.com/erlang/otp/blob/maint/lib/wx/src/gen/wxFrame.erl#L112),并试图明确将列表转换为下面的两行二进制。 – mudasobwa