This is my code. Currently, instead of letters, keypresses result in me getting :current-input "function (p1__19530_SHARP_){\r\nreturn [cljs.core.str.cljscoreIFninvokearity1(p1__19530_SHARP_),cljs.core.str.cljscoreIFn_invoke1(input_value)].join('');\r\n}" instead.
Assistant
It is probable that the issue arises due to your ::update-current-input event using a custom str function instead of ClojureScript's native str function for string concatenation.
The ::update-current-input event defines an anonymous function (within update) using the pound % symbol but incorrectly places str inside it:
The % symbol inside #(str % input-value) is meant to represent the current value of :current-input during the update operation, but the surrounding str function is incorrect here. ClojureScript interprets str as an anonymous function argument, which is then trying to be used as a function inside the anonymous function's body, leading to the observed output.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
;; Later this can be substituted with a database call to pull a list of words.
(def word-collection #{"babyproof" "afar" "affray"
"afro" "arbor" "array"
"arroyo" "barb" "barf"
"boar" "boor" "bray"
"farro" "fora" "foray"
"fray" "parry" "poor"
"pray" "proof" "prop"
"pyro" "roar" "roof"
"ropy"})
(defn find-common-letter [word-set]
(reduce
set/intersection
(map set (seq word-set))))
(defn word-validity-case [word letters common-letter]
(cond
(contains? word-collection word) :submit-ok ; first check if the word is in the word-collection
(> 4 (count (seq word))) :too-short ; check length, notify if less than 3 letters
(not (every? letters (set word))) :invalid ; check if every letter in the word is in letters set
(not (contains? (set word) (first common-letter))) :no-common ; if it does not contain the common letter
(contains? (set word) (first common-letter)) :not-in-list ; then check if the word at least contains common letter
:else :other)) ; generic if it somehow manages to not match one of the above
(rf/reg-event-db ::submit-word
(fn [db [_ word]]
(let [letters (:letters db)
common-letter (:common-letter db)
point-val (point-formula word letters)]
(case (word-validity-case word letters common-letter)
:submit-ok (if (contains? (:found-words db) word)
(assoc db :message "You've already found that word!")
(-> db
(update :found-words conj word)
(update :score + point-val)
(assoc :message (str "Great job! You found " word ", worth a score of " point-val "!")))) ; add the valid word to found words
:too-short (assoc db :message "Only words with 4 letters or more count.")
:not-in-list (assoc db :message (str "Sorry, " word " isn't in the word list today."))
:no-common (assoc db :message "Nice try, but the word needs to contain the common letter.")
:invalid (assoc db :message "All letters in the word must be from the given letter set.")
:other (assoc db :message "Try again.")))))
(defn spawn-words-button
"Starts the game with a preset set of words."
[]
(let [game-started (rf/subscribe [::game-started])]
(when-not @game-started
[:button
{:on-click #(rf/dispatch [::set-words-and-letters word-collection])
:style button-style}
"Get Letters!"])))
(defn text-input
"Field for the user to input a word of their choosing."
[]
(let [input-value (rf/subscribe [::current-input])]
[:input {:type "text"
:placeholder "Type here!"
:value @input-value
:on-change #(rf/dispatch [::assoc-current-input (-> % .-target .-value)])
:style input-style}]))
(defn shuffle-order-button
"Shuffles the order of the letters displayed."
[display-letters]
[:button {:on-click #(rf/dispatch [::shuffle-letter-order display-letters])
:style button-style}
"Shuffle letters"])
(defn init []
(install-global-key-listeners) ; listen for keypress events
(rf/dispatch-sync [::initialize-db]) ; get re-frame atom initialized
(stylefy/init {:dom (stylefy-reagent/init)}) ; set up css
(dev-setup)
(mount-root))
Here's what you should do instead: use the anonymous function to properly concatenate the strings without the symbol mix-up:
This update call will correctly concatenate the existing :current-input value with the new input-value.
Make sure that all your other usages of event functions are consistent with this pattern. Also, always try to keep Clojure's core functions (like str) unshadowed by your definitions to avoid such issues.