Summary:
Appends a reduced value to a series and returns the series head.
Usage:
repend series value
Arguments:
series - The series argument. (must be: series port)
value - The value argument.
Refinements:
/only - Appends a block value as a block
Description:
REPEND stands for REDUCE APPEND. It performs the same operation
as APPEND (inserting elements at the tail of a series) but
REDUCES the block of inserted elements first. Just like APPEND,
REPEND returns the head of the series.
For example, writing:
numbers: [1 2 3]
probe repend numbers [2 + 2 2 + 3 3 + 3]
[1 2 3 4 5 6] |
is the same as writing:
numbers: [1 2 3]
probe append numbers reduce [2 + 2 2 + 3 3 + 3]
[1 2 3 4 5 6] |
REPEND is very useful when you want to add to a series elements
that need to be evaluated first. The example below creates a
list of all the .r files in the current directory, along with
their sizes and modification dates.
data: copy []
foreach file load %. [
if %.r = suffix? file [
repend data [file size? file modified? file]
]
]
probe data
[%comments.r 2966 24-Jan-2003/23:53:56-8:00 %data.r 30 25-Jan-2003/
17:29:21-8:00 %date.r 25 25-Jan-2003/17:29:21-8:00 %datecode.r 25 14-Feb
-2003/10:27:44-8:00 %dict-html.r 13061 14-Feb-2003/9:53:26-8:00 %diction
ary.r 7754 5-Jan-2003/12:29:46-8:00 %install.r 1381 25-Jun-2002/10:14:10
-7:00 %rebol-test-file.r 7 25-Jan-2003/17:29:50-8:00 %undoced.r 3172 26-
Jan-2003/1:08:14-8:00 %upload.r 715 13-Feb-2003/19:08:32-8:00 %words.r 1
78711 15-Feb-2003/4:20:25-8:00 %wordsums.r 6417 15-Feb-2003/4:19:12-8:00] |
When used with strings, repend is a useful way to join values.
The example below is a common method of generating HTML web
page code:
html: copy "<HTML><BODY>"
repend html [
"Date is: " now/date <P>
"Time is: " now/time <P>
"Zone is: " now/zone <P>
</BODY></HTML>
]
print html
<HTML><BODY>Date is: 15-Feb-2003<P>Time is: 4:20:33<P>Zone is: -8:0
0<P></BODY></HTML> |
Related:
append - Appends a value to the tail of a series and returns the series head. insert - Inserts a value into a series and returns the series after the insert. join - Concatenates values. reduce - Evaluates an expression or block expressions and returns the result.
|