This is a split from discussion on earlier question.
Suppose I need to define a function f which checks if given labeling of a graph is a proper coloring. In other words
There are a couple other solutions to this kind of problem which don't require you to use Hold
or ReleaseHold
, but instead rely on the fact that Function
already has the HoldAll
attribute. You first locally "erase" the definitions of Part
using Block
, so the expression you're interested in can be safely constructed, and then uses With
to interpolate that into a Function
which can then be safely returned outside of the Block
, and also uses the fact that Slot
doesn't really mean anything outside of Function
.
Using your example:
coloringChecker[edges_List] :=
Block[{Part},
With[{body = And @@ Table[#[[First@edge]] != #[[Last@edge]], {edge, edges}]},
body &]]
I don't know if this is all that much less cumbersome than using Hold
, but it is different.