Cascading message replies cause delays that add up, that is true. But that is inherent in the message-based architecture of the IC, not something Motoko can change.
My understanding is that composite queries are already in the local replica but we don’t have a direct way to access in Motoko yet. Maybe I misunderstand that concept, but I think this would make this kind of access easier…at least on the same subnet.
Would it possible to add an optional (likely necessarily synchronous) callback for any declared shared method that would be “reasonably guaranteed to be enqueued/called” (except for in cases when a canister is out of cycles for instance) immediately after that method returns?
Something like the cleanup function that exists for React’s useEffect hook.
What would it take to abstract way Iter
and have an easier syntax when using for
loops?
Being able to write something like this
for (let i = 0; i < 5; i++) {
// Do something
}
Of course, the traditional way using an Iter
would still work. It would just be an abstraction, to get a similar feeling to other languages like Python/JavaScript.
Context: I’m asking this because during the Bootcamp I want students to be able to use for
loops on their first day without having to introduce a more advanced concept like Iter
.
@Seb, C-style for loops are among the most error-prone loop constructs in existence (and discouraged in many modern style guides). Motoko very intentionally does not include them. I don’t think using for (i in range(0, 5))
requires understanding the iterator protocol. For beginners not handicapped by prior Python/JS exposure, I would hope it’s actually easier.
As a worked example: https://m7sm4-2iaaa-aaaab-qabra-cai.ic0.app
Some of this syntax isn’t intuitive, but I’d think this was pretty simple for a beginner. Honestly, I’d forgotten that range was even in Iter.
Sometimes I wish base was just always there and I could just do base.iter.range or base.buffer or base.nat32.toNat. Maybe the compiler could get smart enough to back fill what is actually used?
Edit: I messed up the paste and the example is lost to history…it was basically
import {range} from "mo:base/Iter";
....and then later....
for(thisItem in range(1,5){
x += thisItem;
};
would it be possible to add some kind of pipe operator syntax similar to Elixir? eg:
String.split(String.upcase("Elixir rocks"))
"Elixir rocks" |> String.upcase() |> String.split()
["ELIXIR", "ROCKS"]
Wrote down some thoughts
I’m happy to share that we are getting started on interpolation! The language team also brought up the challenges with stringification, which we also want to tackle, but won’t be in the immediate scope.
Something similar came up in the context of cleaning up side effects (iirc specifically guaranteeing releasing a lock at “the end” of the function), or at least I was reminded by that when reading this article:
Maybe something that could be used to improve Motoko?