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
related reading
- Control Flow - Circom 2 Documentationdocs.circom.io
- Templates & Components - Circom 2 Documentationdocs.circom.io
- Scope (computer programming) - Wikipediaen.wikipedia.org
- Agentationagentation.dev
- Agentationagentation.com
- tscircuit - Code Electronics with Reacttscircuit.com
- A Gentle Introduction to LLVM IR · mcyoungmcyoung.xyz
- Subframe – The AI design tool built for codesubframe.com
- CoffeeScriptcoffeescript.org
- React Components, Templates & Themes — 12,000+ Crafted UI | 21st21st.dev
- Home ⚡ Zig Programming Languageziglang.org
- The program structure - Rust for C-Programmersrust-for-c-programmers.com