REBOL Document

Repend - Function Summary


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
    [%dictionary.r 7754 5-Jan-2003/11:29:48-8:00 %comments.r 2966 24-Ja
n-2003/22:53:58-8:00 %undoced.r 3172 26-Jan-2003/0:08:16-8:00 %rebol-tes
t-file.r 103 9-Mar-2004/1:00-8:00 %date.r 23 9-Mar-2004/0:58:24-8:00 %da
ta.r 29 9-Mar-2004/0:58:24-8:00 %upload.r 746 9-Mar-2004/0:41:48-8:00 %d
atecode.r 23 9-Mar-2004/0:39:34-8:00 %words.r 185013 9-Mar-2004/0:41:52-
8:00 %dict-html.r 15043 9-Mar-2004/0:59:26-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: 9-Mar-2004<P>Time is: 0:59:58<P>Zone is: -8:00
<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.


<Back | Index | Next>

Copyright 2004 REBOL Technologies