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(tmpfn, scope, withEnv) → {Numbas.jme.funcObj}

Make a custom function.

Parameters:
Name Type Description
tmpfn Object

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: dictionary of evaluated variables, conditionSatisfied: was the condition satisfied?}
Source:

(static) variableDependants(todo, ancestors) → {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

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 variable

vars Array.<String>

names of variables this variable depends on

Source: