Adding Strings to a Context

Shows how to add strings to the context.

Complete Code

Download file: StringsInContext.pg

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Preamble

These standard macros need to be loaded.
Context()->strings->add(none => {});

# If a case-sensitive string is desired, the following could be used instead.
# Context()->strings->add(none => { caseSensitive => 1 });

Setup

Note that this example is only here to demonstrate how to add strings to a context. However, using strings for this type of problem is not recommended. See Answers with Alternate Forms for a better approach for dealing with this sort of problem.

Add the strings that are to be allowed in answers to the context.

Note that the add call has the form string => { options }. The most common use of options is to allow “aliases”, i.e., strings that are marked the same as others, e.g.,

Context()->strings->add(none => {}, N => { alias => 'none' });

which would allow ‘N’ to be used instead of ‘none’.

By default, strings are case-insensitive. To make them case sensitive, include the option caseSensitive => 1.

There are some shortcuts available if you need to add many allowable strings at once. See parserAutoStrings.pl.

BEGIN_PGML
Enter the positive real value of [`x`] for which [`x^2 = -2`] :

[`x = `] [___]{'none'}

_(Enter *none* if there are no values that satisfy the equation .)_
END_PGML

Statement

It’s usually a good idea to include some indication of what strings are expected or allowed in the answer.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.