I am working on a simple board game in Pharo, and I have a method on my board that adds objects to a cell. Cells are just a dictionary of points on objects.
As part of the method, I would like to ensure that the point is greater than zero, but less than the width and height of the board, in other words, it should actually be on the board. What is the best way to do this?
My current attempt is as follows:
at: aPoint put: aCell
((((aPoint x > self numberOfRows)
or: [aPoint x <= 0])
or: [aPoint y > self numberOfColumns ])
or: [aPoint y <= 0])
ifTrue: [ self error:'The point must be inside the grid.' ].
self cells at: aPoint put: aCell .
Kind of lisp -y with all these parens! But I can’t use short-circuiting or:without closing every expression, so it is evaluated as a logical, not a block (or as a message or:or:or:or:). I could use a binary operator |instead for a short circuit, but that doesn't seem right.
So what is the correct Smalltalk-ish way to handle this?
source
share