Jump to navigation

Class: StatefulScope

Numbas.marking.StatefulScope

new StatefulScope()

A JME scope with marking state attached. The "current" state is a list of feedback items. The scope can also refer to previously computed states by name. The state can be modified by functions as they are called. This should be the base.

Properties:
Name Type Description
state Array.<Numbas.marking.feedback_item>
states Object.<Array.<Numbas.marking.feedback_item>>

Previously computed states.

state_valid Object.<boolean>

Record of whether previously computed states were valid.

state_errors Object.<Error>

The errors that caused states to become invalid, if any.

Source:

Members

parser :Numbas.jme.Parser

Parser to use when compiling expressions.

Type:
Inherited From:
Source:

Methods

addFunction(fn) → {Numbas.jme.funcObj}

Add a JME function to the scope.

Parameters:
Name Type Description
fn Numbas.jme.funcObj

Function to add.

Returns:
Type Description
Numbas.jme.funcObj
  • The function.
Inherited From:
Source:

addRuleset(name, set)

Add a ruleset to the scope.

Parameters:
Name Type Description
name string
set Numbas.jme.rules.Ruleset
Inherited From:
Source:

allConstants() → {Object.<Numbas.jme.token>}

Gather all variables defined in this scope.

Returns:
Type Description
Object.<Numbas.jme.token>

A dictionary of variables.

Inherited From:
Source:

allFunctions() → {Object.<Array.<Numbas.jme.funcObj>>}

Gather all functions defined in this scope.

Returns:
Type Description
Object.<Array.<Numbas.jme.funcObj>>

A dictionary of function definitions: each name maps to a list of @link{Numbas.jme.funcObj}.

Inherited From:
Source:

allRulesets() → {Object.<Numbas.jme.rules.Ruleset>}

Gather all rulesets defined in this scope.

Returns:
Type Description
Object.<Numbas.jme.rules.Ruleset>

A dictionary of rulesets.

Inherited From:
Source:

allVariables() → {Object.<Numbas.jme.token>}

Gather all variables defined in this scope.

Returns:
Type Description
Object.<Numbas.jme.token>

A dictionary of variables.

Inherited From:
Source:

collect(collection) → {object}

Collect together all items from the given collection.

Parameters:
Name Type Description
collection string

The name of the collection. A property of this Scope object, i.e. one of variables, functions, rulesets.

Returns:
Type Description
object

a dictionary of names to values

Inherited From:
Source:

deleteConstant(name)

Mark the given constant name as deleted from the scope.

Parameters:
Name Type Description
name string
Inherited From:
Source:

deleteFunction(name)

Mark the given function name as deleted from the scope.

Parameters:
Name Type Description
name string
Inherited From:
Source:

deleteRuleset(name)

Mark the given ruleset name as deleted from the scope.

Parameters:
Name Type Description
name string
Inherited From:
Source:

deleteVariable(name)

Mark the given variable name as deleted from the scope.

Parameters:
Name Type Description
name string
Inherited From:
Source:

evaluate(expr, variablesopt, noSubstitutionopt) → {Numbas.jme.token}

Evaluate an expression in this scope - equivalent to Numbas.jme.evaluate(expr,this).

Parameters:
Name Type Attributes Description
expr JME
variables Object.<(Numbas.jme.token|object)> <optional>

Dictionary of variables to sub into expression. Values are automatically wrapped up as JME types, so you can pass raw JavaScript values.

noSubstitution boolean <optional>

If true, don't substitute variable values from the scope into the expression.

Returns:
Type Description
Numbas.jme.token
Overrides:
Source:

expandJuxtapositions(tree, options) → {Numbas.jme.tree}

Expand juxtapositions in variable and function names for implicit multiplication or composition.

Parameters:
Name Type Description
tree Numbas.jme.tree
options Numbas.jme.expand_juxtapositions_options
Returns:
Type Description
Numbas.jme.tree
Inherited From:
Source:

flatten()

Gather all members of this scope into this scope object. A backwards-compatibility hack for questions that use question.scope.variables.x Shouldn't be applied to any scope other than the question scope.

Inherited From:
Source:

getConstant(name) → {Numbas.jme.token}

Find the value of the variable with the given name, if it's defined.

Parameters:
Name Type Description
name string
Returns:
Type Description
Numbas.jme.token
Inherited From:
Source:

getFunction(name) → {Array.<Numbas.jme.funcObj>}

Get all definitions of the given function name.

Parameters:
Name Type Description
name string
Returns:
Type Description
Array.<Numbas.jme.funcObj>

A list of all definitions of the given name.

Inherited From:
Source:

getRuleset(name) → {Numbas.jme.rules.Ruleset}

Get the ruleset with the gien name.

Parameters:
Name Type Description
name string
Returns:
Type Description
Numbas.jme.rules.Ruleset
Inherited From:
Source:

getVariable(name) → {Numbas.jme.token}

Find the value of the variable with the given name, if it's defined.

Parameters:
Name Type Description
name string
Returns:
Type Description
Numbas.jme.token
Inherited From:
Source:

isConstant(value) → {object}

If the given value is equal to one of the constant defined in this scope, return the constant.

Parameters:
Name Type Description
value Numbas.jme.token
Returns:
Type Description
object
Inherited From:
Source:

matchFunctionToArguments(tok, args) → {Numbas.jme.call_signature}

Get the definition of the function with the given name which matches the types of the given arguments.

Parameters:
Name Type Description
tok Numbas.jme.token

The token of the function or operator.

args Array.<Numbas.jme.token>
Returns:
Type Description
Numbas.jme.call_signature
Inherited From:
Source:

resolve(collection, name) → {object}

Get the object with given name from the given collection.

Parameters:
Name Type Description
collection string

The name of the collection. A property of this Scope object, i.e. one of constants, variables, functions, rulesets.

name string

The name of the object to retrieve.

Returns:
Type Description
object
Inherited From:
Source:

setConstant(name, data)

Set the given constant name.

Parameters:
Name Type Description
name string
data Numbas.jme.constant_definition
Inherited From:
Source:

setRuleset(name, rules)

Set the given ruleset name.

Parameters:
Name Type Description
name string
rules Array.<Numbas.jme.rules.Ruleset>
Inherited From:
Source:

setVariable(name, value)

Set the given variable name.

Parameters:
Name Type Description
name string
value Numbas.jme.token
Inherited From:
Source:

unset(defs) → {Numbas.jme.Scope}

Return a new scope created by unsetting the members specified by the given object.

Parameters:
Name Type Description
defs object

A dictionary with elements variables, rulesets and functions, each lists of names to unset.

Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source: