Jump to navigation

Namespace: variables

Numbas.jme.variables

Methods

(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) DOMcontentsubvars(element, scope)

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
Source:
See:

(static) DOMsubvars(str, scope, doc) → {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.<Node>
  • Array of DOM nodes to replace the string with.
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) 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) 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) 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) → {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.

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

(static) remakeVariables(todo, changed_variables, scope) → {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 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.

scope Numbas.jme.Scope
Returns:
Type Description
Numbas.jme.Scope
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:

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: