Clojure: `if`, `when`, `cond`, `case`, `doseq`, `for` and `loop` count as decisions and nesting (cx and nest are 1 and 0 for every Clojure function today)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Read cc_walk in src/ingest_metrics.h and clojureListHead in src/ingest_clojure.h, paying attention to the include order noted in the issue. Add the regression fixture and assertions in test/clojurecheck.sh or a registered metrics check, then bump both parser version constants. Done means the expected Clojure metrics and near misses pass, the Elixir checks remain green, and the listed identity and quality delta checks meet their acceptance criteria.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Claim it in this issue first. Size: S-M. Depends on: nothing. Language: Clojure. Siblings: #548 (Clojure call heads) and open PR #747 touch src/ingest_clojure.h; rebase onto whichever lands first.
The problem, in user terms
In Clojure, control flow is a list whose head is a special form or a macro: (if …), (when …), (doseq [x xs] …). The grammar has no control nodes, only list_lit. ripwire's metrics walk looks for control node types, so it finds none: every Clojure function prints cx="1" and no nest. The --quality-delta kinds built on these (complexity, nesting, tangle, and the deep / humps facts) can never fire on Clojure.
Fixture probe.clj:
(ns probe.core)
(defn nested-doseq [xs ys]
(doseq [x xs]
(doseq [y ys]
(when (= x y)
(println x)))))
(defn plain [x]
(inc x))
On main (e94757295), other attributes cut for reading:
ripwire . --no-cache --metrics
<s t="fn" n="nested-doseq" cx="1" ccx="0" nest="0"
<s t="fn" n="plain" cx="1" ccx="0" nest="0"
Expected: nested-doseq reads like the same double loop plus if in every other language: nest="3" and cx="4" (1 + two loops + one when). plain stays cx="1".
Where to look
cc_walkinsrc/ingest_metrics.h:2191. Elixir has the same problem (control is an ordinary call) and already has a keyword channel:elixirKeywordis read from the call's target at line 2237, andelixirDecision/elixirControl(lines 2245-2246) feed the decision count (line 2247) and the nesting branch (line 2274). Clojure needs the same channel, with the list's head symbol as the keyword.clojureListHeadinsrc/ingest_clojure.h:18reads the head symbol (it already skips comments,#_discards and reader metadata). Note the include order:src/ingest.cpp:202includesingest_metrics.hbeforeingest_clojure.h(line 213), so the walk cannot call it as it stands. Move the helper earlier (a forward declaration in the same translation unit works too) and say which you chose.isDecisionType(src/ingest_metrics.h:32) andcc_isNestingControl(line 107) are the node-type lists the other languages use; Clojure stays out of them, the same as Elixir.
Suggested approach
One small constexpr table of head symbols in the Clojure section, in two groups, mirroring Elixir:
| group | heads | counts as |
|---|---|---|
| decision + nesting | if, if-not, when, when-not, if-let, when-let, if-some, when-some, doseq, for, dotimes, while, loop |
+1 cx, one level deeper |
| nesting container | cond, condp, case |
one level deeper; each arm a decision, like case in Ruby (check how you split arms and say so) |
Do not count a list whose head is a local or a parameter, and keep quoted forms inert ('(if a b) is data; the existing quote and discard filter shows the rule). recur is not a loop by itself; loop is.
The test to add (red first)
- Add the fixture to
test/clojurecheck.sh/test/clojurefix/(or a smalltest/clojuremetricscheck.sh, registered intest/regression.shin the same commit ortest/manifestcheck.shfails). Assertnested-doseqprintsnest="3"andcx="4", red onmain. - Near misses that must not move:
(println (if a b c))counts theifbut theprintlncall adds nothing;'(when x y)and#_(when x y)count nothing; a function namedwhen-readycalled as(when-ready x)counts nothing (match the whole symbol, not a prefix);(defn plain …)stayscx="1". - The metrics are cached: bump
kParserVer(src/ingest_cache.h:409) and its mirrorkIngestParserVerMirror(src/quality.h:3335) to any number abovemain's, and runbash test/qschemetripcheck.sh.
Acceptance criteria
nested-doseqprintsnest="3" cx="4"; every near miss holds.bash test/clojurecheck.sh "$PWD/build/ripwire"andbash test/elixircheck.sh "$PWD/build/ripwire"(if you touched the shared channel) pass.bash test/langidentitycheck.sh origin/main HEAD --langs=clj,ex,py,ts,go,cpp: every language except Clojure is SAME. Clojure DIFFs only on metric attributes, waived by--intendedrows naming the new arm. If you have a real Clojure repository, add--repo=clj:<your clone>and report how many functions moved.ripwire . --quality-delta=origin/main..HEADgates 0. No newLang::Clojurebranch in shared code beyond the one channel next to Elixir's (CONTRIBUTING, "Definition of done for a common-code slice", item 6).
Size
S-M: a head table, one channel in the walk, a fixture, a version bump.
How to verify locally
cmake -S . -B build && cmake --build build -j # plain build: no build type
mkdir -p /tmp/cljnest && cp probe.clj /tmp/cljnest/ && ./build/ripwire /tmp/cljnest --no-cache --metrics
bash test/clojurecheck.sh "$PWD/build/ripwire"
bash test/qschemetripcheck.sh
bash test/langidentitycheck.sh origin/main HEAD --langs=clj,ex,py,ts,go,cpp
./build/ripwire . --quality-delta=origin/main..HEAD --legend=compact
Not in scope
Threading macros (->, ->>), map / filter / reduce callbacks (callback loops are low in cx by design in every language), essential complexity ev for Clojure, and moving the head tables into the tags pass (CONTRIBUTING slice 5a).
Claiming it only takes a comment here. Every contributor is credited by handle in the CHANGELOG entry and the release notes. Thank you!
- Lingua principale
- C++
- Stelle
- 2.6k
- Fork
- 182
- Merge medio
- 21h 12m
- PR unite (30g)
- 262
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di redhat-et/ripwire
-
bug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
TS/JS: a generator function expression (const f = function* / async function*) is not indexedForse già presa @shivam512262 l’ha presa 6 giorni fa. Apertabug good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
redhat-et/ripwire#730 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 78/100
redhat-et/ripwire#334 · 8 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
redhat-et/ripwire#68 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement help wanted
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di redhat-et/ripwire
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
riscv-software-src/riscv-isa-sim#2640 ·
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:gui prio:normal type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2118 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
-
mechanics UI
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
endless-sky/endless-sky#12949 ·
I maintainer di solito rispondono entro 1 giorno
-
bug difficulty:easy prio:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NatronGitHub/openfx-io#523 ·
I maintainer di solito rispondono entro 1 giorno