[Cuis] Ropes (functional strings)

Juan Vuletich juan at jvuletich.org
Tue Feb 12 21:37:31 CST 2013


Wow! This is really cool!

I must admit that I don't know when it makes sense to use it, but it is 
really interesting.

My idea of maybe using uft-8 bytearrays for Strings everywhere was based 
on the intuition that maybe #at: and #at:put: are (maybe almost) not 
needed by the system. Now this gives a third alternative, with its own 
distinct balance between cost of different operations and memory usage. 
I guess the first question to be answered remains the same: Do we need 
modifiable Strings? Or immutable Strings are enough?

Food for though...

BTW, I find it totally amazing that you could hook this into the 
existing TextModel and text editor _without modifying a single method_!

WRT #encompassParagraph:, the idea is pretty simple. On many text 
editors (like, for instance, this email client), doing triple click 
selects the whole paragraph. #encompassParagraph: answers just that. You 
pass an interval, i.e. start and end indexes of some substring, and the 
method answers whole paragraphs containing it. This is used, for 
instance, to ensure that a TextAlignment attribute is applied to whole 
paragraphs, as for instance, it doesn't make sense to have part of a 
paragraph justified and part of it centered. The method has a reasonable 
comments, and in senders you'll find some tests. HTH.

Cheers,
Juan Vuletich

On 12/02/2013 01:08 a.m., Ken Dickey wrote:
> Juan wrote:
>
>> Yesterday I played a bit to see how quickly the system would break if
>> #at: and #at:put: were banned for Strings.
> I did a simple, prototype implementation of Ropes, functional strings, for Cuis.
>
> Ropes are _immutable_ (constant) strings, and #at:put: returns a new Rope.  Internal data structures hide the details.
>
> The basic idea is that I had a utf-8 Rope and #at:put: a utf-32 Chinese character into it, then we would NOT have to change the utf-8 part just because of one character.  We could have separate 8/16/32 bit char-arrays supporting Unicode and do mix 'n match as we needed.
>
> 	https://github.com/KenDickey/Cuis-Ropes
>
> Invoking
> 	Rope openTextEditor
> brings up a simple text editor with a rope instead of a string.
>
> This seems to work OK for me, but more knowledgeable people should take a look.
>
> As this is a prototype, Rope>>doesNotUnderstand writes a message to the Transcript and re-sends it to its stringRepresentation.
>
> So far, I have only seen sends to #encompassParagraph, which I don't yet understand and did not implement.
>
> Anyway, feel free to take a look and let me know if you think it is useful.
>
> Cheers,
> -KenD
>
> _______________________________________________
> Cuis mailing list
> Cuis at jvuletich.org
> http://jvuletich.org/mailman/listinfo/cuis_jvuletich.org
>
>





More information about the Cuis mailing list