我正在构建一个程序,该程序旨在允许用户计算字符串中的字母数或单词数,但是当通过 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!)))