# Defining Multiple Variables with the Same Value

I know we have

a := 1
b := 1


but is there some 1-liner shorthand, akin to:

a, b := 1 (* I know this doesn't work, but I'm just using it as an example *)


?

• It works for = which is what is enough for 1 anyway. Or do you insist on SetDelayed? – Kuba Jun 10 at 20:23
• You can try a=b=1 – bill s Jun 10 at 20:37
• Is there a way to make this work with lazy evaluation (i.e., :=)? – George Jun 10 at 20:38
• @George The := assignment is delayed, not lazy. For lazy you need memoization as well. – Roman Jun 10 at 21:32
• @Kuba and @"bill s" seem to have the answer and should post? – Mark R Jun 11 at 7:42

You can define a function that does what you want:

SetAttributes[DotEqual, HoldAll]
DotEqual[a__, v_] := With[
Replace[rhs, Hold[x_] :> ({a} := x)];
]


Then:

Clear[a, b];
x := Print;
DotEqual[a, b, x]


This produces the desired OwnValues with no evaluation leaks:

OwnValues[a]
OwnValues[b]


{HoldPattern[a] :> x}

{HoldPattern[b] :> x}

The reason I chose DotEqual as the function name is that it already has an infix notation (entered by using Esc . =). So:

Clear[a, b];
x := Print;
a ≐ b ≐ x


Check:

OwnValues[a]
OwnValues[b]


{HoldPattern[a] :> x}

{HoldPattern[b] :> x}