Thanks, Steve. I was too lazy to UTSL last night and, as you mention, this isn't in the docs.
(It turns out I ended up writing a 10-line function that just does what pr would do by itself :-)) I did learn that I could type ^C into the REPL under emacs by quoting ( \ C-Q C-C ) and then the reader digested it fine. Also, the \uDDDD form expects hex digits for its data, e.g. \u0041 => A. -- Tom On Jan 17, 6:26 am, "Stephen C. Gilardi" <squee...@mac.com> wrote: > On Jan 17, 2009, at 2:37 AM, Tom Faulhaber wrote: > > > Question: How do I read non-printing characters in the reader? > > From reading src/jvm/clojure/lang/LispReader.java and experimenting, > I see that there are at least 3 ways to read such an arbitrary > character code with the reader: > > - Octal character codes from 0 to 255 (octal 0 to 377) can be entered > using a literal of the form "\oddd" (that's a lower case oh followed > by up to 3 digits). You can represent the ^C character as \o3 in > Clojure source. > > - Unicode character codes can be entered using a literal of the form > "\uDDDD" (that's a lowercase u followed by exactly 4 digits). You can > represent the ^C character as \u0003 in Clojure source. > > - If you can get the character into the input stream with a leading > backslash, the reader does read it properly. This doesn't work for ^C > (for me, in an emacs *shell* buffer) because it's interpreted as > "quit" before Clojure sees it. (I would imagine it's possible to put > the terminal into some kind of "raw" mode so that doesn't happen.) It > does work for less consequential characters like ^G. > > I don't see these documented on clojure.org/reader which is where I > would expect to find the info. > > It does appear that Clojure can properly read the characters it prints: > > user=> (with-in-str (pr-str \u0003) (read)) > \^C > user=> (int (with-in-str (pr-str \u0003) (read))) > 3 > user=> > > (which I did in emacs, which shows a literal ascii 3 as ^C) > > --Steve > > smime.p7s > 3KViewDownload --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---