No, actually, that's not right. You need to read the problem more
carefully. The solution Brody posts is for the charge calculation. It
does not cover how the various variables are updated for a given call.
The price for weekend/holiday calls is the same as for weekday calls
between 11 PM and 8 AM, "LOWEST". So the comment is basically correct.
I'm not going to fault him for not spelling out the entire problem
again in the comments.
> There is no code here that accepts a time of day and a boolean
> to indicate a weekday and that then selects the proper rate.
That's right because that is being left to the portion of the problem
that deals with noting the nature of a call. That code just selects
FULL, LOWER or LOWEST based on the time and the day of the week, let's
call it "time of the week".
> The source is broken up into so many tiny pieces of code
> that it is hard to understand how they interact and fit
> together. This is a type of spaghetti-coding.
I may not be a newbie, but I am no expert at Forth and I don't have any
trouble understanding what he is doing. BTW, breaking the code down
into bite sized pieces is call "factoring"... that name sounds familiar
somehow...
> Look at this:
>
> 0 CHARGE 1MINUTE \ rate for first minute
> 2 CHARGE +MINUTES \ rate for each additional minute
> 4 CHARGE /MILES \ rate per each 100 miles
>
> What is the significance of the 0? Of the 2? Of the 4?
> Are you telling me that the programmer has to tell the
> compiler the offset in bytes for each integer that he
> is storing? What a damned, pitiful language. What a
> damned, pitiful programmer.
Have you been coding much in Forth? This is not much of a criticism.
The only exception I would take to this is that he should have been
using CELLS or CELLS+ with 0, 1 and 2 rather than specifying the byte
offsets. But then, I don't know when CELLs started being used and I
know Brodie's books are fairly old.
> This language is not designed to make things easy for the
> programmer. It is designed to make things easy for the
> implementor of the language. To hell with the programmer.
Lol! When Forth was created that was the same person!
What are you trying to show here? Obviously I don't know this language,
but I see no reason why this is inherently better or easier.
BTW, your solution has the same "problem" that you complained about in
Brodie's code. The rate depends not only on the time of day and the day
of week, but also on whether it is a holiday! So clearly your weekday?
variable is more than just "is it a weekday?"
--
Rick