Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: to-char

From: carl:cybercraft at: 12-Feb-2002 19:24

Hi again Daniel, On 12-Feb-02, [Izkata--aol--com] wrote:
> I've looked at all the responses so far, and > it's almost what I wanted. Heres a better example: > to-charblock: "Hi" > would make: > block: [ > H > i > ]
Ah - you actually want 'H and 'i there to be REBOL "word"s, not REBOL char acters - except they're just 1-letter words.
> then, > H: [print "*** **** ****"] > i: [print "*** iiii"] > so, > do block > *** **** **** > *** iiii
As you have it there, the 'do wouldn't work as you expect, as this sesion at the REBOL Console shows...
>> block: [H i]
== [H i]
>> H: [print "*** **** ****"]
== [print "*** **** ****"]
>> i: [print "*** iiii"]
== [print "*** iiii"]
>> do block
== [print "*** iiii"] Which isn't the result you want. However, if 'H and 'i are made to do their block (pun not intended:) using 'does, you get what you want...
>> H: does [print "*** **** ****"] >> i: does [print "*** iiii"] >> do block
*** **** **** *** iiii (Testing stuff a bit at a time at the Console is a good way to work things out.) 'does turns 'H and 'i into functions (without any arguments), the difference being you'll get the result returned by the function, whereas when they were just blocks, the block is what you get. Um, this probably explains it better...
>> a-block: [print "something"]
== [print "something"]
>> a-block
== [print "something"]
>> a-block: does [print "something"] >> a-block
something Finally, to get words instead of characters into the block, you can use 'to-word. Except it can't convert a character directly to a word, (ie, an #"H". That's a character, whereas "H" is a string.), so you need to convert each character in your string into a 1-character string before you can convert it into a word. I know it sounds convoluted, but the function to do what you want is a lot shorter than this paragraph you'll be happy to hear. (: ... to-charblock: func [str [string!] /local blk][ blk: copy [] foreach letter str [append blk to-word to-string letter] blk ] You should be able to cut and paste that function directly into the Console to test it, and assuming you can, it can be used to give these results (as long as you've also entered the 'H and 'i functions first in the way I suggested above)...
>> block: to-charblock "Hi"
== [H i]
>> do block
*** **** **** *** iiii Have we got it right now? Though don't be afraid to say no if we haven't - it's what the list is for.
> I am going to use a combination of > * and spaces to make a mouth that would > 'talk' to you. > I am going to try what was suggested, though. > Daniel S.
-- Carl Read