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

[REBOL] Re: to-char

From: carl:cybercraft at: 14-Feb-2002 12:46

On 14-Feb-02, Jason Cunliffe wrote:
> From: "Joel Neely" <[joel--neely--fedex--com]> >> Forgive me if I over-explain. I don't mean to insult your >> intelligence/experience. This kind of question comes up >> periodically, so I thought I'd cover all the basics in case >> any newcomers to the list are puzzled by this (or related) >> issues. > Joel > Thanks very much. Your explanation and the posts which followed were > just what I was hoping for.
I'll give it a go, though the terms I use may not all be comp-science perfect...
> So now let me ask an even more basic [FA] question:
A question for you - what's "FA"? (:
> What is happening, what is the real meaning of > someblock: []
An empty block is created, as is the word 'someblock, which points to (references) the block. If you now made another word to reference someblock, they would both be referencing the same block. A Console example...
>> someblock: []
== []
>> not-another-block: someblock
== []
>> append someblock "abc"
== ["abc"]
>> someblock
== ["abc"]
>> not-another-block
== ["abc"]
> What is going on when I call it within a function and then call the > function repeatedly [when the previous values remain]. ie: why do I > _really_ need clear or copy?
The reason can be seen in the above, in that it remains the same block. Meaning you haven't made a copy of the block. Continuing on with the above, this shows the difference 'copy makes...
>> another-block: copy someblock
== ["abc"]
>> append someblock "def"
== ["abc" "def"]
>> someblock
== ["abc" "def"]
>> another-block
== ["abc"]
> Would like to see more helpful doc lookups for : and []
The Core Guide on RT's site is very good here. (It's a full copy of the book version.) See the "series" and "block" sections, blocks being a subset of series.
>>> ? : > ** Syntax Error: Invalid word-get -- : > ** Near: (line 1) ? :
The ":" is just used to define a word - it's says "make this word reference what follows". In the case of series such as blocks and strings, the word is used as an index to the series. So words can be used thus...
>> append someblock ["ghi" "jkl"]
== ["abc" "def" "ghi" "jkl"] That adds two more strings to 'someblock...
>> someblock
== ["abc" "def" "ghi" "jkl"] 'next in the following looks at the block from the next value onwards from where 'someblock's index is pointing. (Which is the first value in the block.)
>> next someblock
== ["def" "ghi" "jkl"] And this creates the word 'a-word to reference the block at that second position...
>> a-word: next someblock
== ["def" "ghi" "jkl"]
>> a-word
== ["def" "ghi" "jkl"] And now to see what the words' indexes are...
>> index? someblock
== 1
>> index? a-word
== 2 And finally, proof (using the 'head word) that 'a-word can reference the full block...
>> head a-word
== ["abc" "def" "ghi" "jkl"]
>>> ? [] > [] is a block
Blocks are very inportant in REBOL, but they're quite a simple concept, being just a container for other stuff.
>>> ? clear > USAGE: > CLEAR series > DESCRIPTION: > Removes all values from the current index to the tail. Returns > at tail. > CLEAR is an action value. > ARGUMENTS: > series -- (Type: series port none)
Clear just empties a series of its values, (from the index-point onwards of the word you're using to reference it), and so the series still exists after a 'clear, its just empty, like "" is an empty string, or [] is an empty block. More on functions: A series is created when the function is first created and not each time the function is called, which is why what's in a series will persist from function-call to function-call unless you specifically clear it or make a copy of it. Whether to use 'copy or 'clear (or neither for that matter) will depend on the behaviour you want from the series. HTH, and that I've got it all more or less right. Others here will (I hope) correct me where I'm wrong. -- Carl Read