Files
typlisp/plan.md
2026-01-30 09:11:34 -10:00

85 lines
2.1 KiB
Markdown

# Clojure-Typst: A Clojure-style Lisp for Typst
## The Problem
Typst is a modern typesetting system with a nice programming language, but it's not a Lisp. We only like Lisps.
## The Vision
Create a Clojure-inspired Lisp that compiles to Typst, bringing:
- S-expression syntax
- Functional programming idioms
- Macros and metaprogramming
- Immutable-first data structures
- REPL-driven development (maybe?)
## Open Questions
### Syntax & Semantics
- [ ] How closely do we follow Clojure syntax?
- [ ] What Typst constructs map to Lisp naturally?
- [ ] How do we handle Typst's content mode vs code mode distinction?
- [ ] Do we support Clojure-style destructuring?
- [ ] What about namespaces/modules?
### Data Structures
- [ ] Vectors `[]`, maps `{}`, sets `#{}`?
- [ ] How do these map to Typst arrays and dictionaries?
- [ ] Lazy sequences - possible in Typst?
### Interop
- [ ] How do we call Typst functions from our Lisp?
- [ ] How do we emit Typst content/markup?
- [ ] Can we import Typst packages?
### Implementation
- [ ] What language for the compiler? (Clojure? Rust? Typst itself?)
- [ ] AST representation
- [ ] Compilation strategy (source-to-source? interpreter?)
- [ ] Error messages and source maps
## Typst Features to Leverage
- Functions are first-class
- Has closures
- Pattern matching in function args
- Content as a first-class type
- Scripting mode `#` vs content mode
## Example Syntax Ideas
```clojure
; Define a function
(defn greet [name]
(str "Hello, " name "!"))
; Emit typst content
(content
(heading "My Document")
(greet "World"))
; Maybe something like hiccup for content?
[:heading {:level 1} "My Document"]
["Hello, " [:strong "World"] "!"]
```
## Next Steps
1. Study Typst's language semantics more deeply
2. Identify the minimal viable feature set
3. Decide on implementation language
4. Build a basic parser for s-expressions
5. Implement core special forms (def, fn, let, if, do)
6. Add Typst content emission
7. Iterate
## Resources
- [Typst Documentation](https://typst.app/docs)
- [Clojure Reference](https://clojure.org/reference)
- [Make a Lisp](https://github.com/kanaka/mal)
## Notes
(Add brainstorming notes here)