Arc Forumnew | comments | leaders | submitlogin
5 points by fallintothis 5207 days ago | link | parent

  arc> (coerce "abc" 'cons)
  (#\a #\b #\c)
  arc> (car (coerce "abc" 'cons))
  #\a
  arc> (cdr (coerce "abc" 'cons))
  (#\b #\c)
coerce works on a wide variety of types. E.g., you can also do

  arc> (coerce (list #\a #\b #\c) 'string)
  "abc"
Keep in mind that certain Arc builtins like map and each will work on strings to begin with.

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

  arc> (each character "abc" (prn character "!"))
  a!
  b!
  c!
  nil


1 point by dpkendal 5204 days ago | link

Thanks. Didn't know coerce could be used like that.

-----