README
NAME
Logic::Ternary â Ternary logic for Raku
SYNOPSIS
use Logic::Ternary;
my $t = True;
my $f = False;
my $u = Unknown;
# Negation
dd not3 $t; # Logic::Ternary::False
dd not3 $u; # Logic::Ternary::Unknown
# Conjunction/Disjunction/xor (operands are coerced to Ternary)
dd $t and3 $u; # Logic::Ternary::Unknown
dd $t or3 $u; # Logic::Ternary::True
dd $t xor3 $t; # Logic::Ternary::False
# Coercions
dd 1 .Ternary; # Logic::Ternary::True
dd -3 .Ternary; # Logic::Ternary::False
dd 0 .Ternary; # Logic::Ternary::Unknown
dd Bool::True.Ternary; # Logic::Ternary::True
dd Bool.Ternary; # Logic::Ternary::UnknownDESCRIPTION
Logic::Ternary implements a three-valued logic for Raku:
True(+1),Unknown(0),and
False(-1).
Values are Logic::Ternary::True, Logic::Ternary::Unknown, and Logic::Ternary::False.
Predicates:
.is-true,.is-false,.is-unknown.Negation:
not3 $x.Booleanization:
Bool($x)is true only when$xisTrue.Coercion:
Numeric.Ternarymaps:negativesâ
False,zeroâ
Unknown,positivesâ
True;Bool.TernarypreservesTrue/Falseand yieldsUnknownwhen undefined.
Operators
These operators always coerce both operands with .Ternary:
and3: ternary conjunction.or3: ternary disjunction.xor3: defined as(A or3 B) and3 not3(A and3 B).not3: negation.so3: ternarisation.
Quick examples
use Logic::Ternary;
my $u = Unknown;
# and3 behavior
dd $u and3 True; # Logic::Ternary::Unknown
dd $u and3 False; # Logic::Ternary::False
# or3 behavior
dd True or3 $u; # Logic::Ternary::True
dd $u or3 False; # Logic::Ternary::Unknown
# Mixed types are coerced
dd 1 and3 0; # Logic::Ternary::Unknown
dd -2 or3 1; # Logic::Ternary::True
dd not3 1; # Logic::Ternary::FalseExports
By default, use Logic::Ternary; exports the enum names
True,Unknown,False
and the operators:
not3,and3,or3,xor3,so3.
You can customize which enum names are exported by passing options to the use line:
Single shorthands:
<True>â same as<True Unknown False>.<True3>â exports<True3 Unknown3 False3>.<KnownTrue>â exports<KnownTrue Unknown KnownFalse>.
Custom list: Provide three identifiers:
<Yes Maybe No>.None:
<none>disables exporting the enum names to the lexical scope; operators are still exported. Fully qualified enum values are always available underLogic::Ternary::.
use Logic::Ternary; # True/Unknown/False
use Logic::Ternary <True>; # same as default
use Logic::Ternary <True3>; # True3/Unknown3/False3
use Logic::Ternary <KnownTrue>; # KnownTrue/Unknown/KnownFalse
use Logic::Ternary <Yes Maybe No>; # custom names
use Logic::Ternary <none>; # no constants; operators only
say (not3 1).Int; # -1
say Logic::Ternary::True.raku; # 'Logic::Ternary::True'AUTHOR
Fernando CorrĂȘa de Oliveira [email protected]
COPYRIGHT AND LICENSE
Copyright 2025 Fernando CorrĂȘa de Oliveira
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.