Skip to content

MindfulMinun/Lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda

Make your own calculator

import Lambda from 'dist/index.js'

// Create your own world of math
const logic = new Lambda.Scope()

// Define operators that follow certain rules
logic.defineOperator({
    name: 'Conjunction',
    symbol: '^',
    stringify: (left, right) => `${left} \\land ${right}`,
    perform: (left, right) => left.value && right.value,
    precedence: 4
})
logic.defineOperator({
    name: 'Negation',
    symbol: '!',
    stringify: operator => `!${operator}`,
    perform: op => !op.value,
    precedence: 5
})

// Create expressions from those rules
const expr = logic.createExpression()

expr.write(
    new Lambda.ExpressionValue(true),
    logic.getOperator('Conjunction'),
    logic.getOperator('Negation'),
    new Lambda.ExpressionValue(false)
)

// ...and evaluate them
console.log(expr.toString()) // true ^ ! false
console.log(expr.evaluate()) // ExpressionValue { value: true }

See some examples.

Versioning

Follow SemVer for versioning. See the tags on this repo for available versions.

License

MIT

About

Make your own calculator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages