relpipe-data/examples-awk-boolean-logic.xml
author František Kučera <franta-hg@frantovo.cz>
Tue, 28 May 2019 21:18:20 +0200
branchv_0
changeset 258 2868d772c27e
permissions -rw-r--r--
Release v0.12 – AWK

<stránka
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
	
	<nadpis>Using boolean logic with AWK</nadpis>
	<perex>boolean data type and logical AND, OR, XOR operators</perex>
	<m:pořadí-příkladu>02500</m:pořadí-příkladu>

	<text xmlns="http://www.w3.org/1999/xhtml">

		<p>Expect that we have a relation with four combinations of logical values:</p>
		
		<pre><![CDATA[logic:
╭─────────────┬─────────────╮
│ a (boolean) │ b (boolean) │
├─────────────┼─────────────┤
│        true │        true │
│        true │       false │
│       false │        true │
│       false │       false │
╰─────────────┴─────────────╯
Record count: 4]]></pre>

		<p>
			we can use logical operators and functions:
		</p>

		
		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli \
	generate logic 2 \
		a boolean \
		b boolean \
		true  true \
		true  false \
		false true \
		false false \
	| relpipe-tr-awk \
		--relation '.*' \
			--output-attribute AND boolean \
			--output-attribute OR  boolean \
			--output-attribute XOR boolean \
			--input-attributes-prepend \
			--for-each '{ AND = a && b; OR = a || b; XOR = xor(a,b); record(); }' \
	| relpipe-out-tabular]]></m:pre>
	
		<p>and append their results to the relation as additional attributes:</p>
	
		<pre><![CDATA[logic:
 ╭─────────────┬─────────────┬───────────────┬──────────────┬───────────────╮
 │ a (boolean) │ b (boolean) │ AND (boolean) │ OR (boolean) │ XOR (boolean) │
 ├─────────────┼─────────────┼───────────────┼──────────────┼───────────────┤
 │        true │        true │          true │         true │         false │
 │        true │       false │         false │         true │          true │
 │       false │        true │         false │         true │          true │
 │       false │       false │         false │        false │         false │
 ╰─────────────┴─────────────┴───────────────┴──────────────┴───────────────╯
Record count: 4]]></pre>
		
	</text>
	
</stránka>