## Forum archive 2000-2006

### Michael Gage - Managing answers

by Arnold Pizer -
Number of replies: 0
 Managing answers topic started 5/11/2000; 8:26:59 AMlast post 6/28/2000; 4:33:13 PM
5/11/2000; 8:26:59 AM (reads: 3482, responses: 1)

#### Overview

##### Three aspects of answers need to be coordinated:

3. The response to the answer provided by WeBWorK when the answer is evaluated.

The answer blank and the answer_evaluator are matched by their labels. There is a provision for implicitly generating labels according to the order in which the answer blanks and answer evaluators are entered, but this is not required.

The answer blank and the response to the answer blank always occur in the same order, the order in which the answer blanks are rendered, which is stored in the flag PG_FLAGS{ANSWER_ENTRY_ORDER} which is returned by ENDDOCUMENT().

Every answer blank has a label. When the answer blank is rendered the label is registered in a queue and is also rendered into the HTML form.

Radio buttons and check forms have auxiliary parts (options) which can be printed separately in different parts of the form. Only one of them registers a label. For example: NAMED_ANS_RADIO('answer1'...) will register the label 'answer1' and print a labeled radio button. NAMED_ANS_RADIO_OPTION('answer1',...) ,however,will print a radio button, but will not register a new label.

Keeping the labels unique is the responsibility of the author. No checking is done. The second answer with the same name will overwrite the first.

#### Order of entry

WeBWorK responds to each answer in the order in which the answer blank appears in the form. This is accomplished using the answer label queue.

This coordinates the answer blanks and the order in which the answer responses appear when WeBWorK responds.

The answers are also evaluated in this order, (the order the answer blanks are rendered), although it may be a bit unreliable to try to rely on this order of evaluation. In general I think it is better if answers are independent of each other in order to minimize surprises when an instructor modifies a question.

#### Matching labels

The order in which answer_evaluators are processed depends on the order of entry of the answer blanks, not on the order of entry of the answer_evaluators. (But see implicit labeling below.)

This method allows storing answer_evaluators in any order, which may occasionally be convenient.

#### Implicit labeling

The most common way of entering answer blanks and answer evaluators also depends on the order of entry: Answer blanks without labels and answer_evaluators without labels are stored in the order they are processed on the problem template form and then provided with labels which identify them with each other by the ENDDOCUMENT() subroutine.

These implicitly defined labels all begin with something obscure like AnSwEr... (a prefix which can be set in PG.pl.) Explicitly labeled answer blanks should avoid using this prefix.

All code outside of the PG language sees every answer blank and every answer_evaluator as labeled. These labeled answer blanks and answer_evaluators and the array storing the order in which the answer blanks were rendered, completely determine how the answers will be evaluated. The answer labels themselves are never sorted, and any unique alphanumeric identifiers can be used.

#### Macros

ANS(ans_eval1, ans_eval2,...)

Stores answer evaluators which will be implicitly labeled by ENDDOCUMENT()

NAMED_ANS(label1 => ans_eval1, label2 => ans_eval2, ...)

Stores labeled answer evaluators. Defined in PG.pl

###### Answer rules family ( a single line of text)

ans_rule(length)

Creates an input text field of length characters, generates a number and registers a label (e.g. AnSwEr5).

ANS_RULE(num, length)

Creates an input text field of length characters and registers a label (e.g. AnSwErnum).

NAMED_ANS_RULE(label,length)

Automatically creates an input text field of length characters and registers a label (e.g. label) without adding a prefix.

ans_box(length)

Creates an input text area field of length characters, generates a number and registers a label (e.g. AnSwEr5).

ANS_BOX(num, length)

Creates an input text area field of length characters and registers a label (e.g. AnSwErnum).

NAMED_ANS_BOX(label,length)

Automatically creates an input text area field of length characters and registers a label (e.g. label) without adding a prefix.