[REBOL] Re: Vertical formatting etc
From: joel:neely:fedex at: 2-Oct-2001 10:47
Hi, Mike,
(It is Mike, right?)
mgkiourt wrote:
> a)If I have e.g., ["Put" "them" "together"] how will I take
> ["Put them together"]
>
Here are a few alternatives:
>> buffer: ""
== ""
>> foreach item ["Put" "them" "together"] [
[ append buffer item
[ append buffer " "
[ ]
== "Put them together "
>> remove back tail buffer
== ""
>> buffer
== "Put them together"
or
>> buffer: ""
== ""
>> delim: ""
== ""
>> foreach item ["Put" "them" "together"] [
[ append buffer rejoin [delim item]
[ delim: " "
[ ]
== " "
>> buffer
== "Put them together"
If you really want the result to be a string inside a block,
then
reduce [buffer]
after either of the above will get you that result. Or you
can be slightly obscure and write
>> reduce [
[ head remove back tail foreach item [
[ "Put" "them" "together"] [
[ append "" rejoin [item " "]
[ ]
[ ]
== ["Put them together"]
But that's a bit over the top! ;-)
> b)If I have [a b c] how will I take [a
> b
> c
> ]
>
Sorry, but I don't understand the question.
> c) If I have [0 0 0 0] how will I ask to print any non-zero
> numbers and what output will I have?
>
One way is
>> foo: [0 0 0 0]
== [0 0 0 0]
>> foreach item foo [if not zero? item [print item]]
== none
>> foo: [0 1 0 -1]
== [0 1 0 -1]
>> foreach item foo [if not zero? item [print item]]
1
-1
HTH!
-jn-
--
This sentence contradicts itself -- no actually it doesn't.
-- Doug Hofstadter
joel<dot>neely<at>fedex<dot>com