2

I need to loop over the characters in a given string--in Ruby, I'd do something like this:

string = "blah"

string.each_char do |c| 

   puts c

end

How do I do this in newLisp?

Alexej Magura
  • 4,833
  • 3
  • 26
  • 40

2 Answers2

2

Note that dostring supplies integers:

(let (str "")
(dostring (c str)
  (println (format "%x" c))))

1f604
1f603
1f600
1f60a

whereas explode supplies the characters:

(let (str "")
(dolist (c (explode str))
  (println c)))





cormullion
  • 1,672
  • 1
  • 10
  • 24
  • that's why I use `(char)` to cast those integers back into characters, silly. :P (It converts them into `ASCII/UTF-8` codes). Didn't know about `(explode)`, though. – Alexej Magura Jul 30 '13 at 18:30
1

I figured it out:

(let (str "blah")  

   (dostring (c str)

      (println (char c) )))
Alexej Magura
  • 4,833
  • 3
  • 26
  • 40