Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,070 changes: 0 additions & 1,070 deletions .docs-plan/motoko-repo-sync-proposal.md

This file was deleted.

2 changes: 1 addition & 1 deletion .sources/motoko
Submodule motoko updated 360 files
60 changes: 31 additions & 29 deletions docs/languages/motoko/base-core-migration.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
sidebar_position: 12
description: "Motoko language documentation"
title: "Motoko `base` to `core` migration guide"
description: "Comprehensive guide for migrating from the Motoko base package to the new core package."
sidebar:
order: 12
hidden: true
---

* [GitHub repository](https://github.com/dfinity/motoko-core)
* [Documentation](https://mops.one/core)
* [GitHub repository](https://github.com/caffeinelabs/motoko-core)
* [Documentation](https://mops.one/core/docs/)

The `core` package is a new and improved standard library for Motoko, focusing on:
* AI-friendly design patterns.
Expand All @@ -28,7 +30,7 @@ If you are migrating an existing project, you can keep the `base` import and gra

### Important considerations

:::warning[Version requirements]
:::caution[Version requirements]
The `core` package depends on new language features, so make sure to update to the latest dfx (0.28+) or Motoko compiler (0.15+) before migrating.
:::

Expand All @@ -40,9 +42,9 @@ When updating to the `core` package:
- Hash-based data structures are no longer included in the standard library. It is encouraged to use ordered maps and sets for improved security.
- In some cases, it won't be possible to fully migrate to `core` due to removal of some features in `base`. In these cases, you can continue using both packages side-by-side or search for [Mops packages](https://mops.one/) built by the community.

For details on function signatures, please refer to the official [documentation](https://mops.one/core).
For details on function signatures, please refer to the official [documentation](https://mops.one/core/docs/).

Also, feel free to ask for help by posting on the [ICP developer forum](https://forum.dfinity.org/c/developers) or opening a GitHub issue on the [`dfinity/motoko-core`](https://github.com/dfinity/motoko-core/issues) repository.
Also, feel free to ask for help by posting on the [ICP developer forum](https://forum.dfinity.org/c/developers) or opening a GitHub issue on the [`caffeinelabs/motoko-core`](https://github.com/caffeinelabs/motoko-core/issues) repository.

## Module changes

Expand Down Expand Up @@ -158,7 +160,7 @@ The `core` package brings significant changes to data structures, making a clear
- `sortInPlace()` - Use `VarArray.sortInPlace()` instead
- `tabulateVar()` - Use `VarArray.tabulate()` instead

### [`Blob`](https://mops.one/core/docs/Blob)
### [`Blob`](https://mops.one/core/docs/Blo)

#### Modified functions
- `fromArrayMut()` → `fromVarArray()`
Expand Down Expand Up @@ -187,7 +189,7 @@ The `core` package brings significant changes to data structures, making a clear
- `isLowercase()` → `isLower()`
- `isUppercase()` → `isUpper()`

### [`Debug`](https://mops.one/core/docs/Debug)
### [`Debug`](https://mops.one/core/docs/Deug)

#### Added functions
- `todo()` - Replaces `Prelude.nyi()`
Expand Down Expand Up @@ -258,7 +260,7 @@ Helper functions have been added, such as `allValues()`, for each finite type in
- `rangeBy()`, `rangeByInclusive()` - Range with step
- `toInt()` - Convert to Int

### [`Int8`, `Int16`, `Int32`, `Int64`, `Nat8`, `Nat16`, `Nat32`, `Nat64`](https://mops.one/core)
### [`Int8`, `Int16`, `Int32`, `Int64`, `Nat8`, `Nat16`, `Nat32`, `Nat64`](https://mops.one/core/docs/)

#### Renamed fields

Expand Down Expand Up @@ -293,7 +295,7 @@ Helper functions have been added, such as `allValues()`, for each finite type in

The `Random` module has been completely redesigned in the core package with a new API that provides better control over random number generation and supports both pseudo-random and cryptographic random number generation.

```motoko
```motoko no-repl
import Random "mo:core/Random";

persistent actor {
Expand Down Expand Up @@ -370,7 +372,7 @@ The new migration pattern allows you to automatically convert existing stable da

The `with migration` syntax follows this structure:

```motoko
```motoko no-repl
(
with migration = func(
state : {
Expand All @@ -389,7 +391,7 @@ persistent actorApp {

It's also possible to use a function defined in an imported module:

```motoko
```motoko no-repl
import { migrate } "Migration";

(with migration = migrate)
Expand All @@ -404,7 +406,7 @@ This pattern ensures that existing stable data is preserved and converted to the

#### Original (`base`)

```motoko
```motoko no-repl
import Buffer "mo:base/Buffer";

persistent actor{
Expand Down Expand Up @@ -433,7 +435,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import List "mo:core/List";

(
Expand Down Expand Up @@ -466,7 +468,7 @@ persistent actorApp {

#### Original (`base`)

```motoko
```motoko no-repl
import Deque "mo:base/Deque";

persistent actor{
Expand All @@ -492,7 +494,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import Deque "mo:base/Deque"; // For migration
import Queue "mo:core/Queue";

Expand Down Expand Up @@ -537,7 +539,7 @@ import Queue "mo:core/Queue";

#### Original (`base`)

```motoko
```motoko no-repl
import HashMap "mo:base/HashMap";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
Expand Down Expand Up @@ -570,7 +572,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import Map "mo:core/Map";
import Text "mo:core/Text";
import Iter "mo:core/Iter";
Expand Down Expand Up @@ -607,7 +609,7 @@ persistent actor{

#### Original (`base`)

```motoko
```motoko no-repl
import OrderedMap "mo:base/OrderedMap";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
Expand All @@ -634,7 +636,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import OrderedMap "mo:base/OrderedMap"; // For migration
import Map "mo:core/Map";
import Text "mo:core/Text";
Expand Down Expand Up @@ -675,7 +677,7 @@ persistent actor{

#### Original (`base`)

```motoko
```motoko no-repl
import OrderedSet "mo:base/OrderedSet";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
Expand Down Expand Up @@ -704,7 +706,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import OrderedSet "mo:base/OrderedSet"; // For migration
import Set "mo:core/Set";
import Text "mo:core/Text";
Expand Down Expand Up @@ -747,7 +749,7 @@ persistent actorApp {

#### Original (`base`)

```motoko
```motoko no-repl
import Trie "mo:base/Trie";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
Expand Down Expand Up @@ -778,7 +780,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import Trie "mo:base/Trie"; // For migration
import Map "mo:core/Map";
import Text "mo:core/Text";
Expand Down Expand Up @@ -816,7 +818,7 @@ persistent actor{

#### Original (`base`)

```motoko
```motoko no-repl
import TrieMap "mo:base/TrieMap";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
Expand Down Expand Up @@ -849,7 +851,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import Map "mo:core/Map";
import Text "mo:core/Text";
import Iter "mo:core/Iter";
Expand Down Expand Up @@ -886,7 +888,7 @@ persistent actor{

#### Original (`base`)

```motoko
```motoko no-repl
import TrieSet "mo:base/TrieSet";
import Text "mo:base/Text";

Expand All @@ -913,7 +915,7 @@ persistent actor{

#### Updated (`core`)

```motoko
```motoko no-repl
import Set "mo:core/Set";
import Text "mo:core/Text";
import Iter "mo:core/Iter";
Expand Down
22 changes: 10 additions & 12 deletions docs/languages/motoko/fundamentals/actors/actors-async.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
sidebar_position: 1
description: "Motoko language documentation"
title: "Actors & async data"
description: "The actor programming model was designed to solve concurrency issues by encapsulating state and computation within independent units called actors."
sidebar:
order: 1
---

The actor programming model was designed to solve concurrency issues by encapsulating [state](/languages/motoko/fundamentals/actors/state) and computation within independent units called **actors**.
The actor programming model was designed to solve concurrency issues by encapsulating [state](./state.md) and computation within independent units called **actors**.

The actor model is built on four key principles:

Expand Down Expand Up @@ -105,7 +106,7 @@ To access the result of an `async` value, the receiver of the future uses an `aw

For example, to use the result of `Counter.read()` above, we can first bind the future to an identifier `a`, and then `await a` to retrieve the underlying [`Nat`](https://mops.one/core/docs/Nat), `n`:

``` motoko no-repl
```motoko no-repl
let a : async Nat = Counter.read();
let n : Nat = await a;
```
Expand All @@ -116,7 +117,7 @@ The second line `await`s this future and extracts the result, a natural number.

Typically, one rolls the two steps into one and just awaits an asynchronous call directly:

``` motoko no-repl
```motoko no-repl
let n : Nat = await Counter.read();
```

Expand All @@ -130,7 +131,7 @@ An `await` will always suspend execution and commit state, even if its future is

When several futures are issued in parallel and racing to complete, it can be more efficient to opt out of the unconditional behavior of `await` and immediately continue with a result when it is available:

``` motoko no-repl
```motoko no-repl
let a : async Nat = CounterA.read();
let b : async Nat = CounterB.read();
let sum : Nat = (await a) + (await? b);
Expand Down Expand Up @@ -177,7 +178,7 @@ A function that does not use `await` runs atomically, meaning nothing else can c

For example, the implementation of `bump()` above is guaranteed to increment and read the value of `count`, in one atomic step. The following alternative implementation does not have the same semantics and allows another client of the actor to interfere with its operation.

``` motoko no-repl
```motoko no-repl
public shared func bump() : async Nat {
await inc();
await read();
Expand Down Expand Up @@ -216,7 +217,7 @@ In other languages without these features, developers often need to use advanced

To demonstrate how asynchronous actors work, consider the following example.

Customers place orders at a pizza restaurant, but the chef can only make one pizza at a time. Orders are taken **[asynchronously](/languages/motoko/fundamentals/actors/actors-async#async--await)**, meaning customers do not have to wait for previous orders to be completed before placing their own. However, each pizza is prepared sequentially. This is representative of an asynchronous actor.
Customers place orders at a pizza restaurant, but the chef can only make one pizza at a time. Orders are taken **[asynchronously](./actors-async.md#async--await)**, meaning customers do not have to wait for previous orders to be completed before placing their own. However, each pizza is prepared sequentially. This is representative of an asynchronous actor.
<!-- TODO(FUTURE): It would be cleaner to use a Deque or Queue pushing new order to the end and popping the next order to make from the front. -->
```motoko no-repl
import Array "mo:core/Array";
Expand Down Expand Up @@ -287,7 +288,7 @@ Use `async*` and `await*` carefully. In Motoko, a regular `await` is a commit po

### Example

``` motoko no-repl
```motoko no-repl
persistent actor class (Logger : actor { log : Text -> async () }) {

var logging = true;
Expand Down Expand Up @@ -376,6 +377,3 @@ When `catch` is used, the `finally` clause is optional. The `catch` block only c
1. Local traps.
2. Pre-await traps in async functions.
3. Traps after `await`.


<img src="https://cdn-assets-eu.frontify.com/s3/frontify-enterprise-files-eu/eyJwYXRoIjoiZGZpbml0eVwvYWNjb3VudHNcLzAxXC80MDAwMzA0XC9wcm9qZWN0c1wvNFwvYXNzZXRzXC8zOFwvMTc2XC9jZGYwZTJlOTEyNDFlYzAzZTQ1YTVhZTc4OGQ0ZDk0MS0xNjA1MjIyMzU4LnBuZyJ9:dfinity:9Q2_9PEsbPqdJNAQ08DAwqOenwIo7A8_tCN4PSSWkAM?width=2400" alt="Logo" width="150" height="150" />
Loading
Loading