relpipe-data/examples-guile-filtering.xml
author František Kučera <franta-hg@frantovo.cz>
Mon, 21 Feb 2022 00:43:11 +0100
branchv_0
changeset 329 5bc2bb8b7946
parent 316 d7ae02390fac
permissions -rw-r--r--
Release v0.18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
<stránka
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
	
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
     5
	<nadpis>Complex filtering with Scheme</nadpis>
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
	<perex>filtering records with AND, OR and functions</perex>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	<m:pořadí-příkladu>01400</m:pořadí-příkladu>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
			For simple filtering, we can use <code>relpipe-tr-grep</code>.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
			But what if we need to write some complex query that contains AND and OR operators?
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
			What if we need e.g. compare numbers – not only match texts against regular expressions?
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    15
			There is a tool capable to do this and much more: <code>relpipe-tr-scheme</code>!
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
			<a href="https://www.gnu.org/software/guile/">Guile</a> is the GNU implementation of Scheme language (something like Lisp and also full of parenthesis).
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    20
			The <code>relpipe-tr-scheme</code> reference implementation uses GNU Guile as a library, puts data in the Scheme context and evaluates Scheme expressions and then reads data from the Scheme context back and generates relational output from them.
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
			Good news are that it is not necessary to know Lisp/Scheme to use this tool. For the first steps, it can be used just as a query language – like SQL, just a bit Polish.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
		<h2>Filtering numbers</h2>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
			We are looking for „satanistic“ icons in our filesystem – those that have size = 666 bytes.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		
258
2868d772c27e Release v0.12 – AWK
František Kučera <franta-hg@frantovo.cz>
parents: 245
diff changeset
    30
		<m:pre jazyk="bash"><![CDATA[find /usr/share/icons/ -type f -print0 \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	| relpipe-in-filesystem \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    32
	| relpipe-tr-scheme --relation 'files.*' --where '(= $size 666)' \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	| relpipe-out-tabular]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		<p>Well, well… here we are:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		<m:pre jazyk="text"><![CDATA[filesystem:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
 ╭───────────────────────────────────────────────────────────────────────┬───────────────┬────────────────┬────────────────┬────────────────╮
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
 │ path                                                         (string) │ type (string) │ size (integer) │ owner (string) │ group (string) │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
 ├───────────────────────────────────────────────────────────────────────┼───────────────┼────────────────┼────────────────┼────────────────┤
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
 │ /usr/share/icons/elementary-xfce/actions/24/tab-new.png               │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
 │ /usr/share/icons/elementary-xfce/apps/16/clock.png                    │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
 │ /usr/share/icons/elementary-xfce/mimes/22/x-office-spreadsheet.png    │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
 │ /usr/share/icons/Tango/22x22/apps/office-calendar.png                 │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
 │ /usr/share/icons/Tango/16x16/actions/process-stop.png                 │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
 │ /usr/share/icons/breeze/actions/24/align-vertical-center.svg          │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
 │ /usr/share/icons/breeze/devices/22/camera-photo.svg                   │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
 │ /usr/share/icons/oxygen/base/48x48/actions/tab-detach.png             │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
 │ /usr/share/icons/oxygen/base/32x32/actions/insert-horizontal-rule.png │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
 │ /usr/share/icons/breeze-dark/actions/24/align-vertical-center.svg     │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
 │ /usr/share/icons/breeze-dark/devices/22/camera-photo.svg              │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
 │ /usr/share/icons/gnome/22x22/status/weather-overcast.png              │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
 │ /usr/share/icons/gnome/16x16/actions/go-home.png                      │ f             │            666 │ root           │ root           │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
 ╰───────────────────────────────────────────────────────────────────────┴───────────────┴────────────────┴────────────────┴────────────────╯
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
Record count: 13]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    57
		<p>The <code>--relation 'files.*'</code> is a regular expression that says which relations should be processed in Scheme – others are passed through unchanged.</p>
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
			The <code>--where '(= $size 666)'</code> is our condition. 
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
			The Polish<m:podČarou>see <a href="https://en.wikipedia.org/wiki/Polish_notation">Polish notation</a></m:podČarou> thing means that we write <code>= $size 666</code> instead of <code>$size = 666</code>.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
			It seems a bit weird but it makes sense – the <code>=</code> is a function that compares two numbers and returns a boolean value – 
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
			so we just call this function and pass <code>$size</code> and <code>666</code> arguments to it.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
			And because it is a function, there are <code>(</code>parentheses<code>)</code>.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		<p>
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    68
			Relational attributes are mapped to Scheme variables with same name, just prefixed with <code>$</code>.
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
			(we considered <code>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
				<abbr title="Bitcoin">₿</abbr>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
			</code> symbol, but <code>$</code> seems to be still more common on keyboards in 2019)
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    72
			While relational attribute name is an arbitrary string, Scheme variable names have some limitations, thus not all attributes can be mapped – those with spaces and some special characters are currently unsupported (this will be fixed in later versions by some kind of encoding/escaping).
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
			We can also look for 
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
			<code>--where '(&gt; $size 100)'</code> which means „size is greater than 100“
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
			or
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
			<code>--where '(&lt; $size 100)'</code> which means „size is smaller than 100“.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
			The <code>&gt;=</code> and <code>&lt;=</code> also work as expected.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
		<h2>Filtering strings</h2>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
			Scheme is strongly typed language and we have to use proper functions/operators for each type.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
			For strings, it is <code>string=</code> instead of <code>=</code> function:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
		<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
    91
	| relpipe-tr-scheme --relation 'fstab' --where '(string= $type "btrfs")' \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
	| relpipe-out-tabular]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
	
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
		<p>The Btrfs filesystems in our <code>fstab</code>:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
		<m:pre jazyk="text"><![CDATA[fstab:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
 ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬──────────────────┬────────────────┬────────────────╮
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
 │ scheme (string) │ device                      (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
 ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼──────────────────┼────────────────┼────────────────┤
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
 │ UUID            │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home                │ btrfs         │ relatime         │              0 │              2 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
 ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴──────────────────┴────────────────┴────────────────╯
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
Record count: 1]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
			There is also <code>string-prefix?</code> which evaluates whether the first string is a prefix of the second string:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
		<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
   109
	| relpipe-tr-scheme --relation 'fstab' --where '(string-prefix? "/mnt" $mount_point)' \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   110
	| relpipe-out-tabular]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
		<p>So we can find filesystems mounted somewhere under <code>/mnt</code>:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
		<m:pre jazyk="bash"><![CDATA[fstab:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
 ╭─────────────────┬───────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
 │ scheme (string) │ device       (string) │ mount_point (string) │ type (string) │ options                      (string) │ dump (integer) │ pass (integer) │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
 ├─────────────────┼───────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
 │                 │ /dev/sde              │ /mnt/data            │ ext4          │ relatime,user_xattr,errors=remount-ro │              0 │              2 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
 │                 │ /dev/mapper/sdf_crypt │ /mnt/private         │ xfs           │ relatime                              │              0 │              2 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
 ╰─────────────────┴───────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
Record count: 2]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
			There are much more functions – can be found in the <a href="https://www.gnu.org/software/guile/manual/guile.html">Guile documentation</a>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   125
			– like case-insensitive variants (e.g. <code>string-ci=</code>) or regular expression search (<code>string-match</code>).
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   129
		<h2>AND and OR</h2>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   130
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   131
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   132
			Like in SQL, we can join multiple conditions together with logical operators AND and OR.
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
   133
			In Scheme these operators are also functions – they are written in the same <code>(</code>fashion<code>)</code>.
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
			So we can e.g. look for icons that are „satanistic“ or „Orwellian“:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   138
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
		<m:pre jazyk="bash"><![CDATA[find /usr/share/icons/ -type f -print0 \
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
	| relpipe-in-filesystem --file path --file size \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
   142
	| relpipe-tr-scheme --relation 'files.*' --where '(or (= $size 666) (= $size 1984) )' \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
	| relpipe-out-tabular]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   144
	
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   145
		<p>Files with sizes 666 bytes or 1984 bytes:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   147
		<m:pre jazyk="text"><![CDATA[filesystem:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   148
 ╭───────────────────────────────────────────────────────────────────────┬────────────────╮
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   149
 │ path                                                         (string) │ size (integer) │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   150
 ├───────────────────────────────────────────────────────────────────────┼────────────────┤
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   151
 │ /usr/share/icons/elementary-xfce/actions/48/mail-mark-important.png   │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
 │ /usr/share/icons/elementary-xfce/actions/24/tab-new.png               │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   153
 │ /usr/share/icons/elementary-xfce/apps/16/clock.png                    │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   154
 │ /usr/share/icons/elementary-xfce/mimes/22/x-office-spreadsheet.png    │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   155
 │ /usr/share/icons/Humanity-Dark/status/22/krb-no-valid-ticket.svg      │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   156
 │ /usr/share/icons/Tango/22x22/apps/office-calendar.png                 │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   157
 │ /usr/share/icons/Tango/16x16/actions/process-stop.png                 │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
 │ /usr/share/icons/breeze/actions/24/align-vertical-center.svg          │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   159
 │ /usr/share/icons/breeze/devices/22/camera-photo.svg                   │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   160
 │ /usr/share/icons/oxygen/base/48x48/actions/tab-detach.png             │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   161
 │ /usr/share/icons/oxygen/base/32x32/actions/insert-horizontal-rule.png │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   162
 │ /usr/share/icons/Humanity/status/22/krb-no-valid-ticket.svg           │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   163
 │ /usr/share/icons/breeze-dark/actions/24/align-vertical-center.svg     │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   164
 │ /usr/share/icons/breeze-dark/devices/22/camera-photo.svg              │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   165
 │ /usr/share/icons/gnome/48x48/status/user-busy.png                     │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   166
 │ /usr/share/icons/gnome/22x22/status/weather-overcast.png              │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   167
 │ /usr/share/icons/gnome/16x16/actions/go-home.png                      │            666 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   168
 ╰───────────────────────────────────────────────────────────────────────┴────────────────╯
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   169
Record count: 17]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   170
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   171
		<p>Or we can look for icons that are in SVG format and (at the same time) Orwellian:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   172
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   173
		<m:pre jazyk="bash"><![CDATA[find /usr/share/icons/ -type f -print0 \
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   174
	| relpipe-in-filesystem --file path --file size \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 258
diff changeset
   175
	| relpipe-tr-scheme \
245
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   176
		--relation 'files.*' \
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   177
		--where '(and (string-suffix? ".svg" $path) (= $size 1984) )' \
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   178
	| relpipe-out-tabular]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   179
	
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   180
		<p>Which is quite rare and we have only two such icons:</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   181
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   182
		<m:pre jazyk="text"><![CDATA[filesystem:
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   183
 ╭──────────────────────────────────────────────────────────────────┬────────────────╮
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   184
 │ path                                                    (string) │ size (integer) │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   185
 ├──────────────────────────────────────────────────────────────────┼────────────────┤
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   186
 │ /usr/share/icons/Humanity-Dark/status/22/krb-no-valid-ticket.svg │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   187
 │ /usr/share/icons/Humanity/status/22/krb-no-valid-ticket.svg      │           1984 │
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   188
 ╰──────────────────────────────────────────────────────────────────┴────────────────╯
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   189
Record count: 2]]></m:pre>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   190
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   191
		<p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   192
			We can nest ANDs and ORs and other functions as deep as we need and build even very complex queries.
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   193
			Prentheses nesting is fun, isn't it?
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   194
		</p>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   195
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   196
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   197
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   198
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   199
		
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   200
	</text>
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   201
4919c8098008 examples: Complex filtering with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   202
</stránka>