ludus/clj_to_janet.md

43 lines
1.1 KiB
Markdown
Raw Normal View History

2024-01-08 01:10:02 +00:00
# From Clojure to Janet
## How to convert files
### Comments
`% s ; r # <esc>`
### called keyword property access
Use a macro:
- Select `\ \( : ret <esc>`
- Record the macro: `Q n <esc> v e c get <esc> e e a <space> <esc> p <esc> Q`
- Then just `q` until you've changed everything
### Chars don't exist
- \char -> "char", e.g.
- \newline -> "\n", etc.
- \a -> "a"
### Use mutable arrays and tables
Where data structures are mutable, add `@`s.
### Sets & tables
Sets don't exist in Janet. Use tables with values set to `true`.
### Strings -> number literals
- Clj uses `edn/read-string`; Janet uses `parse-all`
### `loop` -> `defn recur`
- Clj's `loop` is very different from Janet's `loop`
- As a quick and dirty workaround, change it to an interior recursive function
- Janet has tail calls, so this is nearly as efficient (paying the overhead for creating the function)
- An optimization is to pull out these functions and declare them at the toplevel
### current-char
### Straight replacements:
- nth -> get
- assoc -> put
- conj -> array/push
- str -> string
- substr -> slice