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:

----------------------------------------
(defn -main []
  (println "1. generated test question goes here") ;randomized drill
item printed
  (let [feedback (read-line)]
    (print "2. input from keyboard is: '" feedback "'\n")
    ;; continues if user hits ENTER; to exit, type something
    (if-let [result (not (= feedback ""))]
      (print "3a. input was '" feedback "'--my signal to EXIT PROGRAM
\n")
      (do
        (println "3b. question answer goes here\n\n") ;answer, if given,
printed here
        (recur)))))
----------------------------------------

*Couldn't* get it to work from the REPL within Emacs. More research.
Oh, Phil Hagelberg says that (read-line) is "simply not supported in
swank-clojure" (http://groups.google.com/group/clojure/browse_thread/
thread/bc49afd3986a41e3). Okay, I tried it with `lein run`. I got
something similar to its behavior within Emacs:

----------------------------------------
macscooter:drill gw$ lein run
1. generated test question goes here
2. input from keyboard is: ' nil '
3a. input was ' nil '--my signal to EXIT PROGRAM
macscooter:drill gw$
----------------------------------------

(The above output occurs without *any* keyboard input.)

Finally, I try a leiningen REPL, and I get the desired/expected
behavior:

----------------------------------------
drill.core=> (-main)
1. generated test question goes here
                    <--- keyboard input was ENTER key --GW
2. input from keyboard is: '  '
3b. question answer goes here


1. generated test question goes here
I give up          <--- this is keyboard input --GW
2. input from keyboard is: ' I give up '
3a. input was ' I give up '--my signal to EXIT PROGRAM
nil
drill.core=>
----------------------------------------

I tried clojure-cake (briefly) but got some kind of error and haven't
pursued it just yet. I assume that running clojure completely manually
from the CLI will work, but honestly, I'd like to have some support
for interactivity and/or debugging this program, which could grow over
time.

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.

-- 
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

Reply via email to