2016-11-30 20 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