Skip to content

Commit 2940d8a

Browse files
committed
update 19 files and delete 1 file [deploy]
1 parent f6a3b5d commit 2940d8a

33 files changed

+256
-73
lines changed

.github/workflows/deploy.yml

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: Deploy
22

33
on:
44
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
58

69
jobs:
710
deploy:
11+
if: github.event_name == "workflow_dispatch" || contains(github.event.head_commit.message, '[deploy]')
812
runs-on: ubuntu-latest
913
steps:
1014
- name: Checkout

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"unocss.root": "site"
2+
"unocss.root": "apps/site"
33
}

apps/site/README.md

-49
This file was deleted.

apps/site/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@astrojs/svelte": "^1.0.2",
16+
"@fontsource/noto-serif": "^4.5.11",
1617
"@unocss/reset": "^0.46.1",
1718
"ace-builds": "^1.12.4",
1819
"adoc-skin": "^0.1.1",

apps/site/readme.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- how can we force reload files on dev server?

apps/site/src/components/Nav.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
let links = [
55
{
66
label: "Previous",
7-
href: $challenge?.page.previous,
7+
href: `/${$challenge?.page.previous}`,
88
},
99
{
1010
label: "~",
11-
href:"/",
11+
href: "/",
1212
},
1313
{
1414
label: "Next",
15-
href: $challenge?.page.next,
15+
href: `/${$challenge?.page.next}`,
1616
},
1717
]
1818
</script>

apps/site/src/components/Text.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
2-
import "../styles/adoc.scss"
2+
// import "../styles/adoc.scss"
3+
import "../styles/doc.styl"
34
45
export let title: string | undefined = undefined
56
export let value: string

apps/site/src/lib/challenges.ts

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export async function getChallenge(slug: string): Promise<Challenge> {
5454
slug,
5555
title: readme.getTitle() || slug,
5656
content: readme.convert(),
57+
// title: slug,
58+
// content: slug,
5759
todo,
5860
main,
5961
test,

apps/site/src/styles/doc.styl

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@import "@fontsource/noto-serif/latin-400.css"
2+
@import "@fontsource/noto-serif/latin-400-italic.css"
3+
@import "@fontsource/noto-serif/latin-700.css"
4+
@import "@fontsource/noto-serif/latin-700-italic.css"
5+
6+
.challenge__prompt
7+
@apply space-y-4 text-gray-1
8+
9+
font-family "Noto Serif"
10+
font-size 17px
11+
line-height 1.5
12+
13+
text-rendering optimizeLegibility
14+
font-smooth always
15+
-webkit-font-smoothing antialiased
16+
-moz-osx-font-smoothing grayscale
17+
18+
& > .paragraph
19+
width 96%
20+
@apply mx-auto
21+
22+
pre.highlight
23+
@apply text-gray-4 rounded-lg px-6 py-4 border-(1 dark-1)
24+
background-color #1D1F21
25+
26+
:not(pre) > code
27+
@apply text-gray-4 rounded-lg px-2 py-1 border-(1 dark-1)
28+
background-color #1D1F21

challenges/actors/main.mo

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
actor class Some() {
2+
public func a() : async Bool {
3+
return true;
4+
};
5+
};

challenges/actors/readme.adoc

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
= Actors
2+
3+
== Internet Computer
4+
5+
- Canisters are memory isolated
6+
- Canisters can communicate with asynchronous messages
7+
- Canisters messenge candid values, the values are binary encoded
8+
- Canisters only process one message at a time, others wait
9+
- Canisters use callbacks to register code that needs to be done on given
10+
message processing
11+
12+
== Motoko
13+
14+
=== General
15+
16+
- Actors are an abstraction/representation for canisters
17+
- The type of the actor is its functions
18+
- Its asynchronous functions indicate which messanges can be handled
19+
- Types of an actor and its functions can be translated to candid
20+
- The candid types define how the binary data passed is structured
21+
22+
=== Actors vs Objects
23+
24+
We can think of actors like sorts of objects. But there are notable differences:
25+
26+
- Actors come with completely isolated state
27+
- Any interactivity with the outside goes through asynchronous messanges
28+
- Messages are processed one-at-a-time, no matter if issued in parallel
29+
30+
=== Motoko Implementation
31+
32+
- Message sending in Motoko means calling an async function of an actor
33+
- There is no blocking in the wait for the response, istead there is a
34+
promise/future, that is return to the caller by the callee, that resolves, once
35+
the message is handled
36+
- The promise/future is a placeholder, which can result in a result
37+
- Because there is no blocking in the time waiting for the promise to resolve,
38+
the caller can do anything, send other requests to any actor or whatever
39+
- The caller can wait for the result, when it resolves it will be available,
40+
otherwise its resolved value is stored for future access
41+
42+
=== Shared functions and state
43+
44+
- Actor messanging functions are called _shared_-functions, since they can be
45+
accessed from remote code, actors, etc.
46+
- Shared functions return futures/promises that resolve once handled by the
47+
called actor
48+
- The data transmitted is immutable, we call it _shared_-state
49+
50+
[source,motko]
51+
----
52+
actor {
53+
public shared func someFuncName() : async Text {
54+
return "I am some func returning some string"
55+
}
56+
}
57+
----
58+
59+
Since all functions of an actor have to be shared, we can obmit the `shared`
60+
keyword:
61+
62+
[source,motko]
63+
----
64+
actor {
65+
public shared func someFuncName() : async Text {
66+
return "I am some func returning some string"
67+
}
68+
}
69+
----
70+
71+
---
72+
73+
// Questios:
74+
75+
- Can multiple messanges we processed by one actor at the same time so the
76+
one-action-per-time only applies to one messange handler
77+
- Or does it apply to the whole actor and therfore only one messange can be
78+
called at one time

challenges/actors/solution.mo

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
actor class Some() {
2+
public func a() : async Bool {
3+
return true;
4+
};
5+
};

challenges/actors/test.mo

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Main "./main";
2+
3+
module {
4+
public func testWithoutShared() : async Bool {
5+
let some = await Main.Some();
6+
return (await some.a()) == true;
7+
};
8+
};

challenges/actors/todo.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Run the code to see the tests passing.
2+
3+
Remove the optional `shared` function modifier and see the tests still passing.

challenges/await/main.mo

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
actor class Some() {
2+
public shared func a() : async Bool {
3+
return true;
4+
};
5+
public shared func b() : async Bool {
6+
let aValue = a();
7+
return aValue;
8+
};
9+
};

challenges/await/readme.adoc

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
= Await
2+
3+
Asynchronous functions return promises, that resolve to a value, once it is
4+
available.
5+
6+
We can store a promise in a variable and then wait for it later:
7+
8+
[source,motoko]
9+
----
10+
let a = someAsyncFunc();
11+
let aResolved = await a;
12+
----
13+
14+
In the above example `a` holds the promise and `aResolved` waits for the promise
15+
to resolve and stores the resolved value.
16+
17+
Commonly this is done in one go:
18+
19+
[source,motoko]
20+
----
21+
let aResolved = await someAsyncFunc();
22+
----
23+
24+
If we want to wait for the result of a promise in an expression that is not a
25+
declaration, we can wrap the awaiting into brackets:
26+
27+
[source,motoko]
28+
----
29+
let isTrue = (await someAsyncFunc()) == true;
30+
----

challenges/await/solution.mo

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
actor class Some() {
2+
public shared func a() : async Bool {
3+
return true;
4+
};
5+
public shared func b() : async Bool {
6+
let aValue = await a();
7+
return aValue;
8+
};
9+
};

challenges/await/test.mo

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Main "./main";
2+
3+
module {
4+
public func testAwait() : async Bool {
5+
let some = await Main.Some();
6+
return (await some.b()) == true;
7+
};
8+
};

challenges/await/todo.adoc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Note that we are returning a promise in a function, that should return a boolean.
2+
3+
Run the source as-is and see the compiler throws an exception.
4+
5+
Fix the function to actually return a boolean value.

challenges/classes/main.mo

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
actor class Slang(_slang : Text) {
2+
var slang : Text = _slang;
3+
public func getSlang() : async Text {
4+
return slang;
5+
};
6+
};

challenges/classes/readme.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
= Classes

challenges/classes/solution.mo

Whitespace-only changes.

challenges/classes/test.mo

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Main "./main";
2+
3+
module {
4+
public func testConstructor() : async Bool {
5+
let someObj = await Main.Slang("Some string");
6+
let out = await someObj.getSlang();
7+
return out == "Some string";
8+
};
9+
};

challenges/classes/todo.adoc

Whitespace-only changes.

challenges/comments/readme.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
Motoko comes with 3 different kinds of comments:
44

5-
== Single line comments
5+
Single line comments:
66

77
```motoko
88
// single line comment
99
```
1010

11-
== Multi-line comments
11+
Multi-line comments:
1212

1313
```motoko
1414
/* multi-line
1515
comment */
1616
```
1717
18-
== Documentation comments
18+
Documentation comments:
1919
2020
```motoko
2121
/// documentation comment

chl-new.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/bin/bash
22

3-
folder=$1
3+
topic=$1
44

5-
if [ -z "$folder" ]; then
6-
echo "Usage: $0 <folder>"
5+
if [ -z "$topic" ]; then
6+
echo "Usage: $0 <topic>"
77
exit 1
88
fi
99

10-
cp -r ./chl-tpl ./challenges/$folder
10+
cp -r ./chl-tpl ./challenges/$topic
1111

12-
code ./challenges/$folder/readme.adoc
12+
# Write the capitalized topic as a headline into the readme.adoc
13+
echo "= ${topic^}" > ./challenges/$topic/readme.adoc
14+
15+
code ./challenges/$topic/readme.adoc

chl-tpl/main.mo

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module {
2-
public func a() : Bool {
1+
actor class Some() {
2+
public func a() : async Bool {
33
return true;
44
};
55
};

0 commit comments

Comments
 (0)