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

[REBOL] Re: Vertical formatting etc

From: carl:cybercraft at: 3-Oct-2001 22:00

On 03-Oct-01, Joel Neely wrote:
> 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! ;-)
Or you could try the under-the-top version...
>> reduce [reform ["Put" "them" "together"]]
== ["Put them together"] Joel slaps head! (; (Unless he was being horribly cruel...:) Use 'rejoin instead of 'reform if you don't want spaces between the strings...
>> rejoin ["Put" "them" "together"]
== "Putthemtogether"
>> b)If I have [a b c] how will I take [a >> b >> c >> ] >> > Sorry, but I don't understand the question.
I'm not sure either, but if he means to print them out seperately, then this would do...
>> foreach n [a b c] [prin " " print n]
a b c If however the formatting was wanted in the block, then I don't think it can be done, as this suggests...
>> blk: [a b c]
== [a b c]
>> 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-
-- Carl Read