You can do it the way you did it, and you can open the debugger by inserting the self halt instruction in your code.
Usually if s, as well as case-sytle if s, are a bad sign. So what you can do is break the functionality into classes such as DownMove , LeftMove , etc., and then each class will implement its own functions when you call, for example, the execute: method, which will do exactly that, what a team needs. But in your case, the approach will be cumbersome; in addition, you have very trivial actions.
You can use a dictionary with definitions. So imagine you are defining an instance variable or a class variable:
moveActions := { 'down' -> [ :dist | turtle down: dist ] . 'left' -> [ :dist | turtle left: dist ] . ... } asDictionary
Then in your code you do: (moveActions at: bo) value: valInt . This snippet will give you a block (value) for a string (key), then you evaluate a block with an integer.
On the other hand, since the action template is the same and only the message is changed, you can only display message names in the dictionary:
moveActions := { 'down' ->
Then you can ask your turtle to execute the dynamic message given by the line:
`turtle perform: (moveActions at: bo) with: valInt`
In addition, if you want to rely on the similarities between the commands you read and the messages you send to the turtle, you can dynamically compose a message line:
`turtle perform: (bo, ':') asSymbol with: valInt`
Please note that this is not recommended in your case, because, firstly, you bind user input and your code, that is, if you decide to change the user command down to moveDown, you will have to change your method name from down: to moveDown: . In addition, this approach allows the user to "inject" bad code into your system, as he can write a command such as become 42 , which will lead to the code:
`turtle perform:
which changes pointers between the tortoise object and 42. Or you can think of even worse cases. But I hope this meta tour was good for you. :)