> Well, under the covers the str function applies the java "toString" > method to any passed in object and hence the result could for some > reason be different to the original String object passed in. I think > this could occur if the object subclasses String, but has a different > representation (i.e a different toString method). > > Are you able to post what s contains when this happens? > You could try printing s in your calling function and then also in the > defmethod, e.g; > > (defmethod t-str String [s] (prn "cls:" (class s) "s:" s "chars:" (vec s)))) > > Maybe that'll shed some light?
I thought I sent this to the list, but I think I just sent it to a single person, so I'm trying again... Ok, here's a stripped down set of code that has the problem. It does require that erlang be installed with java support. I couldn't figure out a way to duplicate the problem without it, unfortunately. To test this out, first start erlang like this: erl -setcookie cookie -sname e...@localhost Then, run the attached demo.clj. Once that's started (it won't print anything, so just give it a sec to get running), run the following from the erlang REPL: { echo, e...@localhost } ! { self(), "hi there" }. and then, after the demo.clj has exited, (fun() -> receive X -> X after 0 -> nil end end)(). As the code is submitted, you will get a reply that looks like <<172,237,0,5,117,114,0,2,91,66,172,243,23,248,6,8,84,224, 2,0,0,120,112,0,0,0,8,104,105,...>> If you replace the (let [ inside s ...]) with (let [ inside (str s) ...]) and rerun the test, you will get the string "hi there", as a binary. On the clojure side, the following is printed with [ inside s ]: I was given a class java.lang.String Chars are [\h \i \space \t \h \e \r \e] Given string is 'hi there' Bytes length is 8 OtpBinary size is 35 with [ inside (str s) ] I was given a class java.lang.String Chars are [\h \i \space \t \h \e \r \e] Given string is 'hi there' Bytes length is 8 OtpBinary size is 8 So, I'm hoping this gives somebody an idea, because I'm stumped. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
demo.clj
Description: Binary data