LearnAdvanced formsQuote and syntax

Quote and syntax

Build syntax as a value.

quote lets code build syntax as a value.

let addTemplate := quote (x + #(delta));
let addOneSyntax := quote (#(x) + 1);
addOneSyntax;

Use quote when code needs to describe code. This is not normal data modeling. It is for tools and advanced generation.

A splice with # inserts a known syntax piece into a quoted form. Think of it like placing a prepared sticker into a form.

Keep quoted syntax small. Generated code is harder to read than direct code.

Quote shape

A quote builds syntax as a value for tools.

let nameSyntax := quote {
  let total := 42;
};

Use quote when the output is code or code-like structure. Use records and arrays for ordinary data.

Splice shape

# inserts syntax that was prepared outside the quote.

let delta := quote (2);
let generated := quote {
  let total := 40 + #delta;
};

Keep splices named. A named splice tells readers what generated piece is entering the quoted form.