str_rel{s:str, sep:str, r{seq:int, ss:str}}
A relation generator.
Can convert string s into substrings (ss) and vice-versa.
If sep is provided it is used to split the string (or join the substrings) otherwise no separator is used and the string is split (or joined) by character.
If sep is "\N", where N is an integer, the splits are in groups of N characters.
If sep is "\b", the splits/joins are byte-based.
{seq:int} is used to sequence the substrings.
Examples
split into characters
str_rel(s:="hello world")
| sep | r |
| | seq | ss |
|---|
| 0 | h | | 1 | e | | 2 | l | | 3 | l | | 4 | o | | 5 | | | 6 | w | | 7 | o | | 8 | r | | 9 | l | | 10 | d |
|
str_rel has taken the str s and converted it into a nested relation, r
(hence the name: str_rel)
find the position(s) of the space characters
str_rel(s:="this has spaces")..r[ss=" "]
join words
str_rel(r:={seq:int,ss:str}{[0,"hello"],[1,"world"],}, sep:=" ")
bulk apply via composition to get reversed CITY
$S{*, s:=CITY}(str_rel){*, r:=r{*, seq:=-seq}}(str_rel){*, YTIC:=s}
| SNO | SNAME | STATUS | YTIC |
| S1 | Smith | 20 | nodnoL |
| S2 | Jones | 10 | siraP |
| S3 | Blake | 30 | siraP |
| S4 | Clark | 20 | nodnoL |
| S5 | Adams | 30 | snehtA |
Note: since the second str_rel builds left to right, from smallest seq to largest, we can reverse the strings by inverting the seq provided by the first str_rel using seq:=-seq.
To see how this works here's the intermediate relation, after the first composition:
$S{*, s:=CITY}(str_rel)
| SNO | SNAME | STATUS | sep | r |
| S1 | Smith | 20 | | |
| S2 | Jones | 10 | | |
| S3 | Blake | 30 | | |
| S4 | Clark | 20 | | |
| S5 | Adams | 30 | | |