Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6801977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:10:02+00:00 2026-05-26T19:10:02+00:00

I’m working on a game in Clojure using Swing. I have a KeyListener to

  • 0

I’m working on a game in Clojure using Swing. I have a KeyListener to take care of controls, but it’s not updating a ref.

(def move (ref :drop))

(defn get-move 
  [block state x y moves]
  (do (println @move)
      (if (check-move @move x y block state) @move
        :nothing)))



(defn listener
  [keyevent]
  (let [c (.getKeyChar keyevent)]
   (do (println c)
      (cond (= c "j") (dosync (ref-set move :left))
            (= c "l") (dosync (ref-set move :right))
            (= c "i") (dosync (ref-set move :rotate))
            (= c "k") (dosync (ref-set move :drop))))))



(defn make-keylistener
  []
 (proxy [KeyAdapter] []
  (keyPressed [event]
            (listener event))))

Now, the idea is that the main function that updates the gui calls get-move. It checks if the move ref is valid in the game, and if so returns it. The listener is attached to a JPanel and changes the ref based on a keypress. The listener works fine – whenever a button is pressed, it prints out the key char. I can only assume it’s changing the ref. However, get-move always returns the same value – it never sees @move change. I feel like I’m misunderstanding something fundamental about concurrency and state in Clojure. What am I doing wrong, and is there a more functional way of handling this?

Thanks!

EDIT: Same problem occurs if I use atoms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:10:03+00:00Added an answer on May 26, 2026 at 7:10 pm

    It’s not a concurrency problem. .getKeyChar returns a char, which I was comparing to a string. Rewriting the conditions to (= (str c) “j”) makes it work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.