Hi Ryan, thanks for your question!
Pyret encourages you to write functions that produce a single value. The rps function you shared has an if expression (that prints) *and* a print expression at the end. Which one is the "answer" to the function? That's what Pyret's asking by complaining about multiple expressions.
Now, there's nothing wrong with what you're trying to do! It's just that in most of the ways we teach Pyret we don't encourage writing functions like this.
I've described the error at the end of this message in more detail.
But before you read it, I want to make suggestions for slightly rethinking your program:
- Can you think of a way to make your rps use print *just once*, and print both the message about win/lose/tie AND the computer's guess all at once?
- If you can do that, can you write an rps function that doesn't print, but produces a String that has the combined message in it?
- If you've used the Design Recipe in your class that uses Pyret, can you use it to help you accomplish (1) and/or (2)?
I think there's a lot to learn from the idea in #2 in particular!
That said, your question deserves a direct answer as well.
Compare these two
fun print-it-once(thing):
print(thing)
end
fun print-it-twice(thing):
print(thing)
print(thing)
end
The second function reports an error similar to what you saw. Pyret is trying to guide you away from writing this kind of program.
But that doesn't mean it's impossible! We can have two statements in the same function (do "two things") by adding block: at the top of the function:
fun print-it-twice(thing) block:
print(thing)
print(thing)
end
This version we can call and use. We had to add "block:" to tell Pyret “we know what we're doing, let me use multiple statements here!”
Can you apply that idea to your program to make it have the behavior you wanted originally?