Re: [Pharo-users] can I write this without the three if then;s
I would probably set up an array of associations whose keys are the boundary limits and whose values are the target values (ordered, in this example, from outer to inner). Then loop over the array's associations using inject:into:, testing for the point where (each < key), at which point you return the previous association's value. -t -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Doing it the way I describe above eliminates repetitive if-then statements ('switch' or 'case' statements in other languages, which make for a maintenance mess), automatically extends for additional rings, doesn't embed "magic numbers" for defined rings within the decision logic, and takes advantage of the naturally recursive nature of this kind of graduated comparison test. -t -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
You could also accomplish this with a simple 'do:' construct by creating the associations with the the ring limits & points "staggered" (by one level), so that when (each < key) you can return the 'current' association value... Which, now that I'm looking closely at your solution, Kasper, seems to be what you already proposed... Either should work. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (1)
-
tbrunz