- comments begin with
#
- on their own lines,
- or at the end of a line of code
- all "lines" of code end with
;
- one line of code can be spread across multiple newlines
- blocks of code
{}
from conditionals (if
) or loops (for
orwhile
) don't require semicolon after the close brace
- variables
$variableName
- start with
$
- use them to hold
- numbers
$var1 = 1;
- strings (text)
$var2 = 'Hello world!';
- strings with single-quotes are 'literal' -- no variable substitution
- strings with double-quotes will replace variables with their respective values
- numbers
- start with
$variables
are scalar - single-valued- that value might be a reference to a more complex data structure
- arrays are ordered lists:
@arrayVariable = (1,2,3);
- scalars from array:
$arrayVariable[0] + $arrayVariable[2] == 4
would betrue
- scalars from array:
- hashes are key-value pairs:
- assign key-value pairs:
%hashVariable = (key => 'value');
- scalar from hash:
$hashVariable{key} == 'value';
would betrue
- assign key-value pairs:
- caveats for arrays and hashes: they can be defined as scalars, in which case, the method for accessing their values changes slightly.
- technically, my recommendations above are more accurately classified as 'lists' rather than 'arrays' or 'hashes' (don't @ me).
- For the adventurous: Learn Perl in about 2 hours 30 minutes
- WeBWorK has never stopped evolving (~25 years of unceasing growth!)
- The OPL reflects the state of problem development from an increasingly outdated model
- OPL problems DO implement best practices for tagging/metadata
- Editing existing library problems is a good start, but be aware of these limitations
- Major steps in evolution:
- MathObjects / Contexts
- PGML
- Basic framework for building problems:
- Tagging/metadata (comments at the start of the file)
- Problem setup (combination of perl and MathObjects)
- Problem text, and optional hints/solutions (in PGML)
- bread and butter:
$parameter = random(0,9,1);
- random(min, max, [step=1]);
- set your bounds for the randomization
- "step" is optional, and defaults to 1
- possible results:
min, min+step, min+2*step, ...
- if max - min is not a multiple of step, then max is not a possible result of the randomization
- e.g.
random(0,1.5,0.2)
will never result in 1.5
- alternatively, there is
list_random(2,3,5,7,11,13)
which randomly selects from a given list
- Reference
- "sophisticated" variables
- they have methods and properties
- methods are functions (actions)
- properties are static (configurations)
- they have methods and properties
- they know things about themselves
- how their representation might be "reduced" (simplified)
- actions such as variable substitution/evaluation or their derivative with respect to a given variable
- their representation in TeX
- how their comparison should be evaluated (answer checker)
- Reference
- settings for the MathObjects in their 'scope' (you may use multiple contexts when building a problem)
- variables, their type and domain
x => [Real, limits=>[0,2]]
- reduction rules-- things like:
- '1*x+(-1)*y' reduces to
x-y
- '(-x)+y' reduces to
y-x
- '(-x)-y' reduces to
-(x+y)
- '1*x+(-1)*y' reduces to
- constants (pi or e)
- strings (NONE or DNE)
- options (aka 'flags')
- reduceConstants (display
3/4
or0.75
?) - reduceConstantFunctions (display
\sin(\pi)
or0
?)
- reduceConstants (display
- functions / operations (enable/disable)
- variables, their type and domain
- context controls the 'default' answer-checking settings
- tolerance
- acceptable operators and/or functions
- context determines the available MathObject classes
- Reference
- String -- can be implemented in (almost?) any context
- List -- can be constructed from any MathObjects already implemented in your problem
- Numeric
- Real
- Formula
- LimitedNumeric (Real numbers, but with operations & functions disabled)
- e.g.
1
is okay, butsqrt(1)
andcos(0)
are not
- e.g.
- Complex
- Point (dimension depends on number of variables set in context)
- Vector (dimension depends on number of variables set in context)
- Matrix
- Interval
- Set
- Union
- Reference
- Fraction
- Limited:
- LimitedPolynomial
- LimitedComplex
- LimitedPowers
- etc...
- modify existing contexts with your own configuration settings
- Reference
- Assignment (x = ...)
- FormulaUpToConstant: f(x) + C (or almost any letter for C)
- Implicit Equation (implicit plane for linear)
- PopUp & RadioButtons (for multiple choice)
- Reference
- BEGIN_PGML / END_PGML
- won't execute code in this block (without
[@...@]
)
- won't execute code in this block (without
- mostly-standard markdown
- bold
- italics
- numbered lists
- indent / newline
- variable references
[$var]
- TeX math-mode
- inline:
[`\frac{1}{2}`]
- display-style inline:
[``\frac{1}{2}``]
- display-style (double-dollar):
[```\frac{1}{2}```]
- MathObjects know how to TeX themselves:
[`[$formula]`]
- inline:
- executing code
[@code@]
- embedding more complex objects -
[stuff]*
,[stuff]**
, or[stuff]***
- this is for situations where you are generating HTML or PGML in bracketed code?
- as Mike says, just keep adding asterisks until it works ;P
- answer blanks:
[_]{$answerVariable}
- this is a DEEP rabbit hole
- providing an answer as a MathObject makes this "just work"
$showPartialCorrectAnswers = 1;
(or0
) gives students individual feedback on each answer blank- must be set anywhere outside of PGML blocks
- itemized correct/incorrect
- itemized feedback
- partial credit
- Answer-checker options [_]{$answerObject->cmp(...options)}
- BEGIN_PGML_HINT / END
- $showHint = number; (how many attempts before hints are shown?)
- as with showPartialCorrectAnswers, must be set outside of PGML blocks
- BEGIN_PGML_SOLUTION / END
- appears to student after the 'solutions date'