Title: | Infix and Postfix Logic Operators |
---|---|
Description: | Provides adds postfix and infix logic operators for if, then, unless, and otherwise. |
Authors: | Andrew Redd [aut, cre] (https://orcid.org/000-0002-6149-2438) |
Maintainer: | Andrew Redd <[email protected]> |
License: | GPL-2 |
Version: | 0.1.0.9999 |
Built: | 2025-03-17 03:17:53 UTC |
Source: | https://github.com/rdoctaskforce/postlogic |
This construction allows logical statements to be placed after the value to be returned. Take note that the ' as other custom infix operators and so care should be taken that the effect is as desired.
prior %if% proposition prior %if% proposition %otherwise% alternate
prior %if% proposition prior %if% proposition %otherwise% alternate
prior |
The value to be returned if proposition evaluates to TRUE. |
proposition |
The logical statement to evaluate |
alternate |
The value to be returned if proposition evaluates to FALSE. |
prior %if% proposition |
An |
Other postlogic: unless-then
x <- 1 x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # 2 x <- 1i x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # Hmm this isn't right
x <- 1 x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # 2 x <- 1i x <- (x+1) %if% is.numeric(x) %otherwise% "Hmm this isn't right O.o" x # Hmm this isn't right
These give logic that can be used as a qualifying statement that occurs after the value statement. Take note that the ' as other custom infix operators and so care should be taken that the effect is as desired.
prior %unless% proposition prior %unless% proposition %then% alternate
prior %unless% proposition prior %unless% proposition %then% alternate
prior |
Value to be returned unless proposition returns FALSE. |
proposition |
The logical statement to condition on. |
alternate |
When proposition returns true and the the alternate value is returned. |
prior %unless% proposition |
An |
Other postlogic: if-otherwise
x <- 4 x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # 2 x <- 4i x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # This is too hard :(
x <- 4 x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # 2 x <- 4i x <- sqrt(x) %unless% is.complex(x) %then% "This is too hard :(" x # This is too hard :(