Scoping - Circom 2 Documentation
Circom has static scoping like C and Rust. However, we have that signals and components must have global scoping and hence they should be defined at the top-level block of the template that defines them. Signal out2 must be declared at the top-level block. The next compilation error is produced: "out2 is outside the initial scope". Since circom 2.1.5, signals and components can be now declared inside if blocks, but only if the condition is known at compilation time. In the previous example, the condition i < n is known at compilation time, and then the declaration of signal out is allowed. However, if the condition where in < n, it is not known at compilation time and we output an error, because the declaration in this case is not allowed. Regarding visibility, a signal x of component c is also visible in the template t that has declared c, using the notation c.x. No access to signals of nested sub-components is allowed. For instance, if c is built using another component d, the signal
Scoping Circom has static scoping like C and Rust. However, we have that signals, buses and components must have global scoping and hence they should be defined at the top-level block of the template that defines them or, since circom 2.1.5, inside (nested) if blocks, but only if conditions are known at compilation time. pragma circom 2.1.5; template Cubes (N) { //Declaration of signals. signal input in[N]; signal output out[N]; //Statements. for (var i = 0; i < N; i++) { signal aux; aux <== in[i]*in[i]; out[i] <== aux*in[i]; } } component main = Cubes(5); Signal aux cannot be declared in the
Explore this link on the map →related reading
- Control Flow - Circom 2 Documentationdocs.circom.io
- Templates & Components - Circom 2 Documentationdocs.circom.io
- Scope (computer programming) - Wikipediaen.wikipedia.org
- Learn X in Y Minutes: Scenic Programming Language Tourslearnxinyminutes.com
- A Gentle Introduction to LLVM IR · mcyoungmcyoung.xyz
- tscircuit - Code Electronics with Reacttscircuit.com
- srclsacred.computer
- CoffeeScriptcoffeescript.org
- Protocollie Claude Code Vibe Coding setup · GitHubgist.github.com
- Cursor Docs — Agent, Rules, MCP, Skills & CLIdocs.cursor.com
- Writing a C compiler in 500 lines of Pythonvgel.me
- GitHub - oughtinc/ice: Interactive Composition Explorer: a debugger for compositional language model programs · GitHubgithub.com