NEWTON
Asked
4 months ago
15
views
0
I have a question about creating elements via a function vs doing them directly. Here's a small gist: https://gist.github.com/rlkelly/6cc8f4cce06762c3153fc7e3acaf9429
%lang starknet
from starkware.cairo.common.alloc import alloc
struct Foo:
member val: felt
end
func make_foo(value: felt) -> (foo: Foo):
let foo = Foo(
val=value,
)
return (foo)
end
func make_foo_array() -> (entry: Foo*):
let (struct_array : Foo*) = alloc()
let foo0 = make_foo(0)
assert struct_array[0] = foo0
return (struct_array)
end
@external
func test_make_foo{syscall_ptr : felt*, range_check_ptr}():
let (foo_array) = make_foo_array()
return ()
end
# File "starkware/cairo/lang/compiler/preprocessor/preprocessor.py", line 1223, in visit_CodeElementCompoundAssertEq
# starkware.cairo.lang.compiler.preprocessor.preprocessor_error.PreprocessorError: contracts/tests/test_foo.cairo:22:5: Cannot compare '__main__.Foo' and '(foo : __main__.Foo)'.
i'm curious why __main__.Foo
and (foo : __main__.Foo)
are typed differently
it appears like let foo =
and let (foo) =
allocate memory differently
Newton
asked
4 months ago
0
I believe the raw let will evaluate as an expression and the let (foo) will unpack the function return
https://www.cairo-lang.org/docs/how_cairo_works/functions.html#function-arguments-and-return-values
answered
4 months ago
Cairo Lang / StarkNet: What are Revoked references? What is alloc_locals?
How to use get_fp_and_pc in Cairo Lang?
Why does range_check_ptr chek for [0, 2^128) instead of [0, P/2)
Cairo Error: Getting Expected expression of type 'felt', got '__main__.getCurrNumber.Return'
Can tempvar be of a different type, say U256?
Cairo Error: 'range_check_ptr' cannot be used as an implicit return value. Consider using a 'with' statement.
How to make Bitwise operations in Cairo Lang using %builtins bitwise, bitwise_xor?
How to get the contract ABI using Starknet.Py?
How can I send a Uint256 amount of ERC20 tokens from L1 to starknet? And how should I build my payload for "sendMessageToL2" to match the Uint256 format of Cairo?
What are a few of the best apps to test on starknet?
Which is this extension that shows you errors before compilation ser?
I am already running a full Ethereum node on my server. Can I set the PATHFINDER_ETHEREUM_API_URL parameter to my node's endpoint for pathfinder?
What is the inefficiency in this cairo code using alloc_locals
How to generate a proof for a Cairo program and verify it?[StackOverflow]