Reputation: 23
I'm building a program that's meant to allow users count either the number of letters or number of words in a string, however when running the program through the cmd, I'm getting a clojure.lang.ArityException, wrong number of args (1) passed to : core/-main/counter--5333
My code is
;;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!)))
Upvotes: 1
Views: 269
Reputation: 20194
for your definition of counter
(def counter (fn [fn x, string strInput] (x [strInput])))
you have a function of four arguments
in the handler
function, you call it with one argument:
(counter [letterCount strInput])
from context I assume that you meant to define counter as having two arguments, and you meant to call it on two arguments, rather than a single vector of two items.
(def counter (fn [x strInput] (x strInput)))
...
(counter letterCount strInput)
Also, it's better to use defn
to define functions, rather than def
and fn
separately
(defn counter [x strInput] (x strInput))
Upvotes: 2