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:

Methods

addFunction(fn)

Add a JME function to the scope.

Parameters:
Name Type Description
fn Numbas.jme.funcObj

function to add

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:

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

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:

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:

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:

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:

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

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.funcObj
Inherited From:
Source:

resolve(collection, name) → {Object}

Get the object with given name from the given collection

Parameters:
Name Type Description
collection String

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

name String

the name of the object to retrieve

Returns:
Type Description
Object
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: