I knew Jeff would jump all over my example <grumble grumble> ;-)

I didn't know build-tag was built-in to REBOL yet.  I originally
started with a COMPOSE but didn't want to dig out the build-tag
code.  Guess I should have tried:

help build-tag

before starting :-)

I also toyed with enbase, but it wasn't as straightforward from
a user's standpoint in my opinion as the method I chose.

Just wanted to point out that I had thought about it a little
before allowing my fingers to tap it out.

But mine still uses less bytes to store the function so there!

On 29-Oct-1999/13:37:15-6:00, [EMAIL PROTECTED] wrote:
>
>Howdy johnkenyon:
>
>Bo said:
>
>>  How 'bout this:
>>
>> color-text: func [intensity text][
>>    rejoin [
>>         <lb><FONT color="#<rb>
>>        copy/part tail form to-hex to-integer intensity * 2.55 -2
>>        <lb>8000"><rb> text </FONT>]
>>]
>
> Here's another approach, a little less string-concatenatey:
>
>;- You get back a block with two tag!s surrounding whatever 'text is
>
>color-text: func [intensity text][
>    compose [ (build-tag [FONT COLOR 
>    (mold join # [enbase/base form to-char intensity * 2.55 16 8000])])
>        (text) </FONT>
>    ]
>]
>
>ENBASE is a pretty cool function.  It lets the above code use less
>conversions which lends it some efficiency.  (An implicit integer
>round off occurs with to-char by the way.) The real efficency win,
>however, comes from doing less copying.
>
>Lets see:  The first example does a decimal to integer to hex to
>string to a copy of part of that string joined to copies of other
>strings, including the passed in text.
>
>The second example does a decimal to a char to a string, joined (which
>copies) with an empty issue made into a tag, which is dropped into a
>block with the text and another tag, with out copying the original
>passed in text.
>
>Generally speaking the second example will do less copying especially
>if the text passed in grows large. Also, the second example treats
>numeric data in a more numeric way. Finally, the result of the second
>example maintains its distinct datatypes, which could be useful if you
>want distinguish tags from text in the result later on without having
>to parse it. The second takes a more symbolic approach.
>
>Not to cast any hint of aspersion on Bo's solution! (-: It certainly
>suffices for your purposes just fine, and it may be more intuitive to
>some. I only mean to suggest that in REBOL, as in all languages, there
>is always room for optimization. REBOL is a symbolic language, so
>symbolic approaches to problem solving will generally be more
>efficient in REBOL than approaches based largely on string
>manipulation.
>
>But of course I don't imagine that my approach is the most optimal
>either!! :-)
>
>    Just trying to be helpful....
>
>    -jeff
>
-- 
                           Bohdan "Bo" Lechnowsky
                           REBOL  Adventure Guide
           REBOL Technologies 707-467-8000 (http://www.rebol.com)
          Download the REBOL Messaging Language for all Platforms

Reply via email to