Quick start
Alice asks her team to choose Sushi or Pizza. Bob replies “Soup.” His reply is easy to understand. Should it count as a vote?
With CBCL, Alice can send Bob the rules for the poll. Each participant can use the same rules to check a vote before adding it to the tally. They can do this without a central referee. The JavaScript example shows what happens to Bob’s vote. The Rust example shows how to install a dialect.
Select the instructions for your language. Each example runs locally with CBCL 0.3.1.
JavaScript: run a lunch poll
Use Node.js 22.6 or higher and npm. Run these commands in a new directory.
npm init -y
npm install --save-exact @anuna/[email protected]
node node_modules/@anuna/cbcl/examples/lunch-vote.mjs
Verified lunch-vote
Soup rejected: outside the proposed options
Tally: {"Sushi":1}
The proposal gives two choices, Sushi and Pizza. Bob votes for Sushi. He then tries to vote for Soup. The runtime refuses the second choice because it is absent from the proposal. The tally has one vote.
Rust: install a dialect
Use Rust 1.75.0 or later and Cargo. Check your Rust version.
rustc --version
Run these commands from the directory for your projects.
cargo new cbcl-greeting
cd cbcl-greeting
cargo add 'cbcl-core@=0.3.1' 'cbcl-parser@=0.3.1'
The cbcl-parser crate reads CBCL text. The cbcl-core crate supplies the dialect registry. Replace the contents of src/main.rs with this program.
use cbcl_core::dialect::DialectRegistry;
use cbcl_parser::{parse, parse_dialect};
fn main() {
let source = r#"(define greeting (cbcl) @alice
(extend greet (to) (tell to "Hello")))"#;
let expr = parse(source).expect("read the expression");
let dialect = parse_dialect(&expr).expect("read the dialect");
let mut registry = DialectRegistry::new();
registry.install(dialect).expect("install the dialect");
println!("Installed greeting");
}
cargo run --quiet
Installed greeting
Next steps
- To test the rules for a poll, see Count a vote.
- To install your own dialect in JavaScript, see Install a dialect in JavaScript.
- To use your Cargo project to check incoming messages, build a Rust receiver.
- To see the message that opens the poll, read Text and values.