-
Notifications
You must be signed in to change notification settings - Fork 3
Variables
Greg Swindle edited this page Apr 27, 2019
·
1 revision
Variables are essential to most programming languages. For example:
const MEANING_OF_LIFE = 42
MEANING_OF_LIFE
is a variable that has been assigned a Number
with the value of 42
.
Using archetypes-rules, we could express MEANING_OF_LIFE
like this:
const { ruleElementFactory } = require('archetypes-rules')
const variable = ruleElementFactory.create('MEANING_OF_LIFE', 42)
console.log(variable.toString())
// =>
// NumberVariable name = MEANING_OF_LIFE, value = 42
console.log(JSON.stringify(variable, null, ' '))
// =>
// {
// "name": "MEANING_OF_LIFE",
// "type": "archetypes.rules.NumberVariable",
// "value": 42
// }
Data-type inference
archetypes-rules
ruleElementFactory
can infer the data-type of a value, so it's a good idea to use it whenever you load "raw" data.