Programming Phoenix LiveView B4.0: variable name mismatch in code listing (page 305)

On page 303, the struct Pento.Game.Shape was defined as defstruct color: :blue, shape: :x, points: [] but the code listing on page 305 calls it as %__MODULE__{points: points, color: color(name), name: name}.

Based on the IEx output just below the listing, I believe that the call should be adjusted to %__MODULE__{points: points, color: color(name), shape: name}, or maybe even better, all instances of the variable name should be replaced to shape in the constructor, for the sake of consistency.

(By the way, is there a reason that I might discover later why the struct is initialized with default values rather than as a defstruct [:color, :points, :shape]?)

Thanks for pointing this out @Cellane! The correct attribute for the shape struct is :name, and not :shape. You’ll find that fixed in the next Beta release :slight_smile:

The default values don’t serve a very significant purpose in the code–they’re more there to show the reader right away what kind of values you will be working with for each attribute.

1 Like

Thank you, understood!