Skip to content

Commit

Permalink
Merge pull request #24 from eliascarv/gencolumns
Browse files Browse the repository at this point in the history
Add `gencolumns` function
  • Loading branch information
eliascarv authored Feb 4, 2023
2 parents f909fe3 + bf03ac1 commit d499a70
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ function _truthtable(expr::Expr, full::Bool)
preprocess!(expr)

colnames = propnames(expr)
n = length(colnames)
rows = Iterators.product(fill([true, false], n)...)
columns = Vector{Bool}[vec([row[i] for row in rows]) for i in n:-1:1]
columns = gencolumns(length(colnames))
colexprs = Expr[]

if full
Expand Down
7 changes: 7 additions & 0 deletions src/macroutils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
function gencolumns(n::Integer)
bools = [true, false]
outers = [2^x for x in 0:n-1]
inners = reverse(outers)
[repeat(bools; inner, outer) for (inner, outer) in zip(inners, outers)]
end

const OPRS = (
:&, :,
:|, :,
Expand Down

0 comments on commit d499a70

Please sign in to comment.