Published
Edited
Oct 5, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
q(`likes(${focus}, X), likes(X, Y).`)
Insert cell
Insert cell
{
focus; // update on tick
return q(`likes(X, Y), likes(Y, X).`); // mutuals! n.b. each pair is returned twice.
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
// run this cell to append a new person to the social graph
++mutable id;
mutable db =
`name(${mutable id}, '${pick('ABCDEFGHIJKLMNOPQRSTUVWXYZ')}').
job(${mutable id}, '${pick(['warrior', 'wizard'])}').
` + mutable db;

// you like someone. someone likes you. good luck!
mutable db =
`likes(${mutable id}, ${roll(mutable id)}).
likes(${roll(mutable id)}, ${mutable id}).
` + mutable db;
}
Insert cell
Insert cell
// q = ask => query(compiled[0])(ask)
// FIXME: lazy evaluation, but it takes an extra update cycle to propagate
q = ask => query(pl`${mutable db}`)(ask) // non-lazy evaluation
Insert cell
/* compiled = [pl`${mutable db}`]
{ // lazily compile the database (using a workaround for mutable state)
compiled[0] = pl`${db}`;
} */
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3') // optional, but d3.shuffle is also helpful
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more