Can't get List of strings for an answer to work in PGML problem...
by Christian Seberino - Number of replies: 2Re: Can't get List of strings for an answer to work in PGML problem...
by Davide Cervone -
First, your $strings_1
and $strings_2
are not MathObject strings, they are WeBWorK AnswerEvaluators, since you have set them equal to the results of cmp()
calls (which return AnswerEvaluators). When you try to pass these to List()
, it fails to produce a List object, because you have passed it things that can't be used in a list. It actually produces an error message about this, but PGML traps the error and interprets it to mean that the value in the braces is not a valid Perl command so it uses it as a literal string (as you pointed out).
Second since you are using the ArbitraryString
context, you can't use lists, because the ArbitraryString
context does no parsing of the student's input whatsoever. Since using the comma as a list separator would be parsing the student answer, that isn't done. This really is an arbitrary string. If you want to have the answer broken up as a list, you would need to do that yourself in a custom checker. So you could use
$cmp = Compute("BC,AD")->cmp(checker=>sub { ... (your code here) ... }); BEGIN_PGML [____________]{$cmp} END_PGMLbut the custom checker would be complicated to write.
Alternatively, you might want to use the contextString.pl
context, which allows only string answers, and only the ones your define. Here is one approach:
loadMacros("contextString.pl"); Context("String"); Context()->operators->redefine(',', using=>','); # allow lists of strings Context()->strings->add( "BC" => {caseSensitive=>1}, "CB" => {alias => "BC", caseSensitive=>1}, "AD" => {caseSensitive=>1}, "DA" => {alias => "AD", caseSensitive=>1}, ); BEGIN_PGML [________]{"BC,AD"} END_PGMLOf course, you would need to add whatever other pairs might be entered (I don't have the diagram, so can't tell what they might be). It is possible to add the strings programmatically, for example, to get all pairs of letters from a given list:
loadMacros("contextString.pl","PGML.pl"); Context("String"); Context()->operators->redefine(',', using=>','); # allow lists of strings @letters = ("A","B","C","D"); $n = scalar(@letters); foreach $i (0..$n-2) { foreach $j ($i+1..$n-1) { $AB = $letters[$i].$letters[$j]; $BA = $letters[$j].$letters[$i]; Context()->strings->add( $AB => {caseSensitive => 1}, $BA => {caseSensitive => 1, alias => $AB}, ); } } BEGIN_PGML [________]{"BC,AD"} END_PGML