You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// A function which takes a closure as an argument and calls it.
// <F> denotes that F is a "Generic type parameter"
fn apply<F, +Drop<F>, impl func: core::ops::FnOnce<F, ()>, +Drop<func::Output>>(f: F) {
// ^ TODO: Try changing this to `Fn`.
f();
}
fn main() {
// A non-copy type.
let greeting: ByteArray = "hello";
let farewell: ByteArray = "goodbye";
// Capture 2 variables: `greeting` by snapshot and
// `farewell` by value.
let diary = || {
// `greeting` is by snapshot: requires `Fn`.
println!("I said {}.", greeting);
// Using farewell by value requires `FnOnce`.
// Convert farewell to uppercase to demonstrate value capture through `into_iter`
let mut iter = farewell.into_iter();
let uppercase: ByteArray = iter
.map(|c| if c >= 'a' {
c - 32
} else {
c
})
.collect();
println!("Then I screamed {}!", uppercase);
};
// Call the function which applies the closure.
apply(diary);
}
error: Failed calculating gas usage, it is likely a call for `gas::withdraw_gas` is missing. Inner error: error from the program registry
Caused by:
0: error from the program registry
1: Error during libfunc specialization of function_call<user@Generated core::ops::function::FnOnce::<{closure@/Users/msaug/workspace/cairo-by-example/listings/functions/closures/input_parameters/src/lib.cairo:22:17: 22:19}, ()>::call>: Could not specialize libfunc `function_call` with generic_args: [user@Generated core::ops::function::FnOnce::<{closure@/Users/msaug/workspace/cairo-by-example/listings/functions/closures/input_parameters/src/lib.cairo:22:17: 22:19}, ()>::call]. Error: Could not find the requested function.
The text was updated successfully, but these errors were encountered:
Bug Report
Cairo version:
scarb 2.9.2+nightly-2025-02-01 (3a752f93d 2025-02-01)
cairo: 2.9.2 (99f0528)
sierra: 1.6.0
On the following code:
The text was updated successfully, but these errors were encountered: