programming-beginners

2018-03-05T16:47:14.000837Z

Thank you! 😁

Scot 2018-03-05T16:48:42.000593Z

Hi all!

👋 4
2018-03-05T21:42:51.000509Z

Okay, first question. I wrote the following:

(def names ["Amelia Cook" "Natalie Bell"])
(clojure.string/split names #" ")
But what I get is:
["[\"Amelia" "Cook\"" "\"Natalie" "Bell\"]"]
Checking the answer on the page for this exercise, it should be coming up as:
["Amelia" "Cook" "Natalie" "Bell"]
What have I missed?

2018-03-05T21:43:31.000264Z

Also, why is it that when other people type in code here it comes up in boxes?? [edit: Thank you @manutter51 for answering this!]

2018-03-05T21:44:50.000162Z

The boxes trick is to wrap your code inside 3 backticks

2018-03-05T21:46:52.000134Z

Also, if you click the “+” to the right of the input box, one of the options is “Text Or Code Snipped”, which is what I used to be able to make an example that included the three backticks instead of interpreting them.

2018-03-05T21:47:58.000265Z

Thank you! Testing...

(def names ["Amelia Cook" "Natalie Bell"])
(clojure.string/split names #" ")

2018-03-05T21:48:02.000362Z

Hurray, it worked!

2018-03-05T21:48:18.000189Z

:thumbsup:

2018-03-05T21:48:22.000313Z

Going to go back and edit that then.

2018-03-05T21:51:26.000429Z

So, to figure out why your code didn’t work the way you expected, the first thing I’m going to do is check the docs for clojure.string/split. (by the way, for short inline code, you can just wrap it in a single backtick, and it will stay in-line)

2018-03-05T21:52:10.000236Z

What do you mean 'stay in-line'?

2018-03-05T21:52:14.000604Z

(doc clojure.string/split)
-------------------------
clojure.string/split
([s re] [s re limit])
  Splits string on a regular expression.  Optional argument limit is
  the maximum number of splits. Not lazy. Returns vector of the splits.

2018-03-05T21:53:13.000350Z

So clojure.string/split expects a string and a regular expression. The names value, however, is not a string, it’s a vector that contains a couple strings.

2018-03-05T21:54:45.000481Z

By “stay in line” I mean that clojure.string/split stays on the same line as the rest of the sentence, because it has only a single back tick around the phrase.

2018-03-05T21:55:26.000455Z

If I use three backticks before and after it, I get this:

clojure.string/split
in its own separate block

2018-03-05T21:55:57.000667Z

Oh, I see! Thank you 🙂