Poor Documentation - How Could You Do this to Us K&R?
Exercise 4-3. Given the basic framework, it's straightforward to extend the calculator. Add the modulus (%) and unary minus operators. Add an "erase" command which erases the top entry on the stack. Add commands for handling variables. (Twenty-six single-letter variable names is easy.)
Really? How about some examples that tell us what to expect for us to parse? Chatting with GPT, I get
variable assignment : <value> <variable> :=
And for unary minus: <value> u-
So, essentially, we have new operators. How are we supposed to know what to expect? What will getop send us - given that we're to expect a single character?
That's one thing. Now, given that 'c' is a command that tells you to do something, how are you supposed to deal with a variable named c, which they claim is easy?
Actually, looks like it's a hack by Dr. Chuck. The actual textbook has the getop discussed before the exercise, which makes things easier to understand..
Comments
Post a Comment