Forum archive 2000-2006

Michael Gage - PG language basics

Michael Gage - PG language basics

by Arnold Pizer -
Number of replies: 0
inactiveTopicPG language basics topic started 5/3/2000; 10:41:49 PM
last post 5/3/2000; 10:41:49 PM
userMichael Gage - PG language basics  blueArrow
5/3/2000; 10:41:49 PM (reads: 2934, responses: 0)

'Hello World' program

To obtain the problem:

Complete the sentence:


you would type the following:



TEXT( "Complete the sentence: $PAR", ANS_RULE(1,20), "world!" );

ANS( str_cmp( "Hello" ) );

To test or modify this problem click here.


The basic structure of a problem written in the pg language is very simple:
  1. The loadMacros(...) statement loads the files containing the macros which implement the pg language.
  2. The subroutine DOCUMENT() does setup procedures.
  3. TEXT(...,...,...,) concatenates its inputs and prints them. This is the text of the problem.
  4. ANS(...) This specifies how to check whether the answer is correct.
  5. The subroutine ENDDOCUMENT() finishes the problem.


The subroutine ANS_RULE(1,20) creates space for the first answer, 20 characters long.

The variable $PAR indicates a new paragraph -- <P> for HTML or par for TeX output

The subroutine str_cmp("Hello") checks that the answer matches "Hello". The match is case-insensitive.

Because we are writing a Perl script each statement must end in a semi-colon.

The WeBWorK scripts add the necessary HTML code for the "Submit Answer" button; and a header and footer which place the output inside a FORM.


<| Post or View Comments |>