-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.nr
129 lines (91 loc) · 2.34 KB
/
example.nr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Comments
/*
/*
Multi-Layered Comments
*/
*/
// Strings
"String with \e escape characters"
// Numerics
-5, 6666.555, 7
// Var Names
u7, u4, u567585, [53]Field
CustomType, customVariable,
_CustomUnusedType, _custumUnusedVariable
function(), Class(), _function()
//structure<Hello, World <andEveryoneElse>> // THIS BREAKS: x < y
#[builtin(hello)]
fn WithComment() {
}
// Import
use x::y::z::{
w, v::a
}
// Structs
struct structure {
Var : type, // First-Letter-Capitalization ignored
Var2 : type
x // Over
: // Many
y // Lines
// Note! ":" is simply ignored by the syntax highlighter:
x y()
// Comma separates:
x, y, z,
// Types in Types
val : Struct<More, Structs>
}
struct TupleStruct (basically same, stuff going <on>)
struct WithoutContent
if xx {} else if yy {} else {}
while () {}
let x = true
let y = false
// Example
// https://github.com/noir-lang/noir/blob/master/examples/1/src/foo.nr
mod foo;
fn hello(x : pub Field) -> Field {
x
}
// https://github.com/noir-lang/noir/blob/master/examples/1/src/main.nr
fn main(x : Field, y : pub Field) {
constrain x != foo::hello(y);
}
// https://github.com/noir-lang/noir/blob/master/examples/2/src/main.nr
fn main(x : Field, y : Field) {
priv x_as_u8 = x as u8;
priv y_as_u8 = y as u8;
constrain (x_as_u8 & y_as_u8) == y;
}
// https://github.com/noir-lang/noir/blob/master/examples/3/src/main.nr
fn main(x : u8, y : Field) {
priv _z = x + (y as u8);
}
// https://github.com/noir-lang/noir/blob/master/examples/4/src/main.nr
fn main(x : Field, y : Field) {
const _a = 1;
priv k = x + y;
let j = for _k in _a..100 {
priv z = x + k;
z
};
constrain k == j[1];
}
// https://github.com/noir-lang/noir/blob/master/examples/5/src/main.nr
use dep::std;
fn main(x : Field, result : [32]Field) {
let digest = std::hash::sha256([x as u8]);
constrain digest == result;
}
// https://github.com/noir-lang/noir/blob/master/examples/6/src/main.nr
use dep::std;
fn main(x : [5]u8, result : pub [32]u8) {
let digest = std::hash::sha256(x);
constrain digest == result;
}
// https://github.com/noir-lang/noir/blob/master/examples/7/src/main.nr
use dep::std;
fn main(x : [5]u8, result : [32]u8) {
let digest = std::hash::blake2s(x);
constrain digest == result;
}