On Fri, Apr 8, 2011 at 2:52 AM, Gregg Williams <greg...@innerpaths.net> wrote: > Having worked with Clojure for over a year, I can sympathize with > Clojure beginners (like myself) who find it extremely difficult to do > simple things with Clojure. (It took me weeks to get Clojure working > with Emacs, Swank, and the Clojure Debugging Toolkit, but I'm > persistent.) > > Now this. I'm learning Spanish, and I wanted to whip up a simple > Clojure program to spit out randomly-generated vocabulary phrases, > then give me the answer when I hit ENTER from the keyboard. Simple ... > keyboard ... input. Simple, right? > > After considerable research, reading all sorts of different solutions > (some of which dropped into Java) for this seemingly trivial task, I > wrote an earlier version of this (now cleaned-up) code:
... > I just want to practice Spanish! (Actually, I'd rather program > Clojure, but I don't like wasting my time trying to do elementary > things that SHOULD ... JUST ... WORK.) Can anybody suggest anything > that will enable me to write this simple program that any middle- > school student would find, well, basic if written in BASIC? Thanks. The whole JVM ecosystem seems built around client-server communications, noninteractive jobs, and client-side GUI; not client-side console interaction. It's easier to do something like this using a Swing GUI with a read-only JTextArea holding the interaction history above a one-line JTextField used to submit new input; stick an ActionListener on the JTextField and it will get called when enter is pressed in the field. Or you can use something like this to sugar it up: (defmacro text-line [input-var & body] `(let [f# (javax.swing.JTextField.)] (doto f (setEditable true) (setColumns 60) (.addActionListener (proxy [ActionListener] [] (actionPerformed [_] (let ~(conj input-var `(.getText f#)) (.setText f# "") ~@body))))))) Sample usage: (let [field (text-line [line] (println line))] ... (.add some-panel field java.awt.layout.BorderLayout/SOUTH)) Untested. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en