Can we make a faster Boole implementation?
The problem is the automatic module variable renaming that happens with With
. You can use TracePrint
to see this:
TracePrint[boole[list], _With]
With[{True\$=1,False\$=0},{True,True,False,True,False}]
{True, True, False, True, False}
One idea to circumvent this renaming is to use a pure function:
Clear[boole]
boole = Function[Developer`ToPackedArray @ With[{True = 1, False = 0}, #]];
Then:
boole[list]
{1, 1, 0, 1, 0}
See Using With to scope over pure functions, then try:
boole[list_] := With @@ Hold[{True = 1, False = 0}, list] // Developer`ToPackedArray