I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me.
DeleteCases[{{0, 0, 0, 0, 0, 0, x, 1, -1}, {0, 0, 0, 1, 0, 0, x,
1, -1}}, _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) &]
I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me.
DeleteCases[{{0, 0, 0, 0, 0, 0, x, 1, -1}, {0, 0, 0, 1, 0, 0, x,
1, -1}}, _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) &]
As mentioned in the comments, it's a matter of precedence. When you're not sure about the precedence, just click n times on the code, and the code piece will be selected outwards according to the precedence:
As shown in the GIF above, after clicking on & 3 times, _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) & is selected i.e. the whole _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) has been included in the Function, which is undesired.
Alternatively, you can check the FullForm. It's not that handy, but still a good choice if you're not yet familiar with the real meaning of _, ?, &, etc.
_?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0} &) // FullForm
(*
PatternTest[Blank[],Function[Equal[Part[Slot[1],Span[1,6]],List[0,0,0,0,0,0]]]]
*)
_?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) & // FullForm
(*
Function[PatternTest[Blank[],Equal[Part[Slot[1],Span[1,6]],List[0,0,0,0,0,0]]]]
*)
Head[(_?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) &)]isFunctionnotPattern. Use this instead:x_ /; (x[[1 ;; 6]] == {0, 0, 0, 0, 0, 0})– flinty Jun 13 '21 at 17:02_?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0} &)– Michael E2 Jun 13 '21 at 17:04?and&. The code in the question is equivalent to( _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) ) &. In general_? body &is equivalent to(_? body) &. You need_?(body &). – Michael E2 Jun 13 '21 at 17:13