Arc Forumnew | comments | leaders | submitlogin
1 point by fallintothis 5236 days ago | link | parent

When you map across a string, it coerces the whole result into a new string character-by-character. It's like if you (hypothetically) weren't allowed to have nested lists but tried to do

  (map [list 1 2 3 _] '(8 6 7 5 3 0 9))
Each string element is a character, not a whole string. Thus

  arc> (= s (newstring 3))
  "\u0000\u0000\u0000" ; these are null characters, by the way
  arc> (= (s 0) #\a)
  #\a
  arc> s
  "a\u0000\u0000"
  arc> (= (s 1) #\b)
  #\b
  arc> s
  "ab\u0000"
  arc> (= (s 2) "foo")
  Error: "string-set!: expects type <character> as 3rd argument, given: \"foo\"; other arguments were: \"ab\\u0000\" 2"
But you can use map on a string for things like

  arc> (inc #\a)
  #\b
  arc> (inc #\b)
  #\c
  arc> (inc #\c)
  #\d
  arc> (map inc "abc")
  "bcd"