Write your first loom
Install the loom command once, with the package manager you already use, or with curl if you use none. Installing Loom covers the details. Make a new folder anywhere you like, and create a file in it called hello.loom:
---
Language: TypeScript
---
# Hello world [hello.ts]
Let's write a program which greets the world.
=>
::[Greeting function]
console.log(greet('world'))
# Greeting function
We have assumed the `greet` function takes a name and returns a greeting for it. Let's actually write it.
=>
const greet = (name: string): string => `Hello, ${name}!`
~
That's it. Now we have a function that is transcluded and invoked by the code in the `Hello world` section. We can tangle and run it.
Turn it into code
Run . Loom writes hello.ts next to hello.loom. Open it and you will find plain TypeScript, with the greeting first and the line that uses it after:
const greet = (name: string): string => `Hello, ${name}!`
console.log(greet('world'))Run it
Run the file with the runtime you use:
It prints Hello, world!.