Skip to content

Commit fcf1fb1

Browse files
committed
First Commit
0 parents  commit fcf1fb1

30 files changed

+3824
-0
lines changed

.github/CODE_EXAMPLE.md

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Wave Programming Language - Code Examples and Explanation
2+
3+
This document provides a series of code examples written in the Wave programming language. Each example demonstrates a specific feature or concept in the language, accompanied by a detailed explanation.
4+
5+
## Input/Output
6+
```
7+
fun main() {
8+
print("Hello World?\n");
9+
println("Hello World!");
10+
}
11+
```
12+
### Explanation:
13+
* `fun main()`: This defines the main function, which serves as the entry point for the program.
14+
In Wave, the `main` function is where the execution of the program begins, just like in C or Rust.
15+
16+
* `print("Hello World?\n");`: The `print` function outputs the string `"Hello World?"` without appending a newline character at the end.
17+
The `\n` ensures the output is followed by a newline.
18+
19+
* `println("Hello World!");`: The `println` function is used to print the string `"Hello World!"` to the console, followed by a newline character.
20+
21+
* Output:
22+
```
23+
Hello World?
24+
Hello World!
25+
```
26+
27+
This example demonstrates how to use `print` for output without a newline and `println` for output with a newline.
28+
29+
## Variables and Conditionals
30+
```
31+
fun main() {
32+
var x: i32 = 5;
33+
var y: i32 = 10;
34+
35+
if (x < y) {
36+
println("x is less than y");
37+
} else {
38+
println("x is greater than or equal to y");
39+
}
40+
}
41+
```
42+
### Explanation:
43+
* `var x: i32 = 5;` and `var y: i32 = 10;`: These lines declare two variables, `x` and `y`, of type `i32` (32-bit integer),
44+
and assign them initial values of 5 and 10, respectively.
45+
46+
* `if (x < y) { ... } else { ... }`: This is and `if-else` conditional statement.
47+
It checks if the value of `x` is less than `y`. If the condition is true, it prints `x is less than y`.
48+
Otherwise, it prints `x is greater than or equal to y`.
49+
50+
* Output:
51+
```
52+
x is less than y
53+
```
54+
55+
This example demonstrates how to declare variables, compare them, and use conditional logic.
56+
57+
## Loops
58+
### `while` Loop
59+
```
60+
fun main() {
61+
var i: i32 = 0;
62+
63+
while (i < 5) {
64+
println(i);
65+
i = i + 1;
66+
}
67+
}
68+
```
69+
70+
#### Explanation:
71+
* `var i: i32 = 0;`: This line initializes a variable `i` with the value 0.
72+
73+
* `while (i < 5) { ... }`: The `while` loop continues executing the code block as long as the condition `i < 5` holds true.
74+
Inside the loop, the current value of `i` is printed, and `i` is incremented by 1.
75+
76+
* Output:
77+
```
78+
0
79+
1
80+
2
81+
3
82+
4
83+
```
84+
85+
### `for` Loop
86+
```
87+
fun main() {
88+
for (i in 0..4) {
89+
println(i);
90+
}
91+
}
92+
```
93+
94+
#### Explanation:
95+
* `for (i in 0..4) { ... }`: The `for` loop iterates over the range `0..4`, effectively printing the values of `i` from 0 to 4.
96+
97+
* Output:
98+
```
99+
0
100+
1
101+
2
102+
3
103+
4
104+
```
105+
106+
This example demonstrates how the same task can be accomplished using a `for` loop, iterating through a specified range instead of manually managing the loop condition.
107+
108+
## Functions
109+
```
110+
fun greet(name: str) {
111+
println("Hello, {} !", name);
112+
}
113+
114+
fun main() {
115+
greet("Wave");
116+
}
117+
```
118+
119+
### Explanation:
120+
* `fun greet(name: str)`: This defines a function called `greet` that takes a single parameter `name` of type `str` (String).
121+
122+
* `"println("Hello, {} !"), name"`: inside the function, we use a formatted string to print a greeting message that includes the value of `name`.
123+
124+
* `greet("Wave")`: In the `main` function, we call the `greet` function with the argument `"Wave"`, which outputs the greeting message.
125+
126+
* Output:
127+
```
128+
Hello, Wave !
129+
```
130+
131+
This example demonstrate how to define and call a function with parameters in Wave, along with string formatting.
132+
133+
## Error Handling
134+
```
135+
fun divide(a: i32, b: i32) -> i32 {
136+
if (b == 0) {
137+
println("Error: Divison by zero");
138+
return -1;
139+
}
140+
return a / b;
141+
}
142+
143+
fun main() {
144+
var result: i32 = divide(10, 2);
145+
146+
if result != -1 {
147+
println("Result: {}", result);
148+
}
149+
}
150+
```
151+
152+
### Explanation
153+
154+
* `fun divide(a: i32, b: i32) -> i32`: This defines a function called `divide` that takes two integers as parameters and returns an integer result.
155+
* `if (b == 0) { ... }`: Inside the function, we check if `b` is zero. If it is, we print an error message and return `-1` to indicate an error. Otherwise, the function performs the division and returns the result.
156+
* `var result: i32 = divide(10, 2)`: In the `main` function, we call `divide` with the arguments `10` and `2`, storing the result in the variable `result`.
157+
* `if result != -1 { ... }`: We then check if the result is not equal to `-1` (indicating an error) and, if valid, print the result.
158+
159+
* Output:
160+
```
161+
Result: 5
162+
```
163+
164+
This example demonstrates how to handle errors, such as division by zero, and return an error value.
165+
166+
## Arrays
167+
```
168+
fun main() {
169+
var arr = [1, 2, 3, 4, 5];
170+
171+
for (num in arr) {
172+
println(num);
173+
}
174+
}
175+
```
176+
177+
### Explanation:
178+
179+
* `var arr = [1, 2, 3, 4, 5];`: This creates an array named `arr` containing the integers from 1 to 5.
180+
181+
* `for (num in arr) { ... }`: The `for` loop iterates over each element in the array `arr`. In each iteration, the current element is stored in the variable `num`.
182+
183+
* `println(num);`: Inside the loop, the current value of `num` is printed.
184+
185+
* Output:
186+
```
187+
1
188+
2
189+
3
190+
4
191+
5
192+
```
193+
194+
This example demonstrates how to declare an array and iterate through its elements using a `for` loop.

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: []
2+
ko_fi: lunasev
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
### Bug Title:
11+
(Brief description of the bug)
12+
13+
### Environment:
14+
- Operating System: (e.g., Windows 10, macOS, Ubuntu 20.04, etc.)
15+
- Wave Version: (e.g., 1.0.0)
16+
- Execution Environment: (e.g., Local, Server, etc.)
17+
18+
### Steps to Reproduce:
19+
1. (Step 1 to reproduce the bug)
20+
2. (Step 2 to reproduce the bug)
21+
3. ...
22+
23+
### Expected Result:
24+
(What should have happened if the bug didn’t occur)
25+
26+
### Actual Result:
27+
(What actually happened when the bug occurred)
28+
29+
### Screenshot/Logs:
30+
(Attach relevant screenshots or log files related to the bug)
31+
32+
### Additional Information:
33+
(Any additional information or special circumstances related to the bug)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
### Feature Title:
11+
(Brief description of the feature)
12+
13+
### Background:
14+
(Explain the reason or background for requesting this feature)
15+
16+
### Expected Behavior:
17+
(Describe in detail how this feature should behave)
18+
19+
### User Scenarios:
20+
1. (User scenario 1)
21+
2. (User scenario 2)
22+
3. ...
23+
24+
### Additional Information:
25+
(Any additional information or considerations related to the feature request)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Performance Issue Report
3+
about: Performance Issue
4+
title: ''
5+
labels: question
6+
assignees: ''
7+
8+
---
9+
10+
### Performance Issue Title:
11+
(Brief description of the performance issue)
12+
13+
### Environment:
14+
- Operating System: (e.g., Windows 10, macOS, etc.)
15+
- Wave Version: (e.g., 1.0.0)
16+
- Hardware: (e.g., CPU, RAM, etc.)
17+
18+
### Performance Problem Description:
19+
(Describe the performance degradation and its impact)
20+
21+
### Steps to Reproduce:
22+
1. (Step 1 to reproduce the performance issue)
23+
2. (Step 2 to reproduce the performance issue)
24+
3. ...
25+
26+
### Expected Performance:
27+
(What performance should have been like if it was working normally)
28+
29+
### Actual Performance:
30+
(Describe the actual performance observed with degradation)
31+
32+
### Additional Information:
33+
(Any additional information or context related to solving the performance issue)

.github/scalability.svg

Lines changed: 1 addition & 0 deletions
Loading

.github/scalability1.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)