WeBWorK Problems



by Kenneth Appel -
Number of replies: 2
I thought that I had understood how to use unionTables, but seem to be
wrong. What I have here seems essentially the same as something that worked
in another problem, but either I have misunderstood where I can use the
tables or I have made one of my (sad to say) usual errors.

Here is the code
##Type of

#for currency use context("Currency") then currency($A);
$showPartialCorrectAnswers = 1;





For each of the following relation tables answer T if the relation is a function
and F if it is not.
AlignedRow ( [, 1, $a1, , 1, $b4, ,1, $c1, ,1 ,$d1],separation=>30,align=>"ri
AlignedRow ( [, 2, $a2, , 2, $b2, ,2, $c2, ,2 ,$d2],separation=>30,align=>"ri
AlignedRow ( [, 3, $a3, , 3, $b3, ,2, $c3, ,1 ,$d2],separation=>30,align=>"ri
AlignedRow ( [, 4, $a4, , 4, $b1, ,4, $c4, ,3 ,$d2],separation=>30,align=>"ri
AlignedRow([, ans_rule(2), , ans_rule(2),, ans_rule(2),,
EndTable() \}




The display looks like this;

For each of the following relation tables answer T if the relation is a function and F if it is not.


BeginTable(). AlignedRow ( [, 1, 1.9, , 1, 4.9, ,1, 1.1, ,1 ,1.7],separation=>30,align=>"right"). AlignedRow ( [, 2, 2.6, , 2, 2.7, ,2, 2.6, ,2 ,2.3],separation=>30,align=>"right"). AlignedRow ( [, 3, 3, , 3, 2.7, ,2, 3.2, ,1 ,2.3],separation=>30,align=>"right"). AlignedRow ( [, 4, 4.8, , 4, 1.7, ,4, 4.8, ,3 ,2.3],separation=>30,align=>"right"). AlignedRow([, ans_rule(2), , ans_rule(2),, ans_rule(2),, ans_rule(2)],align=>"right") . EndTable()



In reply to Kenneth Appel

Re: unionTables

by Davide Cervone -
The problem is with the blank entries in the row arrays. Perl complains about the '[,' since you can't start an array with an empty entry. It also turns out that the empty entries within the array are ignored, so [1,,2,,3] is the same as [1,2,3]. If you really want blank entries, you need to use "" to do it, as in [1,"",2,"",3].

There are also a couple of other mistakes: First, in

the change of context has no effect. MathObjects retain the context in which they were created, so since $ans1 is already a MathObject, it already knows its context.

Second, you should explicitly set the TF context before you create the T/F answers. It turns out that since you have loaded contextTF.pl as the last file, it has set the ontext to TF, but you can't rely on that, as that behavior is not guaranteed for the future (in fact, I'm going to change the context files from setting contexts, so that problem authors would be forced to set a context explicitly.

Finally, you should not load macro files that you don't actually use. For example, you have loaded contextCurrency.pl, which is not used in this problem. While it may make it easier for you to copy and paste from one problem to another, this causes WeBWorK to have to load and process files it doesn't need, and that happens each time the student views the problem or submits an answer. While it is not much for a single instance, if lots of students are submitting lots of answers, it can cause a significant impact on your server.

If you really feel you need to see the other macro files, at least comment them out in the problems that don't use them.


In reply to Davide Cervone

Re: unionTables

by Kenneth Appel -
Thanks again. Things work now. Thanks for the advice on limiting contexts
loaded. I know that I will have to go back through all of the problems I have
written to take care of things like that and every suggestion heips.