Cairo Variables and Mutability
Overview
Guide variable bindings in Cairo, including immutability, mutation with mut, constants, and shadowing.
Quick Use
- •Read
references/variables-mutability.mdbefore answering. - •Provide short, compile-ready examples that show correct use of
let,let mut,const, and shadowing. - •When addressing errors, point to the specific rule violated (immutability, type change, or scope).
Response Checklist
- •Decide whether the variable should be immutable, mutable, or constant.
- •If the name is reused or the type changes, prefer shadowing with a new
let. - •For constants, require
const, a type annotation, and global scope.
Example Requests
- •"Why does
x = 6fail afterlet x = 5in Cairo?" - •"Should I use
mutor shadowing when convertingu64tofelt252?" - •"How do I declare a constant in Cairo?"