mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Rename examples
This commit is contained in:
parent
508c54dd92
commit
99ec270f8a
@ -4,10 +4,10 @@ This directory includes the following Leo code examples:
|
||||
|
||||
1. Hello World -> Basic Sum of two u32
|
||||
2. Groups -> Basic operations over groups
|
||||
3. Core -> Core circuits functions over a field type
|
||||
3. Core -> Core functions over a field type
|
||||
4. Bubblesort -> Sorting algorithms over a tuple
|
||||
5. Import point -> Import code from an other file
|
||||
6. Message -> Initialization of a circuit type
|
||||
5. Import point -> Import code from another file
|
||||
6. Message -> Initialization of a struct
|
||||
7. Token -> Record example
|
||||
|
||||
## Build Guide
|
||||
@ -16,7 +16,7 @@ To compile each example, run:
|
||||
```bash
|
||||
leo build
|
||||
```
|
||||
When you run this command for the first time the snarkvm parameters (universal setup) will be downloaded, these are necessary to run the circuits.
|
||||
When you run this command for the first time the snarkvm parameters (universal setup) will be downloaded, these are necessary to run the programs.
|
||||
|
||||
To run each program, run:
|
||||
```bash
|
||||
|
@ -1,7 +1,7 @@
|
||||
// This function takes as input a field `a` and calls several core circuit functions.
|
||||
// Core circuit functions are built-in to the Leo language and call handwritten, optimized circuits in the AVM.
|
||||
// To call a core circuit function, use the correct capitalized circuit identifier followed by two colons
|
||||
// and then the function. Example: `Pedersen64::hash()`.
|
||||
// This function takes as input a field `a` and calls several core functions.
|
||||
// Core functions are built-in to the Leo language and call handwritten, optimized circuits in the AVM.
|
||||
// To call a core function, use the correct capitalized identifier followed by two colons
|
||||
// and then the function name. Example: `Pedersen64::hash()`.
|
||||
@program
|
||||
function main(a: field) -> field {
|
||||
let b: field = BHP256::hash(a);
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Leo message circuit
|
||||
A basic example showing how to declare a circuit in the Leo language.
|
||||
# Leo message struct
|
||||
A basic example showing how to declare a struct in the Leo language.
|
||||
|
||||
## Build Guide
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The program input for message/src/main.leo
|
||||
// To pass "m" into the "main" function we
|
||||
// 1. Define the "Message" type.
|
||||
// 2. Use brackets `{ }` to enclose the circuit members.
|
||||
// 3. Define each circuit member `name : value`.
|
||||
// 2. Use brackets `{ }` to enclose the struct members.
|
||||
// 3. Define each struct member `name : value`.
|
||||
[main]
|
||||
m: Message = Message { first: 2field, second: 3field };
|
||||
|
@ -1,28 +1,27 @@
|
||||
// This example demonstrates the definition and initialization of a "circuit" type in Leo.
|
||||
// Circuit types are similar to composite types in other languages such as "struct".
|
||||
// This example demonstrates the definition and initialization of a "struct" in Leo.
|
||||
|
||||
// The "Message" circuit type.
|
||||
circuit Message {
|
||||
// A circuit member named "first" with type "field".
|
||||
// The "Message" struct.
|
||||
struct Message {
|
||||
// A struct member named "first" with type "field".
|
||||
first: field,
|
||||
// A circuit member named "second" with type "field".
|
||||
// A struct member named "second" with type "field".
|
||||
second: field,
|
||||
}
|
||||
|
||||
// The "main" function of this Leo program takes a "Message" circuit type as input.
|
||||
// The "main" function of this Leo program takes a "Message" struct type as input.
|
||||
// To see how to input variable "m" is passed in open up `inputs/message.in`.
|
||||
@program
|
||||
function main(m: Message) -> field {
|
||||
|
||||
// 1. Define the "Message" type.
|
||||
// 2. Use brackets `{ }` to enclose the circuit members.
|
||||
// 3. Define each circuit member `name : value`.
|
||||
// 2. Use brackets `{ }` to enclose the struct members.
|
||||
// 3. Define each struct member `name : value`.
|
||||
let m1: Message = Message {
|
||||
first: m.first,
|
||||
second: m.second,
|
||||
};
|
||||
|
||||
// Access the members of a circuit with dot syntax.
|
||||
// `circuit_name.member`
|
||||
// Access the members of a struct with dot syntax.
|
||||
// `struct_name.member`
|
||||
return m1.first + m1.second;
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ A standard game of Tic-Tac-Toe in Leo.
|
||||
❌ ❕ ❌ ❕ ⭕
|
||||
|
||||
## Representing State
|
||||
Leo allows users to define composite data types with the `circuit` keyword.
|
||||
The game board is represented by a circuit called `Board`, which contains three `Row`s.
|
||||
Leo allows users to define composite data types with the `struct` keyword.
|
||||
The game board is represented by a struct called `Board`, which contains three `Row`s.
|
||||
An alternative representation would be to use an array, however, these are not yet supported in Leo.
|
||||
|
||||
## Language Features
|
||||
- `circuit` declarations
|
||||
- `struct` declarations
|
||||
- conditional statements
|
||||
- early termination. Leo allows users to return from a function early using the `return` keyword.
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
// - `c3` : The third entry in the row.
|
||||
// A valid entry is either 0, 1, or 2, where 0 is empty, 1 corresponds to player 1, and 2 corresponds to player 2.
|
||||
// Any other values are invalid.
|
||||
circuit Row {
|
||||
struct Row {
|
||||
c1: u8,
|
||||
c2: u8,
|
||||
c3: u8
|
||||
@ -14,7 +14,7 @@ circuit Row {
|
||||
// - `r1` : The first row in the board.
|
||||
// - `r2` : The second row in the board.
|
||||
// - `r3` : The third row in the board.
|
||||
circuit Board {
|
||||
struct Board {
|
||||
r1: Row,
|
||||
r2: Row,
|
||||
r3: Row,
|
||||
|
@ -1,7 +1,7 @@
|
||||
// The 'vote.leo' program.
|
||||
|
||||
// Proposal details
|
||||
circuit ProposalInfo {
|
||||
struct ProposalInfo {
|
||||
title: field,
|
||||
content: field,
|
||||
proposer: address,
|
||||
|
Loading…
Reference in New Issue
Block a user