-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): adding learn by for Wing
- Loading branch information
David Boyne
authored and
David Boyne
committed
Aug 27, 2024
1 parent
2ebeaf5
commit f57f78a
Showing
12 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Wing by example | ||
id: wing-by-example | ||
slug: / | ||
sidebar_label: Introduction | ||
description: Hands-on introduction to Wing using annotated code | ||
keywords: [Wing language, api] | ||
--- | ||
|
||
|
||
Wing is an open-source programming language. | ||
|
||
Wing by Example is a hands-on introduction to Dart using annotated example programs, inspired by Go By Example, Dark by Example and Haskell By Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: Wing by example | ||
id: hello-world | ||
slug: /hello-world | ||
sidebar_label: 1. Hello world | ||
description: Hello world wing example | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
# Hello world | ||
|
||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
log("Hello world!"); | ||
}; | ||
|
||
main(); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
Hello world! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Values | ||
id: values | ||
slug: /values | ||
sidebar_label: 2. Values | ||
description: Hello world wing example | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
|
||
Wing has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples. | ||
|
||
- Strings, which can be added together with + | ||
- Integers and floats | ||
- Booleans, with boolean operators as you'd expect | ||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
log("Hello " + "Wing"); | ||
|
||
log("1+1 = {1+1}"); | ||
log("7.0/3.0 = {7.0/3.0}"); | ||
|
||
log(true && true); | ||
log(true || false); | ||
log(!true); | ||
}; | ||
|
||
main(); | ||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
Hello Wing | ||
1+1 = 2 | ||
7.0/3.0 = 2.3333333333333335 | ||
true | ||
true | ||
false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: Variables | ||
id: Variables | ||
slug: /Variables | ||
sidebar_label: 4. Variables | ||
description: Using variables with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
Wing has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples. | ||
|
||
- Strings, which can be added together with + | ||
- Integers and floats | ||
- Booleans, with boolean operators as you'd expect | ||
|
||
```js title="main.w" | ||
let main = () => { | ||
|
||
// var delcares a varaible. Wing infers the type | ||
let a = "initial"; | ||
log(a); | ||
|
||
|
||
// type can also be declared | ||
let b: num = 1; | ||
let c: num = 2; | ||
log("{b}, {c}"); | ||
|
||
// variables cannot be changed using let without var | ||
let d: str = "Hello"; | ||
// d = "Test"; // error: Variable is not reassignable | ||
|
||
// makes variable mutable | ||
let var s = "hello"; | ||
s = "hello world"; // compiles | ||
log(s); | ||
|
||
}; | ||
|
||
main(); | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
initial | ||
1, 2 | ||
hello world | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: For | ||
id: for | ||
slug: /for | ||
sidebar_label: 5. For | ||
description: Using for loops with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
Wing supports for..in statements. | ||
|
||
[for..in](/docs/api/language-reference#26-for) is used to iterate over an array, a set or a range. The loop invariant in for loops is implicitly re-assignable (var). | ||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
|
||
// a standard for loop | ||
for item in 1..3 { | ||
log(item); | ||
} | ||
|
||
// for-in with arrays | ||
let arr = [1, 2, 3]; | ||
for item in arr { | ||
log("{item}"); | ||
} | ||
|
||
// break a loop | ||
let items = Set<num>[1, 2, 3]; | ||
for item in items { | ||
if(item == 1){ | ||
break; | ||
} | ||
log(item); | ||
} | ||
|
||
// continue the next iteration of the loop | ||
for item in 1..10 { | ||
if(item%2 == 0){ | ||
continue; | ||
} | ||
log(item); | ||
} | ||
|
||
}; | ||
|
||
main(); | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
1 | ||
2 | ||
1 | ||
2 | ||
3 | ||
1 | ||
3 | ||
5 | ||
7 | ||
9 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: If/Else | ||
id: if-else | ||
slug: /if-else | ||
sidebar_label: 6. If/Else | ||
description: Using if else with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
Flow control can be done with if/else statements. The if statement is optionally followed by else if and else. | ||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
|
||
if (7 % 2 == 0) { | ||
log("7 is even"); | ||
} else { | ||
log("7 is odd"); | ||
} | ||
|
||
if (8 % 4 == 0) { | ||
log("8 is divisble by 4"); | ||
} | ||
|
||
if(8 % 2 == 0 || 7 % 2 == 0){ | ||
log("either 8 or 7 are even"); | ||
} | ||
|
||
let value:num = 9; | ||
if(value < 0){ | ||
log("${value} is negative"); | ||
} else if value < 10 { | ||
log("${value} has 1 digit"); | ||
} else { | ||
log("{value} has multiple digits"); | ||
} | ||
|
||
}; | ||
|
||
main(); | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
7 is odd | ||
8 is divisble by 4 | ||
either 8 or 7 are even | ||
9 has 1 digit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: While | ||
id: while | ||
slug: /while | ||
sidebar_label: 7. While | ||
description: Using while statements with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
|
||
let var i = 0; | ||
|
||
while(i < 2){ | ||
log("while {i}"); | ||
i = i + 1; | ||
} | ||
|
||
}; | ||
|
||
main(); | ||
|
||
``` | ||
|
||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
while 0 | ||
while 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Optionality | ||
id: optionality | ||
slug: /optionality | ||
sidebar_label: 8. Optionality | ||
description: Using while statements with Wing | ||
keywords: [Wing language, example] | ||
--- | ||
|
||
Nullity is a primary source of bugs in software. Being able to guarantee that a value will never be null makes it easier to write safe code without constantly having to take nullity into account. | ||
|
||
Optionality requires developers to be more intentional about working with the concept of "lack of value". | ||
|
||
```js playground title="main.w" | ||
let main = () => { | ||
|
||
let monday:str = "doctor"; | ||
let tuesday: str? = nil; | ||
|
||
// Set next to tuesday if there is a value otherwise use monday value | ||
let var next = tuesday ?? monday; | ||
|
||
log("{next}"); | ||
|
||
}; | ||
|
||
main(); | ||
|
||
``` | ||
```bash title="Wing console output" | ||
# Run locally with wing console | ||
wing it | ||
|
||
doctor | ||
``` |
Oops, something went wrong.