简体   繁体   中英

clojure: how to bind console input to a variable?

I'm trying to learn clojure, but coming from OO background simple things look like mission impossible. For instance, how do I write the function that would accept console input and output it into console as well?

I'm trying something like this, but it doesn't work.

(ns ClojureTest2.core)

,(defn fun [] 
   (let [input (read-line)]) 
   (println input)
 )

(fun [])

PS I work with eclipse - counterclockwise

Try this:

(ns ClojureTest2.core)

(defn fun []
  (let [input (read-line)]
    (println input)))

(fun)

Note how the println is enclosed in the let statement. input will only exist within the let statement. Also, the empty parameter list of fun means you do not need to supply any arguments to call it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM