## WeBWorK Problems

### ambiguous unit --- how/need to handle ?

by Dick Lane -
Number of replies: 1
Problem Library/Michigan/Chap2Sec4/Q11.pg involves a relation between diet and weight.  W = f(c) is weight of adult as a function of average Calories per day, c, consumed by the subject.  Most parts of this problem ask about suitable units.  E.g.,

In the statement  f(1800) = 145
what are the units of 1800?  ______
what are the units of 145? ______

It turns out that the first item will accept both  cal  and  cal/day.
I've examined Gavin's code --- although he uses a custom checker, I can not see where the "cal/day" variant is being handled.  Looking further at Units.pm and parserNumberWithUnits.pl has not helped me understand what is going on.

Although I could write a custom checker which accepts either "cal" or "cal/day", I'm puzzled by the seeming lack of need to do so.

thanks

### Re: ambiguous unit --- how/need to handle ?

by Gavin LaRose -
Hi Dick,

It's actually worse than this. I think it's not actually managing to do any meaningful check of units (that is, it appears that whatever one puts in is marked correctâ€”lb, lb/day, etc.). The checker is

ANS(String("cal")->cmp( checker=>sub {
my ( $cor,$student, $ansHash ) = @_; return NumberWithUnits( 1,$cor ) ==
NumberWithUnits( 1, \$student );
} ) );


After some poking, I think the problem is somewhere in the interaction between the NumberWithUnits comparison embedded in a String object. I can construct NumberWithUnits objects in a checker for a NumberWithUnits that do what I expect, but when I start with a String it's not figuring out what's going on correctly.

I'll have to look at this more to get a better understanding of where the problem is creeping in, but it appears to be farther into the internals of MathObjects.

Gavin