I'm trying to parse a command and an int to make a "turtle" move on a board. I'm a bit overwhelmed, since it's not throwing an exception, and I can't even figure out how to open the debugger without one.
My code:
"only should begin parsing on new line"
endsWithNewLine:= aTurtleProgram endsWith: String cr.
endsWithNewLine ifTrue:[
"splits commands based on new lines"
commands := aTurtleProgram splitOn: String cr.
commands do:[:com |
"should split into command and value for command"
i := com splitOn: ' '.
"command"
bo := ci at: 1.
val := ci at: 2.
"value for command"
valInt := val asInteger.
^ bo = 'down' "attempted switch"
ifTrue: [ turtle down: valInt ]
ifFalse: [
bo = 'left'
ifTrue: [ turtle left: valInt ]
ifFalse: [
bo = 'right'
ifTrue: [ turtle right: valInt ]
ifFalse: [
bo = 'up'
ifTrue: [ turtle up: valInt ]
ifFalse: [ self assert: false ] ] ] ] ].
perform:
needs a symbol as argument. So you can do either(bo, ':') asSymbol
orbo asSymbol asMutator
– Experience