REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: repend

repend  series  value  /part  length  /only  /dup  count

Appends a reduced value to a series and returns the series head.

Arguments:

series [series! port! map! gob! object! bitset!] - Series at point to insert

value - The value to insert

Refinements:

/part - Limits to a given length or position

length [number! series! pair!]

/only - Inserts a series as a series

/dup - Duplicates the insert a specified number of times

count [number! pair!]

See also:

append   insert   reduce   join  

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
[%build-docs.r 7915 13-Feb-2009/0:03:17.078 %bulk-modify.r 4210 7-Feb-2009/17:20:06.906 %cgi.r 5125 12-Feb-2009/20:54:51.578 %convert-orig.r 1112 7-Feb-2009/17:20:06.906 %emit-html.r 10587 13-Feb-2009/0:09:38.875 %eval-examples.r 2545 13-Feb-2009/1:46:59.765 %fix-args.r 416 13-Feb-2009/0:41:11.296 %funcs.r 1133 12-Feb-2009/18:54:32.875 %merge-funcs.r 1318 13-Feb-2009/0:42:03.718 %replace.r 197 7-Feb-2009/16:56:23 %scan-doc.r 3429 13-Feb-2009/0:05:33.062 %scan-titles.r 4402 12-Feb-2009/16:51:42.687 %strip-title.r 274 7-Feb-2009/17:20:06.953]

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: 12-Feb-2009<P>Time is: 17:47:54<P>Zone is: -8:00<P></body></html>


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin