docs: update documentation for May 12 compiler fixes
- CLJNIM_RECOMMENDATIONS.md: mark all 12 recommendations as implemented - README.md: add --lib-path, first-class functions, multi-arity, rest params - User guides (EN/BG): add sections for docstrings, multi-arity, rest params, keyword-as-function, first-class functions, loop/recur, --lib-path flag - TASKS.md: add Phase 11 with all BRing compiler fixes
This commit is contained in:
@@ -33,6 +33,21 @@ make build
|
||||
```
|
||||
Компилира до Nim, после до C, после до бинарен файл, и го изпълнява.
|
||||
|
||||
### Глобални Флагове
|
||||
|
||||
#### `--lib-path <dir>` — Потребителска Директория за Библиотеки
|
||||
Презаписва стандартния път за търсене на `lib/`. Проверява се преди `CLJNIM_LIB_PATH` environment променлива и вградените пътища.
|
||||
|
||||
```bash
|
||||
./cljnim --lib-path ./my_project/lib run app.clj
|
||||
```
|
||||
|
||||
Алтернатива чрез environment променлива:
|
||||
```bash
|
||||
export CLJNIM_LIB_PATH=./my_project/lib
|
||||
./cljnim run app.clj
|
||||
```
|
||||
|
||||
### `read` — Парсиране и Отпечатване на AST
|
||||
```bash
|
||||
./cljnim read examples/hello.clj
|
||||
@@ -61,8 +76,24 @@ make build
|
||||
(defn greet [name]
|
||||
(println "Здравей, " name))
|
||||
|
||||
; Функция с docstring
|
||||
(defn greet "Поздравява някого" [name]
|
||||
(str "Здравей, " name))
|
||||
|
||||
; Multi-arity функция
|
||||
(defn greet-multi
|
||||
([name] (greet-multi name "Здравей"))
|
||||
([name greeting] (str greeting ", " name)))
|
||||
|
||||
; Функция с rest параметри
|
||||
(defn sum-all [x & rest]
|
||||
(+ x (reduce + rest)))
|
||||
|
||||
; Извикване на функция
|
||||
(greet "Свят")
|
||||
(greet-multi "Алиса") ;; => "Здравей, Алиса"
|
||||
(greet-multi "Алиса" "Здрасти") ;; => "Здрасти, Алиса"
|
||||
(sum-all 1 2 3 4) ;; => 10
|
||||
|
||||
; Аритметика
|
||||
(+ 1 2 3) ; => 6
|
||||
@@ -88,6 +119,10 @@ make build
|
||||
; Ключови думи
|
||||
(def person {:name "Алиса" :age 30})
|
||||
|
||||
; Ключова дума като функция (търсене в карта)
|
||||
(:name person) ;; => "Алиса"
|
||||
(:age person) ;; => 30
|
||||
|
||||
; Картите и множествата използват persistent HAMT структури
|
||||
; със structural sharing и O(log₃₂ n) операции.
|
||||
```
|
||||
@@ -102,6 +137,33 @@ make build
|
||||
(println (factorial 5)) ; => 120
|
||||
```
|
||||
|
||||
### Функции от Първи Клас
|
||||
Потребителските функции могат да се подават като стойности на функции от по-висок ред:
|
||||
|
||||
```clojure
|
||||
(defn square [x] (* x x))
|
||||
(defn odd? [x] (= 1 (mod x 2)))
|
||||
|
||||
(map square [1 2 3 4]) ;; => [1 4 9 16]
|
||||
(filter odd? [1 2 3 4]) ;; => [1 3]
|
||||
(apply + [1 2 3]) ;; => 6
|
||||
```
|
||||
|
||||
### Loop / Recur
|
||||
```clojure
|
||||
(defn find-header [headers name]
|
||||
(loop [pairs (seq headers)]
|
||||
(if (empty? pairs)
|
||||
nil
|
||||
(let [[k v] (first pairs)]
|
||||
(if (= k name)
|
||||
v
|
||||
(recur (rest pairs)))))))
|
||||
|
||||
(find-header [[:content-type "text/html"] [:accept "*/*"]] :accept)
|
||||
;; => "*/*"
|
||||
```
|
||||
|
||||
## Ръководство за AI REPL
|
||||
|
||||
JSON REPL е проектиран за програмно взаимодействие.
|
||||
|
||||
@@ -33,6 +33,21 @@ Generates a `.nim` file from Clojure source.
|
||||
```
|
||||
Compiles to Nim, then to C, then to a binary, and runs it.
|
||||
|
||||
### Global Flags
|
||||
|
||||
#### `--lib-path <dir>` — Custom Library Directory
|
||||
Override the default `lib/` search path. Checked before `CLJNIM_LIB_PATH` env var and built-in paths.
|
||||
|
||||
```bash
|
||||
./cljnim --lib-path ./my_project/lib run app.clj
|
||||
```
|
||||
|
||||
Environment variable alternative:
|
||||
```bash
|
||||
export CLJNIM_LIB_PATH=./my_project/lib
|
||||
./cljnim run app.clj
|
||||
```
|
||||
|
||||
### `read` — Parse and Print AST
|
||||
```bash
|
||||
./cljnim read examples/hello.clj
|
||||
@@ -61,8 +76,24 @@ Shows the Clojure AST as S-expressions.
|
||||
(defn greet [name]
|
||||
(println "Hello, " name))
|
||||
|
||||
; Function with docstring
|
||||
(defn greet "Says hello to someone" [name]
|
||||
(str "Hello, " name))
|
||||
|
||||
; Multi-arity function
|
||||
(defn greet-multi
|
||||
([name] (greet-multi name "Hello"))
|
||||
([name greeting] (str greeting ", " name)))
|
||||
|
||||
; Function with rest parameters
|
||||
(defn sum-all [x & rest]
|
||||
(+ x (reduce + rest)))
|
||||
|
||||
; Call a function
|
||||
(greet "World")
|
||||
(greet-multi "Alice") ;; => "Hello, Alice"
|
||||
(greet-multi "Alice" "Hi") ;; => "Hi, Alice"
|
||||
(sum-all 1 2 3 4) ;; => 10
|
||||
|
||||
; Arithmetic
|
||||
(+ 1 2 3) ; => 6
|
||||
@@ -88,6 +119,10 @@ Shows the Clojure AST as S-expressions.
|
||||
; Keywords
|
||||
(def person {:name "Alice" :age 30})
|
||||
|
||||
; Keyword as function (lookup in map)
|
||||
(:name person) ;; => "Alice"
|
||||
(:age person) ;; => 30
|
||||
|
||||
; Maps and sets use persistent HAMT data structures
|
||||
; with structural sharing and O(log₃₂ n) operations.
|
||||
```
|
||||
@@ -102,6 +137,33 @@ Shows the Clojure AST as S-expressions.
|
||||
(println (factorial 5)) ; => 120
|
||||
```
|
||||
|
||||
### First-Class Functions
|
||||
User-defined functions can be passed as values to higher-order functions:
|
||||
|
||||
```clojure
|
||||
(defn square [x] (* x x))
|
||||
(defn odd? [x] (= 1 (mod x 2)))
|
||||
|
||||
(map square [1 2 3 4]) ;; => [1 4 9 16]
|
||||
(filter odd? [1 2 3 4]) ;; => [1 3]
|
||||
(apply + [1 2 3]) ;; => 6
|
||||
```
|
||||
|
||||
### Loop / Recur
|
||||
```clojure
|
||||
(defn find-header [headers name]
|
||||
(loop [pairs (seq headers)]
|
||||
(if (empty? pairs)
|
||||
nil
|
||||
(let [[k v] (first pairs)]
|
||||
(if (= k name)
|
||||
v
|
||||
(recur (rest pairs)))))))
|
||||
|
||||
(find-header [[:content-type "text/html"] [:accept "*/*"]] :accept)
|
||||
;; => "*/*"
|
||||
```
|
||||
|
||||
## AI REPL Guide
|
||||
|
||||
The JSON REPL is designed for programmatic interaction.
|
||||
|
||||
Reference in New Issue
Block a user