# Motoko Base Library Changes

**URL:** <https://forum.dfinity.org/t/motoko-base-library-changes/39766>\
**Category:** Motoko\
**Created:** [January 6, 2025, 6:55pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766 "2025-01-06T18:55:49Z")\
**Posts on this page:** 19\
**Page:** 4

<div class="post-metadata">

**Author:** ![theoman42](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/theoman42/32/23829_2.png) [@theoman42](https://forum.dfinity.org/u/theoman42)\
**Post date:** [August 1, 2025, 1:35am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/61 "2025-08-01T01:35:52Z")

</div>

Hey Ryan, thanks for all the work. I am noticing that the AsyncRandom class in Random.mo doesn’t have all of the fun methods such as **nat64, nat64Range, natRange, intRange** , even though it’s in the documentation [https://internetcomputer.org/docs/motoko/core/Random](https://internetcomputer.org/docs/motoko/core/Random), will this be added soon?

I am using core@0.6.0

Let me know!

---

<div class="post-metadata">

**Author:** ![infu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/infu/32/11321_2.png) [@infu](https://forum.dfinity.org/u/infu)\
**Post date:** [August 1, 2025, 9:11am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/62 "2025-08-01T09:11:26Z")

</div>

Checking the lib out quickly. Looks like

Vector → List

List → Stack, Queue, pure/List

Map and Set look great - Btree based. No need for hashmaps? How do they perform compared to Zhenya’s Map and Set?

Changes are looking great. I like the ‘pure’ libraries idea. Also that there are no classes, just functions. Random libs look great too.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/gekctek/32/6863_2.png) [@Gekctek](https://forum.dfinity.org/u/Gekctek)\
**Post date:** [August 2, 2025, 5:23am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/63 "2025-08-02T05:23:32Z")

</div>

Is there a way to add initial capacity to List like Buffer had. Many times with my code i have an item count estimate/upper bound/exact number, so i would like to be able to use that for efficiency

---

<div class="post-metadata">

**Author:** ![rvanasa](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rvanasa/32/23650_2.png) [@rvanasa](https://forum.dfinity.org/u/rvanasa)\
**Post date:** [August 2, 2025, 6:50am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/64 "2025-08-02T06:50:48Z")

</div>

> [@theoman42](#):
>
> Hey Ryan, thanks for all the work. I am noticing that the AsyncRandom class in Random.mo doesn’t have all of the fun methods such as **nat64, nat64Range, natRange, intRange** , even though it’s in the documentation [https://internetcomputer.org/docs/motoko/core/Random](https://internetcomputer.org/docs/motoko/core/Random), will this be added soon?

Thank you for pointing this out! I opened [this PR](https://github.com/dfinity/motoko-core/pull/360) to add the missing methods.

> [@Gekctek](#):
>
> Is there a way to add initial capacity to List like Buffer had. Many times with my code i have an item count estimate/upper bound/exact number, so i would like to be able to use that for efficiency

There currently isn’t a way to specify an initial capacity for `List` (same as with the original [`Vector`](https://mops.one/vector)). For situations where performance is critical and the maximum size is known beforehand, using a var-array with optional values is going to be the most efficient option. For example:

```motoko
import VarArray "mo:core/VarArray";

let array = VarArray.repeat<?Text>(null, 3);
array[0] := "A";
array[1] := "B";
array[2] := "C";

assert array == [var "A", "B", "C"];

```

We considered adding a wrapper data structure around this pattern into the standard library but decided that this would be better suited for an external Mops package.

It’s worth noting that it is possible to continue using `Buffer` and the other original data structures by importing both `base` and `core` into a project. The goal is to give enough time for the package ecosystem to fill in the gaps before fully dropping support for the original base library.

---

<div class="post-metadata">

**Author:** ![ZenVoich](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/zenvoich/32/5969_2.png) [@ZenVoich](https://forum.dfinity.org/u/ZenVoich)\
**Post date:** [August 2, 2025, 7:43am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/65 "2025-08-02T07:43:15Z")

</div>

Can we get `Array.take` in core also?

 ![image](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/3X/b/4/b424415838e3d5cd85e345621660e2929cc435fb.png)

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [August 2, 2025, 2:30pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/66 "2025-08-02T14:30:47Z")

</div>

> [@Gekctek](#):
>
> Is there a way to add initial capacity to List like Buffer had.

We were thinking of doing that (providing a `reserve` function) but in the end decided against it. The problem is that List has a shrinking logic to free unused space if the List shrinks. Reserving large unused space would interfere with that logic because the logic would try to shrink it again. We didn’t see the performance gain as significant enough to justify the additional complexity. List should be efficient enough even without reservation.

---

<div class="post-metadata">

**Author:** ![DAGroupHQ](https://avatars.discourse-cdn.com/v4/letter/d/f08c70/32.png) [@DAGroupHQ](https://forum.dfinity.org/u/DAGroupHQ)\
**Post date:** [August 11, 2025, 8:31am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/67 "2025-08-11T08:31:17Z")

</div>

Are there any types that are getting deprecated and if so is there a legacy library we will be able to import ? Are there clear instructions regarding this somewhere ?

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [August 11, 2025, 9:38am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/68 "2025-08-11T09:38:56Z")

</div>

AFAIK the `base` library will stay around so that’s your legacy library. In that sense nothing would be “deprecated”.

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [August 12, 2025, 5:02am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/69 "2025-08-12T05:02:22Z")

</div>

I’ve been working on a larger project for several months using the “old” base library. Would it be advisable to upgrade to the new one at this point, or should we continue using the existing version?

---

<div class="post-metadata">

**Author:** ![rvanasa](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rvanasa/32/23650_2.png) [@rvanasa](https://forum.dfinity.org/u/rvanasa)\
**Post date:** [August 12, 2025, 9:40pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/70 "2025-08-12T21:40:53Z")

</div>

We encourage switching to the new `core` package if possible. This will reduce the complexity in the long run when we eventually drop support for the original base library.

Including both `base` and `core` as parallel dependencies is one way to gradually make this transition. LLMs are also beginning to pick up the `core` package and could be useful (with caution) in combination with the [migration guide](https://internetcomputer.org/docs/motoko/base-core-migration).

Let me know if you run into any issues if you end up migrating in case we can assist.

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [August 13, 2025, 5:11am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/71 "2025-08-13T05:11:56Z")

</div>

Thanks for your response. I’m in the final weeks of the project, with a due date at the end of August. I will try to migrate the project. It consists of four different Motoko canisters that work together for various tasks, such as backend services for task management, documentation, user management, indexing, time tracking, and file storage.

---

<div class="post-metadata">

**Author:** ![timo](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/timo/32/5543_2.png) [@timo](https://forum.dfinity.org/u/timo)\
**Post date:** [August 13, 2025, 5:30am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/72 "2025-08-13T05:30:32Z")

</div>

> [@rbole](#):
>
> I’m in the final weeks of the project, with a due date at the end of August.

Are you completely done with everything else? Otherwise I wouldn’t migrate in this time.

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [August 13, 2025, 7:57am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/73 "2025-08-13T07:57:44Z")

</div>

I’m mostly done, but there are still a few small functions that the frontend needs which have to be added.

Today, I tried refactoring a module and realized that migrating will require a significant amount of work. I use OrderedMap and Buffer extensively, and several inter-canister calls from the module functions will also need to be refactored due to the new OrderedMap behavior.

---

<div class="post-metadata">

**Author:** ![rvanasa](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rvanasa/32/23650_2.png) [@rvanasa](https://forum.dfinity.org/u/rvanasa)\
**Post date:** [August 15, 2025, 7:07pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/74 "2025-08-15T19:07:44Z")

</div>

Hello all, we just published version 1.0.0 of the [`core`](https://mops.one/core) package! Formal announcements are on the way, most likely starting next week.

This release includes a few breaking API changes to account for early adopter feedback. Here is the [changelog](https://github.com/dfinity/motoko-core/blob/main/Changelog.md) and [API diff](https://github.com/dfinity/motoko-core/compare/preview-0.6.0...v1.0.0#diff-587c72edd860434a9d8d1a6650f12ea37c0a0dbbfb5493c4c74987093d0c5e0b) for reference.

Let us know if you run into any issues so we can address them prior to the big announcement.

Cheers!

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 17, 2025, 4:23pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/75 "2025-08-17T16:23:26Z")

</div>

Where is my Debug.trap? 😕

Do you all have a better recommended way of handling this? I really don’t want to import Prim.

---

<div class="post-metadata">

**Author:** ![rvanasa](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rvanasa/32/23650_2.png) [@rvanasa](https://forum.dfinity.org/u/rvanasa)\
**Post date:** [August 17, 2025, 4:36pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/76 "2025-08-17T16:36:03Z")

</div>

`Debug.trap()` is now `Runtime.trap()`. We moved it to a separate module so that `Debug` is now specifically for debugging-related functions.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [August 17, 2025, 8:57pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/77 "2025-08-17T20:57:24Z")

</div>

Ahhh….nice…I hadn’t noticed runtime.

---

<div class="post-metadata">

**Author:** ![rvanasa](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rvanasa/32/23650_2.png) [@rvanasa](https://forum.dfinity.org/u/rvanasa)\
**Post date:** [August 22, 2025, 3:38pm UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/78 "2025-08-22T15:38:39Z")

</div>

New forum topic for `core`:

> [@Announcing \`core\`, the new Motoko standard library!](https://forum.dfinity.org/t/announcing-core-the-new-motoko-standard-library/55850):
>
> Hello Motoko devs! As you might have already heard, the Languages team overhauled the Motoko standard library (originally named base) to make it simpler for both humans and AI to understand and write Motoko programs. Relevant links [GitHub repository](https://github.com/dfinity/motoko-core)[Mops package](https://mops.one/core)[Documentation](https://internetcomputer.org/docs/motoko/core/)[Migration guide from base to core](https://internetcomputer.org/docs/motoko/base-core-migration)Summary of changes New imperative and functional data structures. Reworked existing data structures for storing directly in stable memory. Simplified and included missing type conversi…

---

<div class="post-metadata">

**Author:** ![rbole](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rbole/32/1334_2.png) [@rbole](https://forum.dfinity.org/u/rbole)\
**Post date:** [August 28, 2025, 4:48am UTC](https://forum.dfinity.org/t/motoko-base-library-changes/39766/79 "2025-08-28T04:48:20Z")

</div>

I finally managed to migrate all canisters in the project to the new core base library. 👍

[Previous page](https://forum.dfinity.org/t/motoko-base-library-changes/39766.md?page=3)
