Published
Edited
Aug 15, 2019
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { jit } from '2cc017f09c1e5210'
Insert cell
md`Ji begins simple - every character is a plain text characters. There are a few base symbols provided as the initial *vocabulary*.

This implementation, here on ObservablesHQ, begins with two basic symbols; \`Termination Symbol\` - new line ("\\n") character is initialized as an invokation character forcing the collected string to be executed, and \`Set Symbol\` - *integral with double stroke* ("⨎") character is used to allow Javascript to be executed - primarily as functions.
`
Insert cell
md`Symbols in Ji can be one or more characters, and will receive a maximum of two parameters when invoked as functions; Left and Right.

A ji symbol will take the left and right strings that surrounds it and will execute a given function or template when used in future code.

Both parameters are optional.

Let's take a look at an example of Ji implemented in Observables - we'll be using the \`jit\` function which returns the Ji compiled string given to it as a \`Markdown\` element.`
Insert cell
jit`
Hello, World!
`
Insert cell
Insert cell
jit`
We'll define 👋 as a string with the value 'Hello, World!';
👋⨎ () => 'Hello, World!'

And now we can just use the wave emoji to output "👋"
`
Insert cell
Insert cell
jit`
📣 ⨎ (left, right) => state => {
const num = parseInt(left)
const output = []
if (num > 0) {
for (let i = 1; i <= num; ++i) {
output.push(\`\${right === 'reverse' ? num - i : i}\`)
}
}

return '📣 ' + output.join(' ') + ' 📣 Ta Da!'
}

12📣

Or we can count down, in reverse:

20📣reverse
`
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