@scot-brown has joined the channel
set the channel description: Questions about general programming fundamentals in the context of Clojure
@bronsa has joined the channel
@honeyhastings has joined the channel
@amelia has joined the channel
@val_waeselynck has joined the channel
@sundarj has joined the channel
Thank you! 😁
@joelsanchez has joined the channel
Hi all!
@otfrom has joined the channel
@madstap has joined the channel
@manutter51 has joined the channel
@anantpaatra has joined the channel
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?Also, why is it that when other people type in code here it comes up in boxes?? [edit: Thank you @manutter51 for answering this!]
The boxes trick is to wrap your code inside 3 backticks
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.
Thank you! Testing...
(def names ["Amelia Cook" "Natalie Bell"])
(clojure.string/split names #" ")
Hurray, it worked!
👍
Going to go back and edit that then.
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)
What do you mean 'stay in-line'?
(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.
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.
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.
If I use three backticks before and after it, I get this:
clojure.string/split in its own separate blockOh, I see! Thank you 🙂