Forum archive 2000-2006

Michael Gage - Hello world

Michael Gage - Hello world

by Arnold Pizer -
Number of replies: 0
Hello world topic started 5/7/2000; 1:22:55 PM
last post 9/9/2001; 10:42:39 PM
userMichael Gage - Hello world  blueArrow
5/7/2000; 1:22:55 PM (reads: 2620, responses: 1)

This is not a working version of this problem.
Go here to test a live version of this problem.

To get this problem you would enter the following (without the line numbers)
1       DOCUMENT();
2
3 loadMacros(PG.pl,
4 PGbasicmacros.pl,
5 PGanswermacros.pl,
6 );
7
8 TEXT(beginproblem());
9
10 BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
14 ANS( str_cmp( "Hello" ) );
15
16 ENDDOCUMENT();

1       DOCUMENT();
The subroutine DOCUMENT() must the first line of any pg problem. It does setup procedures and initializes much of the information that will be used later on by WeBWorK to create the problem.
3       loadMacros(PG.pl,
4 PGbasicmacros.pl,
5 PGanswermacros.pl,
6 );
The loadMacros() call loads the specified macro files so that any macros that have been defined within them will be readily available to the professor.

Mandatory modules:

  • PG.pl defines the macros that make up the pg language (such as DOCUMENT(), TEXT(), and ANS).
  • PGbasicmacros.pl defines many of the basic display macros used for displaying answer blanks, radio buttons, check boxes, solutions, hints, regular text, several reserved characters (ones that perl would otherwise interpret incorrectly, such as $DOLLAR returns a $) and basic html tags (such as $PAR for <P>).
  • PGanswermacros.pl defines the different methods for comparing the students answer(s) to the professors answer(s) with the ability to select many options such as case-sensitivity and tolerance.

Optional modules:

  • PGchoicemacros.pl contains methods used to create objects that allow the student to choose their answers (like Matching Lists and Multiple Choice questions).
  • PGgraphmacros.pl provides methods for creating and viewing graphs based on user-provided functions.
  • PGnumericalmacros.pl has pre-defined methods for several numerical calculus methods, such as Hermite splines and the Trapezoid Rule
  • PGauxiliaryFunctions.pl has many trigonometric and arithmetric functions that are not otherwise available in perl (arc functions, rounding functions, gcf, lcm, etc).
  • PG_CAPAmacros.pl contains macros that can help convert CAPA problems to WeBWorK problems.
  • Other Macro files can be and often are created to provide methods not otherwise found in any of the provided macro files.
8       TEXT(beginproblem());
The TEXT command is essentially the print command of the pg language. Everything that is passed to it, concatenated, evaluated, and then printed out.
The beginproblem() method prints some of the opening information that should be printed for each problem, such as how points it is worth and, if the user has permission, the filename of the problem.
10      BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
The BEGIN_TEXT/END_TEXT pair is a replacement for the older EV2 and EV3 tags.
  • Both BEGIN_TEXT and END_TEXT tags must be alone on a line, but everything between them is printed exactly AS IS.
  • TeX (math mode) equations can be added by placing the TeX code between \( ... \) tags.
  • Perl variables can be added to the text directed (such as the above $PAR)
  • but calls to perl methods must be enclosed in \{ ... \} tags (such as the ans_rule(20) call which is a macro from PGbasicmacros.pl that creates an answer blank.)
14      ANS( str_cmp( "Hello" ) );
The ANS subroutine is used to evaluate the students answer by comparing the submitted answer to the one given in the call to ANS. How the answers are compared is determined by which answer evaluator is used (str_cmp("Hello") is one example) all of which are listed in PGanswermacros.pl.
16      ENDDOCUMENT();
The ENDDOCUMENT() finishes up the pg problem and makes sure everything closes out correctly. This must be the last line in your problem (at best anything after this will be ignored, at worst it will cause an error).

Final Notes:

Because we are writing a perl script, each statement must end in a semi-colon. Note however that many statements can be several lines long (such as loadMacros(), lines 2-5), these only require one semi-colon. All of the extra exterior links, buttons, forms, pictures, etc that are common to all problems are generated by the WeBWorK scripts and do not (and cannot) be created within the pg problem itself.


<| Post or View Comments |>


userMichael Gage - Re: Hello world  blueArrow
9/9/2001; 10:42:39 PM (reads: 4440, responses: 0)

Complete the sentence:

world!

 

 


WARNINGS
µ¦å{h­ To get this problem you would enter the following (without the line numbers). (The code has been simplified slightly for pedagogical purposes. )
1       DOCUMENT();
2 loadMacros(
3 PGbasicmacros.pl,
4 PGanswermacros.pl,
5 PGchoicemacros.pl
6 );
7
8 TEXT(beginproblem());
9
10 BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
14 ANS( str_cmp( "Hello" ) );
15
16 ENDDOCUMENT();

1       DOCUMENT();
The subroutine DOCUMENT() must the first line of any pg problem. It does setup procedures and initializes much of the information that will be used later on by WeBWorK to create the problem.
3       loadMacros(
4 PGbasicmacros.pl,
5 PGanswermacros.pl,
6 );
The loadMacros() call loads the specified macro files so that any macros that have been defined within them will be readily available to the professor.

Mandatory modules:

  • PGbasicmacros.pl defines many of the basic display macros used for displaying answer blanks, radio buttons, check boxes, solutions, hints, regular text, several reserved characters (ones that perl would otherwise interpret incorrectly, such as $DOLLAR returns a $) and basic html tags (such as $PAR for <P>).
  • PGanswermacros.pl defines the different methods for comparing the students answer(s) to the professors answer(s) with the ability to select many options such as case-sensitivity and tolerance.

Optional modules:

  • PGchoicemacros.pl contains methods used to create objects that allow the student to choose their answers (like Matching Lists and Multiple Choice questions).
  • PGgraphmacros.pl provides methods for creating and viewing graphs based on user-provided functions.
  • PGnumericalmacros.pl has pre-defined methods for several numerical calculus methods, such as Hermite splines and the Trapezoid Rule
  • PGauxiliaryFunctions.pl has many trigonometric and arithmetric functions that are not otherwise available in perl (arc functions, rounding functions, gcf, lcm, etc).
  • PG_CAPAmacros.pl contains macros that can help convert CAPA problems to WeBWorK problems.
  • Other Macro files can be and often are created to provide methods not otherwise found in any of the provided macro files.
8       TEXT(beginproblem());
The TEXT command is essentially the print command of the pg language. Everything that is passed to it, concatenated, evaluated, and then printed out.
The beginproblem() method prints some of the opening information that should be printed for each problem, such as how points it is worth and, if the user has permission, the filename of the problem.
10      BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
The BEGIN_TEXT/END_TEXT pair is a replacement for the older EV2 and EV3 tags.
  • Both BEGIN_TEXT and END_TEXT tags must be alone on a line, but everything between them is printed exactly AS IS.
  • TeX (math mode) equations can be added by placing the TeX code between \( ... \) tags.
  • Perl variables can be added to the text directed (such as the above $PAR)
  • but calls to perl macros must be enclosed in \{ ... \} tags (such as the ans_rule(20) call which is a macro from PGbasicmacros.pl that creates an answer blank.)
14      ANS( str_cmp( "Hello" ) );
The ANS subroutine stores the answer evaluators used to evaluate the students answer by comparing the submitted answer to the one given by the instructor. How the answers are compared is determined by which answer evaluator is used (str_cmp("Hello") is one example) all of which are listed in PGanswermacros.pl.
16      ENDDOCUMENT();
The ENDDOCUMENT() finishes up the pg problem and makes sure everything closes out correctly. This must be the last line in your problem (at best anything after this will be ignored, at worst it will cause an error).

Final Notes:

Because we are writing a perl script, each statement must end in a semi-colon. Note however that many statements can be several lines long (such as loadMacros(), lines 2-5), these only require one semi-colon. All of the extra exterior links, buttons, forms, pictures, etc that are common to all problems are generated by the WeBWorK scripts and do not (and cannot) be created within the pg problem itself.


<| Post or View Comments |>