2

The condition for b here doesn't recognize a. How can I fix this?

f[a_Integer, b_Integer /; Divisible[a, b]] := a/b
f[6,2]
(* f[6,2] *)
a = 4;
f[6,2]
(* 3 *)
H.v.M.
  • 1,093
  • 5
  • 12

1 Answers1

3

@user5601 and your analysis explain the problem and the solution

g[a_Integer, b_Integer] /; Divisible[a, b] := a/b
g[6, 2]
(* 3 *)

You attached the condition to the pattern b_Integer so you were testing against the global a not the local a.

(In my version) Mathematica highlights b in your original condition, but not a, so this points to the problem.

mikado
  • 16,741
  • 2
  • 20
  • 54