Gannicus
Gannicus

Reputation: 530

Can someone please explain ask and ask-concurrent in layman's term?

I'm really having a hard time grasping this concept. When I use it, it doesn't really seem like it's performing it at the same time.

Upvotes: 1

Views: 380

Answers (1)

Mars
Mars

Reputation: 8854

If you haven't yet, I recommend trying the Ask Concurrent Code Example in the Code Example section of the Models Library. Run it at a slow speed.

As I understand it, ask-concurrent isn't really supposed to run procedures in the turtles simultaneously. The claim in the Programming Guide is that ask-concurrent runs each single command in ask [...] sequentially, one turtle at a time. It differs from ask in that if there are multiple commands within the braces, ask-concurrent will run the first command in one turtle, then run the same command in another turtle, and so on, until it has run that first command in each of the turtles asked. Then it runs the second command in the first turtle chosen, then in the second, and so on. By contrast, ask will run all of the commands within the braces for the first turtle. Then it will run all of the commands for the second turtle, and so on.

So the difference between ask and ask-concurrent only shows up if there is more than one command in the braces, and even then, ask-concurrent still deals with turtles in sequence.

Upvotes: 3

Related Questions