<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><BR><DIV><DIV>On Jun 28, 2006, at 6:45 PM, Romain Lenglet wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">ke han wrote:</DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Jun 28, 2006, at 2:47 PM, Romain Lenglet wrote:</DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Personally, I am voting for (1) representing strings as</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">lists of Unicode code points, but (2) providing a better</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(more flexible, more efficient) external representation, and</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">most importantly (3) providing a more flexible interface to</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">the external encoding/decoding primitives, such as</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">supporting strings as tuples as above.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I don't care about the internal representation of string so</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">long as its (a) _significantly_ more memory efficient than one</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">word per character in a list and (b) allows me to pass these<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">non-mutable strings between processes without a mem copy each</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">time.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">My end game is writing web apps in erlang+yaws+mnesia.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">What we were discussing is how to internally represent, and<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">externally encode (in the term_to_binary/1 sense), strings in a<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">form suitable for building or modification by programs. You are<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">discussing about the need to pass around strings that are<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">already 8-bit encoded and that don't need to be modified.<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Different problems. Different representations.</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>right..I do understand this thread has several facets...I'm adding my high level application needs into the mix to ensure they aren't forgotten...why, because I haven't the skills to solve this low level problem and need guys like you who do understand the internals of erlang to take these needs into account in hopes of eventually getting something useful ;-)</DIV><BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">The basic result of any yaws page (or any dynamic html server)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">is to output a sequence of terms into a stream the browser is</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">expecting. This means the following concatenation or list of</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">"strings"<SPAN class="Apple-converted-space"> </SPAN>is common in streaming out a page:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Header + StaticWebPagePreamble +</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">StaticContentSuchAsLabelsLookedUpByUsersLangPref +</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">HTMLInputControl + ContentForInputControl + ...<SPAN class="Apple-converted-space"> </SPAN>+</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">HTMLSelectControl +</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">ContentForSelectControl + StaticWebPageFooter</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">[...]</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Since you don't seem to need to modify the contents of those<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">strings, why don't IO-lists (i.e. a list of binaries) fit your<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">need? You should simply pass a list of binaries, where each<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">binary contains text is 8-bit encoded in UTF-8 or ISO-8859-1 or<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">whatever. Binaries are not copied. Such IO-lists are what is<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">used to communicate with linked-in C drivers. IO-lists are the<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">most efficient way to transmit large data in an Erlang node.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Why doesn't that fit your needs?</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I understand that a lengthy binary is not copied. I have seen posts on this maillist that short binaries _are_ copied and long ones _are not_...but I don't know what length determines when something is copied or not.</DIV><DIV>In the example I gave, my countryManager process is a singleton (pardon the oo pattern reference, but thats what it is) that serves the entire VM to answer a list of countries. This is a lengthy list of short utf-8 encoded binaries. So wouldn't the list get copied? And won't each short binary in the list get copied as well? There must be a better way.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>In order to get around this problem, I would have to destroy MVC separations and have my model object (countryManager) return an already serialized binary of binaries (or if I'm going to do that I may as well have the countryManager go ahead and serialize it to json form as well). </DIV><DIV>This violates lots of sounds application design. Basic principles of encapsulation and separation of presentation and app logic are well grounded in OO design. These principals apply to non-OO languages as well. I understand that not having object references and copying terms between calls to erlang processes is a key element of erlang. But for non-mutable strings??? Not having a solution for this makes mainstream web apps very inefficient.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>To reference Richard's earlier post:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">> </SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">STRINGS ARE WRONG.</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Helvetica; min-height: 16px; ">><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">>Strings are a good data type for text that you are NOT going to manipulate.</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">>If you have to manipulate text, it's usually a good idea to convert it to</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">>something else as quickly as you can, such as an abstract syntax tree.</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">>This will be orders of magnitude cheaper to process, even in C.</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;"><BR class="khtml-block-placeholder"></SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 13px;">I agree. I am talking about handling these non-mutable things (I've been calling them strings) that need to be stored (in mem and on disk) and passed around between processes efficiently.</SPAN></FONT></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>My point of providing a real world example of how I need to use strings is that talk of string implementation without defining a set of cases for how it would be used is pretty, well useless.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>As Ulf points out, my scenario gets even worse with 64-bit erlang.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>thanks, ke han</DIV><BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Romain LENGLET</DIV> </BLOCKQUOTE></DIV><BR></BODY></HTML>