争论的次数不对



我正在构建一个程序,该程序旨在允许用户计算字符串中的字母数或单词数,但当通过cmd运行该程序时,我会收到一个clojure.lang.ArityException,错误的args数(1)传递给:core/-main/counter-5333

我的代码是

;;Create a GUI which allows user to input a string and to select "word count" or "letter count". When "Start" is clicked pass both the string and either (wordCount [string x]) or (letterCount [string x]) to 
;;declare functions as variables
;;show function that takes functions as parameters
;;show function that returns another function
(ns firstclass.core
  (:gen-class)
  (:use seesaw.core))
(defn -main
  [& args]
(def strInput (input "Please enter a string to be evaluated"))
(def groups (button-group))
(def s (selection groups))
(def letterRadio (radio :text "Letter" :group groups))
(def wordRadio (radio :text "Word" :group groups))
(defn letterCount
  [string]
  (loop [characters string
         a-count 0]
    (if (= (first characters) a)
      (recur (rest characters) (inc a-count))
      a-count)))
(defn wordCount
  [string]
  (loop [characters string
         a-count 0]
    (if (= (first characters) a)
      (recur (rest characters) (inc a-count))
      a-count)))
(def counter (fn [fn x, string strInput] (x [strInput])))
(defn handler [event]
    (if-let [s letterRadio]
        (counter [letterCount, strInput]))
    (if-let [s wordRadio]
        (counter [wordCount, strInput])))
(def start (button :text "Start Count" :listen [:action handler] ))
(def panel
  (flow-panel :items [strInput, letterRadio, wordRadio, start]))
(invoke-later
  (-> (frame :content panel :on-close :dispose) 
      pack! show!)))

用于counter 的定义

(def counter (fn [fn x, string strInput] (x [strInput])))

你有一个四个参数的函数

handler函数中,您用一个参数调用它:

(counter [letterCount strInput])

根据上下文,我假设您打算将counter定义为有两个参数,并且您打算在两个参数上调用它,而不是两个项的单个向量。

(def counter (fn [x strInput] (x strInput)))
...
(counter letterCount strInput)

此外,最好使用defn来定义函数,而不是分别使用deffn来定义

(defn counter [x strInput] (x strInput))

相关内容

  • 没有找到相关文章

最新更新