From: jj v. a. <we...@ma...> - 2005-10-11 18:01:10
|
Log Message: ----------- Added syntactic sugar for pop_up_lists. A common situation is that a problem includes a short multiple-choice question along with other answers. Often, these questions are written as fill-in-the-blank where the student is told a list of legal words to put in the blanks. The idea is to make it as simple as possible for problem writers to replace the fill-in-the-blank with a drop-down list of alternatives. So, now the text of a problem can contain is the function increasing on [0,1]? \{ pop_up_list(['?', 'yes', 'no']) \} instead of is the function increasing on [0,1]? \{ pop_up_list('?' => '?', 'yes' => 'yes', 'no' => 'no') \} The result is checked with something like ANS(str_cmp('yes')); Existing problems are unaffected since the added syntax uses a reference to a list (the extra square brackets). Modified Files: -------------- pg/macros: PGbasicmacros.pl Revision Data ------------- Index: PGbasicmacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGbasicmacros.pl,v retrieving revision 1.42 retrieving revision 1.43 diff -Lmacros/PGbasicmacros.pl -Lmacros/PGbasicmacros.pl -u -r1.42 -r1.43 --- macros/PGbasicmacros.pl +++ macros/PGbasicmacros.pl @@ -185,7 +185,12 @@ ans_rule( width ) tex_ans_rule( width ) ans_radio_buttons(value1=>label1, value2,label2 => value3,label3=>...) - pop_up_list(@list) # list consists of (value => label, PR => "Product rule",...) + pop_up_list(@list) # list consists of (value => label, PR => "Product rule",...) + pop_up_list([@list]) # list consists of values + +In the last case, one can use C<pop_up_list(['?', 'yes', 'no'])> to produce a +pop-up list containing the three strings listed, and then use str_cmp to check +the answer. To indicate the checked position of radio buttons put a '%' in front of the value: C<ans_radio_buttons(1, 'Yes','%2','No')> will have 'No' checked. C<tex_ans_rule> works inside math equations in C<HTML_tth> mode. It does not work in C<Latex2HTML> mode @@ -212,6 +217,7 @@ NAMED_ANS_RADIO_BUTTONS(name,value1,label1,value2,label2,...) check_box('-name' =>answer5,'-value' =>'statement3','-label' =>'I loved this course!' ) NAMED_POP_UP_LIST($name, @list) # list consists of (value => tag, PR => "Product rule",...) + NAMED_POP_UP_LIST($name, [@list]) # list consists of a list of values (and each tag will be set to the corresponding value) (Name is the name of the variable, value is the value given to the variable when this option is selected, and label is the text printed next to the button or check box. Check box variables can have multiple values.) @@ -733,6 +739,10 @@ sub NAMED_POP_UP_LIST { my $name = shift; my @list = @_; + if(ref($list[0]) eq 'ARRAY') { + my @list1 = @{$list[0]}; + @list = map { $_ => $_ } @list1; + } $name = RECORD_ANS_NAME($name); # record answer name my $answer_value = ''; $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); |