Jump to navigation

Namespace: variables

Numbas.jme.variables

Methods

(static) DOMcontentsubvars(element, scope) → {Element}

Substitute variables into a DOM element (works recursively on the element's children).

Ignores iframes and elements with the attribute nosubvars.

Parameters:
Name Type Description
element Element
scope Numbas.jme.Scope
Returns:
Type Description
Element
Source:
See:

(static) DOMsubvars(str, scope, doc) → {Array.<Array.<Node>>}

Substitute variables into the contents of a text node. Substituted values might contain HTML elements, so the return value is a collection of DOM elements, not another string.

Parameters:
Name Type Description
str string

The contents of the text node.

scope Numbas.jme.Scope
doc Document

The document the text node belongs to.

Returns:
Type Description
Array.<Array.<Node>>
  • Array of DOM nodes to replace the string with.
Source:

(static) computeRuleset(name, todo, scope, path) → {Numbas.jme.rules.Ruleset}

Collect together a ruleset, evaluating all its dependencies first.

Parameters:
Name Type Description
name string

The name of the ruleset to evaluate.

todo Object.<Array.<string>>

Dictionary of rulesets still to evaluate.

scope Numbas.jme.Scope
path Array.<string>

Breadcrumbs - Rulesets names currently being evaluated, so we can detect circular dependencies.

Returns:
Type Description
Numbas.jme.rules.Ruleset
Source:

(static) computeVariable(name, todo, scope, path, computeFnopt) → {Numbas.jme.token}

Evaluate a variable, evaluating all its dependencies first.

Parameters:
Name Type Attributes Default Description
name string

The name of the variable to evaluate.

todo Numbas.jme.variables.variable_data_dict

Dictionary of variables still to evaluate.

scope Numbas.jme.Scope
path Array.<string>

Breadcrumbs - Variable names currently being evaluated, so we can detect circular dependencies.

computeFn function <optional>
Numbas.jme.variables.computeVariable

A function to call when a dependency needs to be computed.

Returns:
Type Description
Numbas.jme.token
Source:

(static) makeConstants(definitions, scope) → {Array.<string>}

Add a list of constants to the scope.

Parameters:
Name Type Description
definitions Array.<Numbas.jme.constant_definition>
scope Numbas.jme.Scope
Returns:
Type Description
Array.<string>
  • The names of constants added to the scope.
Source:

(static) makeFunction(def, scope, withEnv) → {Numbas.jme.funcObj}

Make a custom function.

Parameters:
Name Type Description
def Numbas.jme.variables.func_data

Contains definition, name, language, parameters.

scope Numbas.jme.Scope
withEnv object

Dictionary of local variables for javascript functions.

Returns:
Type Description
Numbas.jme.funcObj
Source:

(static) makeFunctions(tmpFunctions, scope, withEnv) → {Object.<Numbas.jme.funcObj>}

Make up custom functions.

Parameters:
Name Type Description
tmpFunctions Array.<Numbas.jme.variables.func_data>
scope Numbas.jme.Scope
withEnv object

Dictionary of local variables for javascript functions.

Returns:
Type Description
Object.<Numbas.jme.funcObj>
Source:
See:

(static) makeJMEFunction(fn, scope) → {function}

Make a new function, whose definition is written in JME.

Parameters:
Name Type Description
fn object

Contains definition and paramNames.

scope Numbas.jme.Scope
Returns:
Type Description
function
  • Function which evaluates arguments and adds them to the scope, then evaluates fn.definition over that scope.
Source:

(static) makeJavascriptFunction(fn, withEnv) → {function}

Make a new function, whose definition is written in JavaScript.

The JavaScript is wrapped with (function(<paramNames>){ and }).

Parameters:
Name Type Description
fn object

Contains definition and paramNames.

withEnv object

Dictionary of local variables for javascript functions.

Returns:
Type Description
function
  • Function which evaluates arguments, unwraps them to JavaScript values, then evalutes the JavaScript function and returns the result, wrapped as a Numbas.jme.token.
Source:

(static) makeRulesets(todo, scope) → {Object.<Numbas.jme.rules.Ruleset>}

Gather together a set of ruleset definitions.

Parameters:
Name Type Description
todo Object.<Array.<string>>

A dictionary mapping ruleset names to definitions.

scope Numbas.jme.Scope

The scope to gather the rulesets in. The rulesets are added to this scope as a side-effect.

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

A dictionary of rulesets.

Source:

(static) makeVariables(todo, scope, condition, computeFn, targets) → {object}

Evaluate dictionary of variables.

Parameters:
Name Type Description
todo Numbas.jme.variables.variable_data_dict

Dictionary of variables mapped to their definitions.

scope Numbas.jme.Scope
condition Numbas.jme.tree

Condition on the values of the variables which must be satisfied.

computeFn function

A function to compute a variable. Default is Numbas.jme.variables.computeVariable.

targets Array.<string>

Variables which must be re-evaluated, even if they're already present in the scope.

Returns:
Type Description
object
  • variables: a dictionary of evaluated variables, and conditionSatisfied: was the condition satisfied?
Source:

(static) remakeVariables(todo, changed_variables, scope, computeFnopt, targets) → {Numbas.jme.Scope}

Remake a dictionary of variables, only re-evaluating variables which depend on the changed_variables. A new scope is created with the values from changed_variables, and then the dependent variables are evaluated in that scope.

Parameters:
Name Type Attributes Description
todo Numbas.jme.variables.variable_data_dict

Dictionary of variables mapped to their definitions.

changed_variables Object.<Numbas.jme.token>

Dictionary of changed variables. These will be added to the scope, and will not be re-evaluated.

scope Numbas.jme.Scope
computeFn function <optional>

A function to compute a variable. Default is Numbas.jme.variables.computeVariable.

targets Array.<string>

Variables which must be re-evaluated, even if they're already present in the scope.

Returns:
Type Description
Numbas.jme.Scope
Source:

(static) splitVariableNames(s) → {Array.<string>}

Split up a list of variable names separated by commas, for destructuring assignment.

Parameters:
Name Type Description
s string
Returns:
Type Description
Array.<string>
Source:

(static) variableDependants(todo, ancestors, scope) → {object}

Given a todo dictionary of variables, return a dictionary with only the variables depending on the given list of variables.

Parameters:
Name Type Description
todo object

Dictionary of variables mapped to their definitions.

ancestors Array.<string>

List of variable names whose dependants we should find.

scope Numbas.jme.Scope

The scope to use for normalising names.

Returns:
Type Description
object
  • A copy of the todo list, only including the dependants of the given variables.
Source:

Type Definitions

func_data

The definition of a custom JME function.

Type:
Properties:
Name Type Description
name string
definition string

Definition of the function, either in JME or JavaScript.

language string

Either "jme" or "javascript".

outtype string

Name of the Numbas.jme.token type this function returns.

parameters Array.<object>

Definition of the function's calling signature: an array of objects with properties name and type for each of the function's parameters.

Source:

note_definition

A definition of a note.

The note's name, followed by an optional description enclosed in parentheses, then a colon, and finally a JME expression to evaluate.

Type:
Source:

variable_data_dict

A dictionary describing a variable to be evaluated.

Type:
Properties:
Name Type Description
tree Numbas.jme.tree

Definition of the variable.

vars Array.<string>

Names of variables this variable depends on.

Source: