[REBOL] Re: Text-List more help please
From: gjones05:mail:orion at: 25-May-2001 19:35
From: "Ammon Cooke"
> Thanks, now I need to be able to convert that to an integer so I can
do a
> for loop stopping at the length of the list. ;))
This expression returns an integer:
length? tl1/data
I changed it to a string so that it could be inserted into the text
label.
to-string length? tl1/data
While REBOL offers a 'for loop, I can only remember using it one time.
I have found 'foreach, 'forall, and 'forskip to be much more powerful
and easier to use. If you need to process each item in the list, do
what I did: use 'foreach. Example:
fruits: ["apples" "oranges" "bananas" "pears" "kiwi"]
foreach fruit fruits [print ["The length of the word" fruit "is" length?
fruit]]
Would a looping structure like this work?
> Now to fix the vaugeness of the last question I asked :))) Have you
ever
> scripted with Perl??
I hacked a Perl script once, does that count? :-)
I'm slightly familiar with it.
> If so, the values of an array are accessed from an
> index:
>
> $array[0]
> $array[1]
> $array[2]
>
> Is there a similar way to access data from a list with REBOL??
I guess my example above answers the question. Does it?
> PS Is there absolutely nothing to gain by not declaring variables in
REBOL
> or why don't I ever see anything about?
When you say "declaring a variable", are you meaning assigning a value
to a variable, or are you meaning assigning a type to a variable? (or
both?)
I assume that what you are getting at is why don't you see more variable
assignments in REBOL. Like why do this:
...
remove find tl1/data p
...
and not this:
...
index: find tl1/data p
remove index
...
It can be done, if you wish, and for clarity, especially early in
programming, this may help you see the flow of data. However, the
ability to take advantage of REBOL's abilities in fucntional programming
is what I like most about it. Most of the throw-away, temporary
variables are no longer needed. The data in the code just "flows"
along.
It's like our spoken language itself: ideas hook together, and act upon
each other in a kind of stream or flow. Like spoken languages, the
REBOL way becomes very natural after a while, and then it will seem
annoying to set up temporary variables in other languages. At least it
does for me. But I will readily admit that it requires a paradigm shift
in comparison to more strictly imperative languages like Pascal. No one
doubts that Perl is a fine, powerful language. It is more C like in its
characteristics, at least if I recall correctly.
I am no expert on any of these concepts, but a useful reference that
talks more about the difference between imperative programming versus
functional programming can be found at the following link. Haskell is a
functional language that is similar to REBOL in concept. Check it out
when you have ten minutes.
http://www.haskell.org/aboutHaskell.html
> Thanks!!
> Ammon
You are welcome!
--Scott Jones