mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-05-07 07:18:31 +00:00
updated cairo.html.markdown
This commit is contained in:
parent
aced78c444
commit
741e0f4a7f
@ -239,14 +239,14 @@ from starkware.cairo.common.bool import TRUE
|
|||||||
|
|
||||||
+ Storage variables: Cairo's storage is a map with `2^251` slots, where each
|
+ Storage variables: Cairo's storage is a map with `2^251` slots, where each
|
||||||
slot is a felt which is initialized to `0`. You create one using the
|
slot is a felt which is initialized to `0`. You create one using the
|
||||||
`@storage_var` decorator
|
`@storage_var` decorator.
|
||||||
|
|
||||||
```cairo
|
```cairo
|
||||||
@storage_var
|
@storage_var
|
||||||
func names() -> (name: felt) {}
|
func names() -> (name: felt) {}
|
||||||
```
|
```
|
||||||
|
|
||||||
+ Storage mappings: Unlike soldity where mappings have a separate keyword, in
|
+ Storage mappings: Unlike Solidity where mappings have a separate keyword, in
|
||||||
Cairo you create mappings using storage variables.
|
Cairo you create mappings using storage variables.
|
||||||
|
|
||||||
```cairo
|
```cairo
|
||||||
@ -269,7 +269,7 @@ from starkware.cairo.common.bool import TRUE
|
|||||||
|
|
||||||
+ Constants: Constants are fixed and as such can't be altered after being set.
|
+ Constants: Constants are fixed and as such can't be altered after being set.
|
||||||
They evaluate to an integer (field element) at compile time. To create a
|
They evaluate to an integer (field element) at compile time. To create a
|
||||||
constant in Cairo, you use the `const` keyword. Its proper practice to
|
constant in Cairo, you use the `const` keyword. It's proper practice to
|
||||||
capitalize constant names.
|
capitalize constant names.
|
||||||
|
|
||||||
```cairo
|
```cairo
|
||||||
@ -479,12 +479,12 @@ contract passing in the contract address as the first parameter like this:
|
|||||||
IENS.store_name(contract_address, _name);
|
IENS.store_name(contract_address, _name);
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that Interfaces excludes the function body/logic and the implicit
|
Note that Interfaces exclude the function body/logic and the implicit
|
||||||
arguments.
|
arguments.
|
||||||
|
|
||||||
### 9. Recursions
|
### 9. Recursions
|
||||||
|
|
||||||
Due to the unavailability of loops, Recursions are the go-to for similar
|
Due to the unavailability of loops, Recursion is the go-to for similar
|
||||||
operations. In simple terms, a recursive function is one which calls itself
|
operations. In simple terms, a recursive function is one which calls itself
|
||||||
repeatedly.
|
repeatedly.
|
||||||
|
|
||||||
@ -512,7 +512,7 @@ The nth fibonacci term is the sum of the `nth - 1` and the `nth - 2` numbers,
|
|||||||
that's why we get these two as `(x,y)` using recursion.
|
that's why we get these two as `(x,y)` using recursion.
|
||||||
|
|
||||||
NB: when implementing recursive functions, always remember to implement a base
|
NB: when implementing recursive functions, always remember to implement a base
|
||||||
case (`n==0`, `n==1` in our case), to prevent stack overflow.
|
case (`n==0`, `n==1` in our case), to prevent stack overflows.
|
||||||
|
|
||||||
### 10. Registers
|
### 10. Registers
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ registers:
|
|||||||
|
|
||||||
### 11. Revoked References
|
### 11. Revoked References
|
||||||
|
|
||||||
Revoked references occurs when there is a call instruction to another function,
|
Revoked references occur when there is a call instruction to another function,
|
||||||
between the definition of a reference variable that depends on `ap` (temp
|
between the definition of a reference variable that depends on `ap` (temp
|
||||||
variables) and its usage. This occurs as the compiler may not be able to compute
|
variables) and its usage. This occurs as the compiler may not be able to compute
|
||||||
the change of `ap` (as one may jump to the label from another place in the
|
the change of `ap` (as one may jump to the label from another place in the
|
||||||
@ -559,7 +559,7 @@ trying to access the `multiplier` variable after calling the `get_balance`
|
|||||||
function.
|
function.
|
||||||
|
|
||||||
In simple cases you can resolve revoked references by adding the keyword
|
In simple cases you can resolve revoked references by adding the keyword
|
||||||
`alloc_locals` within function scopes. In most complex cases you might need to
|
`alloc_locals` within function scopes. In more complex cases you might need to
|
||||||
create a local variable to resolve it.
|
create a local variable to resolve it.
|
||||||
|
|
||||||
```cairo
|
```cairo
|
||||||
|
Loading…
Reference in New Issue
Block a user