Am I the only one who ever gets frustrated when working with Common Lisp's strings and characters, particularly when you have to stuff them into binary streams? I was trying to do some simple stuff tonight and just about pulled my hair out bumping into what I think is silly behavior. Let me count the annoyances:
Maybe I've been playing around too much with Perl and Ruby lately and I'm used to all the fast-and-loose type coercion that goes on there. I sure reduces the typing, though.
- You can't call READ-BYTE on a text stream. This means that you can't easily use WITH-INPUT-FROM-STRING to create a stream that will be read using READ-BYTE. Can anybody think of a reason that READ-BYTE wouldn't return (CHAR-CODE (READ-BYTE stream)), if stream was a text stream?
- You can't include any binary data in a string. The reader doesn't interpret things like \n or \0 as C would. I suppose this is a symptom of trying to be compatible with early Lisps that came before C was invented, but this behavior is standard in just about every programming language out there today.
- Because of the previous limitation, you need to use something like CONCATENATE to put some binary data in the middle of a string. Unfortunately, something like (CONCATENATE 'STRING "Foo" #\newline) doesn't work because #\newline isn't a sequence. So you have to use something like (CONCATENATE 'STRING "Foo" (LIST #\newline)) to create this. It would seem that CONCATENATE could just treat any ATOM as a list of length 1 and be done with it.
- Then, you're constantly using CODE-CHAR and CHAR-CODE to convert back and forth between character objects and integers.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/