You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The enhanced dependency system in the Leo programming language simplifies the development of Leo projects by providing better support for external calls to both on-chain and local programs. Here's a breakdown of the key changes and features:
Change in Import Statement: Instead of using import foo.leo, you now use import foo.aleo to import dependencies.
Attaching Dependencies: Dependencies are attached using the CLI. For example, to pull credits.aleo as a dependency, you would use Usage: leo add --network <NETWORK> <NAME>.
Screencast.from.27-04-2024.01.24.11.webm
New Registry Structure: There's a new .aleo/registry structure in the ~/.aleo file system to store .aleo files from the Aleo network.
Automatic Retrieval of Network Dependencies: The system can automatically retrieve network dependencies and build complicated nested dependency structures, simplifying the management of dependencies in your project.
Adding Local Dependencies: You can also add local dependencies. For example, to add a local dependency named foo.aleo at path ../foo, you would use leo add -l ../foo foo.
In your Leo file, you would import these dependencies as usual:
READING EXTERNAL MAPPING
The Leo programming language supports reading external mappings using the Mapping::get and Mapping::get_or_use functions to retrieve values from a mapping stored in an external contract. Here's an explanation of each line of code:
Reading a Value from a Mapping: let val: u32 = Mapping::get(token.aleo/account, 0u32);
Mapping::get: This function is used to read a value from a mapping.
token.aleo/account: This is the identifier for the external contract's mapping. It specifies the contract (token.aleo) and the name of the mapping (account).
0u32: This is the key used to look up the value in the mapping. In this case, 0u32 is used as the key.
let val: u32: This declares a variable val of type u32 (unsigned 32-bit integer) to store the value retrieved from the mapping.
Reading a Value from a Mapping with a Default Value: let val: u32 = Mapping::get_or_use(token.aleo/account, 0u32, 0u32);
Mapping::get_or_use: This function is similar to Mapping::get, but it allows you to specify a default value to return if the key is not found in the mapping.
token.aleo/account: Same as before, the identifier for the external contract's mapping.
0u32: This is the key used to look up the value in the mapping.
0u32: This is the default value to return if the key is not found in the mapping.
let val: u32: This declares a variable val of type u32 to store the value retrieved from the mapping or the default value if the key is not found.
Relaxed Shadowing
In Leo programming, relaxed shadowing allows you to use local names (such as for mappings, structs, records, and functions) that overlap with names of external objects (like mappings, structs, records, and functions from external contracts or libraries). This can help simplify code and make it more readable. Here's an explanation of the provided code: let bar: hello.aleo/foo = bye.aleo/foo(foo {a: 1u32, b: 1u32});
let bar: hello.aleo/foo: This declares a variable bar of type hello.aleo/foo, which is a struct or record type defined in the hello.aleo contract or module.
bye.aleo/foo(foo {a: 1u32, b: 1u32}): This is an initialization expression for bar. It calls the foo function from the bye.aleo contract or module with a struct literal as an argument. The struct literal {a: 1u32, b: 1u32} creates a new instance of a struct with fields a and b, both initialized to 1u32.
The text was updated successfully, but these errors were encountered:
ENHANCED DEPENDENCY SYSTEM
The enhanced dependency system in the Leo programming language simplifies the development of Leo projects by providing better support for external calls to both on-chain and local programs. Here's a breakdown of the key changes and features:
Attaching Dependencies: Dependencies are attached using the CLI. For example, to pull credits.aleo as a dependency, you would use
Usage: leo add --network <NETWORK> <NAME>
.Screencast.from.27-04-2024.01.24.11.webm
Automatic Retrieval of Network Dependencies: The system can automatically retrieve network dependencies and build complicated nested dependency structures, simplifying the management of dependencies in your project.
leo add -l ../foo foo
.In your Leo file, you would import these dependencies as usual:

READING EXTERNAL MAPPING
The Leo programming language supports reading external mappings using the
Mapping::get
andMapping::get_or_use
functions to retrieve values from a mapping stored in an external contract. Here's an explanation of each line of code:let val: u32 = Mapping::get(token.aleo/account, 0u32);
let val: u32 = Mapping::get_or_use(token.aleo/account, 0u32, 0u32);
Relaxed Shadowing
In Leo programming, relaxed shadowing allows you to use local names (such as for mappings, structs, records, and functions) that overlap with names of external objects (like mappings, structs, records, and functions from external contracts or libraries). This can help simplify code and make it more readable. Here's an explanation of the provided code:
let bar: hello.aleo/foo = bye.aleo/foo(foo {a: 1u32, b: 1u32});
The text was updated successfully, but these errors were encountered: