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

Quick REBOL question from a newbie

 [1/10] from: glenn:hometot at: 4-Oct-2005 14:35


Hi all! I'm trying to do this (Ruby):
>> 340.times {|i| puts "%03d" % i }
000 001 002 ::: 339 in REBOL, but I can't figure out how. Any ideas? Thanks! -- Glenn

 [2/10] from: AJMartin:orcon at: 4-Oct-2005 22:13


Glenn wrote:
> I'm trying to do this (Ruby): > >> 340.times {|i| puts "%03d" % i }
<<quoted lines omitted: 5>>
> in REBOL, but I can't figure out how. Any ideas? >> repeat i 3 [print i]
1 2 3 Rebol seems easier to me. AJ Martin Auto-surfing for 4% daily at: http://www.surfmunkee.com/?ref=7295 Are you The Next Internet Millionaire? http://ajmartin.thenextinternetmillionaire.com/

 [3/10] from: tom:conlin:gmai:l at: 4-Oct-2005 14:59


I'm betting the formatting was the rub
>> repeat i 3 [s: to string! i insert/dup s "0" 3 - length? s print s]
001 002 003 On 10/4/05, A J Martin <[AJMartin--orcon--net--nz]> wrote:
> Glenn wrote: > > I'm trying to do this (Ruby):
<<quoted lines omitted: 20>>
> To unsubscribe from the list, just send an email to > lists at rebol.com <http://rebol.com> with unsubscribe as the subject.
-- .... nice weather eh

 [4/10] from: glenn:hometot at: 4-Oct-2005 15:03


The formatting was definitely the rub. Thanks, Tom! I appreciate it! -- Glenn Tom Conlin wrote:

 [5/10] from: SunandaDH::aol::com at: 4-Oct-2005 18:06


Glenn:
> I'm trying to do this (Ruby):
I guess the first bit you are okay with: running a loop: for n 0 399 1 [print n] It's that fixed-length with leading zeroes you want, yes? Sadly, there is no C-style printf (or even VB- or Cobol-style picture) formatting available as standard in REBOL......Still waiting for someone to write it :-) Meanwhile, two suggestions: Do it by hand: for n 0 399 1 [loop 3 - length? form n [prin "0"] print n] Get an assist from align.r in the Library: http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=ali gn.r for n 0 399 1 [print replace/all align/right n 3 " " 0] Sunanda

 [6/10] from: compkarori::gmail::com at: 5-Oct-2005 0:55


>> i: 999 loop 300 [ print next form i: i + 1 ]
000 001 002 003 004 005 On 10/5/05, [SunandaDH--aol--com] <[SunandaDH--aol--com]> wrote:
> Glenn: > > I'm trying to do this (Ruby):
<<quoted lines omitted: 15>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu

 [7/10] from: glenn:hometot at: 4-Oct-2005 17:17


Wow!!! It took me 10 minutes to figure out what you were doing, but I never would have come up with that one myself!!! Thanks, Graham! -- Glenn Graham Chiu wrote:

 [8/10] from: carl::cybercraft::co::nz at: 5-Oct-2005 13:17


On Tuesday, 4-October-2005 at 17:17:57 Glenn M. Lewis wrote,
>Wow!!! It took me 10 minutes to figure out what you were doing, >but I never would have come up with that one myself!!! >Thanks, Graham! >-- Glenn
I disagree. Bad Graham! ;-)
>Graham Chiu wrote: >>>>i: 999 loop 300 [ print next form i: i + 1 ]
<<quoted lines omitted: 5>>
>> 004 >> 005
My approach to formatting...
>> repeat i 5 [ print skip tail join "00" i -3 ]
001 002 003 004 005 Though it's no good if i exceeds the number of digits you've decided on. -- Carl Read.

 [9/10] from: petr::krenzelok::trz::cz at: 5-Oct-2005 11:49


Graham Chiu napsal(a):
>>>i: 999 loop 300 [ print next form i: i + 1 ] >>>
<<quoted lines omitted: 5>>
>004 >005
Oh man, you made my REBOL day ;-) So clever way of how to substitute 'pad function, right? :-) -pekr-

 [10/10] from: gerardcote::sympatico::ca at: 7-Oct-2005 19:48


Hi Glenn, Here is a small function that I called "pad-left" that seems really natural to use for people beginning with REBOL learning and coming from say VB. I used the "for" construct with the "insert" function to get a final product that is versatile and near enough of the style you wanted to get. Its use can be easily deduced but my user manual is: pad-left start-number end-number step pad-character as in: pad-left 2 120 5 " " (white-space) Here is my code: pad-left: func [start end step pad-char][ end-length: length? form end for c start end step [ n: form c ; Integer to string cvt insert/dup at n 1 pad-char (end-length - (length? n)) ; Real padding done here print n ] ] I developed the main part on a single line but found it too much ugly to keep it in this former state... Enjoy it! Gerard Cote

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