--- loncom/homework/default_homework.lcpm 2001/07/13 14:49:28 1.30
+++ loncom/homework/default_homework.lcpm 2001/07/19 21:26:22 1.31
@@ -24,11 +24,13 @@ sub caparesponse_check {
my $unit=''; #done
my $calc='';
my ($response,$expr)=@_;
-
+
($answer,$type,$tol,$sig,$ans_fmt,
- $unit,$calc) = eval $expr.';return $answer,$type,$tol,$sig,$ans_fmt,$unit,$calc';
+ $unit,$calc) = eval $expr.';return ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc);';
#type's definitons come from capaParser.h
+ my $message='';
if ($type eq '' ) {
+ $message .= "Didn't find a type :$type:$expr: defaulting
";
if ( $answer eq ($answer *1.0)) { $type = 2;
} else { $type = 3; }
} else {
@@ -77,7 +79,7 @@ sub caparesponse_check {
elsif ($result =='12') { $result='WANTED_NUMERIC'; }
else {$result = "ERROR: Unknown Result:$result:$@:";}
- return "$result:
Error $error:
Answer $answer:
Response $response:
$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$units
";
+ return "$result:
Error $error:
Answer $answer:
Response $response:
type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$units
$message$expr";
}
sub caparesponse_check_list {
@@ -87,26 +89,43 @@ sub caparesponse_check_list {
my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $answer';
my (@list) = eval $CAPARESPONSE_CHECK_LIST_answer;
my $result='';
+ $result.="error:$@:
";
+ # if the eval fails just use what is in the answer exactly
+ if (!defined(@list) || !defined($list[0])) {
+ $result.="list zero is undefined
";
+ $list[0]=$CAPARESPONSE_CHECK_LIST_answer;
+ }
my $aresult='';
my $current_answer;
- my (@responselist)=split /,/,$response;
+ $result.="Got response :$CAPARESPONSE_CHECK_LIST_answer:$list[0]:
";
+ my @responselist;
+ if ($type ne '' && $#list > 0) {
+ (@responselist)=split /,/,$response;
+ } else {
+ (@responselist)=($response);
+ }
my $unit='';
- $result.="Final response :$responselist['-1']:
";
- if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
- $responselist['-1']=$1;
- $unit=$2;
+ $result.="Initial final response :$responselist['-1']:
";
+ if ($type eq '') {
+ #for numerical problems split off the unit
+ if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
+ $responselist['-1']=$1;
+ $unit=$2;
+ }
}
- $result.="Final response :$responselist['-1']:
";
+ $result.="Final final response :$responselist['-1']:
";
+ $result.=":$#list: answers
";
$unit=~s/\s//;
my $i=0;
my $awards='';
for ($i=0; $i<@list;$i++) {
+ $result.="trying answer :$list[$i]:
";
if ($unit eq '') {
$aresult=&caparesponse_check($responselist[$i],
- $expr.';my $answer='.$list[$i].';');
+ $expr.';my $answer=\''.$list[$i].'\';');
} else {
$aresult=&caparesponse_check($responselist[$i]." $unit",
- $expr.';my $answer='.$list[$i].';');
+ $expr.';my $answer=\''.$list[$i].'\';');
}
my ($temp)=split /:/, $aresult;
$awards.="$temp,";