I have a mapping address to int. For addresses that are not in the mapping, what is the returned int value…0 or something else?
I guess it will actually throw an error? And I need to use something like state.myMapping[myAdr=0] if I want it to return 0 for addresses non existent in the mapping?
state.myMapping[myAdr=0]
will return 0 as this is the syntax for providing a default value. state.myMapping[myAdr]
will fail if there is no such key. Or Map.lookup(myAdr, state.myMapping)
will return option(int)
so you can decide what to if the key is not existent.
@philipp.chain - one more thing, something like state.myMapping[myAdr=1] will return 1 as expected, but say state.myMapping[myAdr=-1] does not compile. state.myMapping[myAdr=(-1)] compiles but doesn’t work. Is that intended behaviour? I would expect that negative numbers could be returned as well?
You need a space between the =
and the -
or the parser thinks it’s one token.
state.myMapping[myAdr=(-1)]
works as expected for me.
/ Ulf
I am using online IDEs (https://contracts.aepps.com and http://fireeditor.nikitafuchs.de/) and seems both are having issues with CORS trying to reach remote compiler:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://latest.compiler.aepps.com/decode-call-result. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
I am using VIM and the command line compiler, that works just fine!
haha yes, that is nice, but it would also be nice if online compiler worked as well, otherwise what is the point of having it