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 е проектиран за програмно взаимодействие.
|
||||
|
||||
Reference in New Issue
Block a user