REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Series: Series as Data Sets

Pending Revision

This document was written for R2 and has yet to be revised for R3.

There are a few functions that operate on series as data sets. These functions allow you to perform operations such as finding the union or intersection between two series.

Contents

Unique

The unique function returns a unique set that contains no duplicate values.

Examples:

data: [Bill Betty Bob Benny Bart Bob Bill Bob]
probe unique data
[Bill Betty Bob Benny Bart]
print unique "abracadabra"
abrcd

Intersect

The intersect function takes two series and returns a series that contains the values that are present in both series.

Examples:

probe intersect [Bill Bob Bart] [Bob Ted Fred]
[Bob]
lunch: [ham cheese bread carrot]
dinner: [ham salad carrot rice]
probe intersect lunch dinner
[ham carrot]
print intersect [1 3 2 4] [3 5 4 6]
3 4
string1: "CBAD"    ; A B C D scrambled
string2: "EDCF"    ; C D E F scrambled
print sort intersect string1 string2
CD

The intersection can be found between bitsets:

all-chars: "ABCDEFGHI"
charset1: charset "ABCDEF"
charset2: charset "DEFGHI"
charset3: intersect charset1 charset2

print find charset3 "E"
true
print find charset3 "B"
false

The /case refinement allows case-sensitive intersection:

probe intersect/case [Bill bill Bob bob] [Bart bill Bob]
[bill Bob]

Union

The union function takes two series and returns a series that contains all the values from both series, but no duplicates.

Examples:

probe union [Bill Bob Bart] [Bob Ted Fred]
[Bill Bob Bart Ted Fred]
lunch: [ham cheese bread carrot]
dinner: [ham salad carrot rice]
probe union lunch dinner
[ham cheese bread carrot salad rice]
print union [1 3 2 4] [3 5 4 6]
1 3 2 4 5 6
string1: "CBDA"    ; A B C D scrambled
string2: "EDCF"    ; C D E F scrambled
print sort union string1 string2
ABCDEF

The union function can also be used on bitsets:

charset1: charset "ABCDEF"
charset2: charset "DEFGHI"
charset3: union charset1 charset2

print find charset3 "C"
true
print find charset3 "G"
true

The /case refinement allows case-sensitive unions:

probe union/case [Bill bill Bob bob] [bill Bob]
[Bill bill Bob bob]

Exclude

The exclude function takes two series and returns a series that contains all the values of the first series, less the values of the second.

probe exclude [1 2 3 4] [1 2 3 5]
[4]
probe exclude [Bill Bob Bart] [Bob Ted Fred]
[Bill Bart]
lunch: [ham cheese bread carrot]
dinner: [ham salad carrot rice]
probe exclude lunch dinner
[cheese bread]
string1: "CBAD"    ; A B C D scrambled
string2: "EDCF"    ; C D E F scrambled
print sort difference string1 string2
AB

The /case refinement allows case-sensitive exclusion:

probe exclude/case [Bill bill Bob bob] [Bart bart bill Bob]
[Bill bob]

Difference

The difference function takes two series and returns a series that contains all of the values not in common with both series.

Examples:

probe difference [1 2 3 4] [1 2 3 5]
[4 5]
probe difference [Bill Bob Bart] [Bob Ted Fred]
[Bill Bart Ted Fred]
lunch: [ham cheese bread carrot]
dinner: [ham salad carrot rice]
probe difference lunch dinner
[cheese bread salad rice]
string1: "CBAD"    ; A B C D scrambled
string2: "EDCF"    ; C D E F scrambled
print sort difference string1 string2
ABEF

The /case refinement allows case-sensitive differences.

probe difference/case [Bill bill Bob bob] [Bart bart bill Bob]
[Bill bob Bart bart]

Exclude

A variation of the difference function is the exclude function. It returns the values that are in the first series but not found in the second series. For example:

probe exclude [1 2 3 4] [1 2 3 5]
[4]

Notice that the above result does not contain 5, as was the case with difference in the prior section.

probe exclude [Bill Bob Bart] [Bob Ted Fred]
[Bill Bart]
probe exclude "abcde" "ace"
"bd"


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