PREP 2014 Question Authoring - Archived

Interpreting ->

Interpreting ->

by Susanna Epp -
Number of replies: 1
When we see := we say "is defined as" to ourselves. What should we say to ourselves when we see -> in WeBWork code? Does the answer to this question depend on the context in which -> appears?
In reply to Susanna Epp

Re: Interpreting ->

by Davide Cervone -
The -> operator is perl's method of de-referencing an object reference. It is used to access an objects methods or properties (methods are the code associated with an object, and its properties are its data). So
    $ans->cmp;
Means the call the cup method of the $ans object, and $ans->{test_points} means the data stored as test_points for $ans. I don't know a good word to replace ->, but you can think of it as a possessive, so the first example can be read "$ans's cmp", and the second as "$ans's test_points".

The use of -> does not depend on the context. It is part of perl itself, not MathObejcts. But because MathObjects are instances of perl Objects, you do use -> with them.