[REBOL] Re: Using "repeat" in write/append/lines
From: greggirwin:mindspring at: 4-May-2004 14:25
Tom gave you the best general answer, using REPEAT *around* the calls
you want to make, so I'll just chime in with a note.
Disks are faster these days, but you probably don't want to use WRITE
repeatedly if you're going to be making ten thousand calls that way.
Instead, build up a string buffer and write the whole thing out at
once, or in sections.
INSERT/DUP handily creates a filled string:
head insert/dup clear "" #"*" 10
which you could then wrap up in a function (named for your use here):
ascii-bar: func [len /with fill] [
head insert/dup clear "" any [fill #"*"] len
>> ascii-bar 5
>> ascii-bar 15
>> ascii-bar/with 15 "."
>> ascii-bar/with 15 ".-"
Here's the function, broken down.
head ;- INSERT returns at the point *after* the
insert/dup ; insertion, so we use HEAD to get the top.
clear "" ;* Read up on how local series values are
; retained in functions.
any [ ;- ANY is like a list of OR clauses
fill ;- If FILL (e.g.) is none, it will go on to
#"*" ; the next item in the block, until it finds
] ; a non-none/non-false value.
len ;- This is the value for the DUP refinement