0

CLOJURE

Hi everyone, I am new to clojure. I would like to update my record with a split string.

(defrecord Learning [Name Age Gender])
(def person [:Name :Age :Gender])

(let person 
(clojure.string/split "John,12,Male" #","))

I am able to split the string but it throws an exception IllegalArgumentException let requires a vector for its binding in ShipDataRecord:1 clojure.core/let (core.clj:3965)

Can Someone kindly explain how should I go about doing it?

1
  • 1
    You are not new but very very new to clojure. Please read clojure documentation and see how to use let Commented Dec 31, 2012 at 8:23

1 Answer 1

3

Looks like you missed a lot.

First, you using def the wrong way. All variables in clojure are immutable. So, after you defined some variable you can't change its value, but you can rebind it with a new value in any local context using let.

Second, your using of let is incorrect. Try to read Clojure Docs:

(let [x 1]
     x)

let creates new context by binding some variables with new values. [x 1] means that you bind value 1 to the variable x. But outside of let x won't change.

What you want to do is:

(defrecord Learning [Name Age Gender])

(def person
  (apply ->Learning
         (clojure.string/split "John,12,Male" #",")))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.