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

Vertical formatting etc

 [1/9] from: mgkiourt::otenet::gr at: 2-Oct-2001 15:53


a)If I have e.g., ["Put" "them" "together"] how will I take ["Put them together"] b)If I have [a b c] how will I take [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?

 [2/9] from: greggirwin:starband at: 2-Oct-2001 9:36


<< a)If I have e.g., ["Put" "them" "together"] how will I take ["Put them together"] b)If I have [a b c] how will I take [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?
>>
I'm not clear on what you're asking, but I think you're talking about outputting the results to the console. In that case, look at prin and print. print prints with a newline and prin does not. You can also use ASCII escape sequences to position the cursor in the console. I think the Core docs talk about it but Ingo Hohmann's console dialect article on the REBOL Forces site provides the best info I've seen on it. To keep only non-0 numbers, you should be able to use exclude:
>> exclude [0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9][0]
== [1 2 3 4 5 6 7 8 9] --Gregg

 [3/9] 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

 [4/9] from: carl:cybercraft at: 3-Oct-2001 22:00


On 03-Oct-01, Joel Neely wrote:
> Hi, Mike, > (It is Mike, right?)
<<quoted lines omitted: 40>>
> == ["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?
<<quoted lines omitted: 11>>
> HTH! > -jn-
-- Carl Read

 [5/9] from: joel:neely:fedex at: 3-Oct-2001 5:56


Hi, Carl, Carl Read wrote:
> Or you could try the under-the-top version... > > >> reduce [reform ["Put" "them" "together"]] > == ["Put them together"] >
Thanks for the reminder!
> Joel slaps head! (; (Unless he was being horribly cruel...:) > > Use 'rejoin instead of 'reform if you don't want spaces between > the strings... >
Not trying to be cruel, just flexible... If the next question is, "Now how do I put commas between them?" you just replace the with "," in all of the code samples.
> If however the formatting was wanted in the block, then I don't think > it can be done, as this suggests... >
I believe that it can,
>> whatever: [a b c]
== [a b c]
>> use [buf del] [
[ buf: "" [ del: "[" [ foreach item whatever [ [ append buf rejoin [del item] [ del: "^/^-" [ ] [ append buf "]" [ thingie: load buf [ ] == [a b c]
>> thingie
== [a b c] but don't see why anyone would want to do this! -jn- -- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] foreach [order string] sort/skip reduce [ true "!" false head reverse "rekcah" none "REBOL " prin "Just " "another " ] 2 [prin string] print ""

 [6/9] from: cyphre:volny:cz at: 3-Oct-2001 16:31


what about:
>> form ["Put" "them" "together"]
== "Put them together"
>>
regards Cyphre

 [7/9] from: d4marcus:dtek:chalmers:se at: 3-Oct-2001 20:56


On Tue, 2 Oct 2001, mgkiourt wrote:
> a)If I have e.g., ["Put" "them" "together"] how will I take ["Put them together"] > b)If I have [a b c] how will I take [a > c) If I have [0 0 0 0] how will I ask to print any non-zero numbers
Others have given more verbose answers, so here are the brief versions: a) to-block mold form ["Put" "them" "together"] b) to-block foreach i [a b c] [repend "" [i newline]] c) foreach i exclude copy [0 0 0 0] [0] [print i] Marcus ------------------------------------ If you find that life spits on you calm down and pretend it's raining

 [8/9] from: carl:cybercraft at: 4-Oct-2001 10:42


On 04-Oct-01, Richard Smolak wrote:
> what about: >>> form ["Put" "them" "together"] > == "Put them together"
Chuckle - yeah, two more bytes saved. I just forget that 'form isn't just 'join with spaces added...
>> join "aaa" "bbb"
== "aaabbb"
>> form "aaa" "bbb"
== "bbb" so I tend to use 'reform and 'rejoin when joining strings in a block, as I'm sure it'd make my head hurt if I tried to figure out why 'join and 'form are not almost the same... -- Carl Read

 [9/9] from: carl:cybercraft at: 4-Oct-2001 11:18


On 03-Oct-01, Joel Neely wrote:
>> If however the formatting was wanted in the block, then I don't >> think it can be done, as this suggests...
<<quoted lines omitted: 18>>
> b > c]
I stand corrected.
> but don't see why anyone would want to do this!
For code that generates code, perhaps, and they want it nicely formatted? I doubt that's why this question was asked though...
> -jn-
-- Carl Read

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted