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
example.toit:31:9: error: Argument mismatch for 'List.sort'
Argument '--in-place' was passed with block type, but must be non-block
items.sort --in-place=: | a b | a[1] < b[1] ? 1 : -1
^~~~
Compilation failed
;but here =: seems required;
/opt/tmp/started$ /opt/src/toit/bin/toit.compile -o example example.toit
example.toit:36:38: error: Argument mismatch for 'Map.get'
Method does not take an unnamed block argument, but one was provided
Argument '--if-absent' was passed with non-block type, but must be block
return (base_counts code.size seq).get code
^~~
Compilation failed
By trial and error I figured out how to make it compile but it seems like both situations are the same?
So --in-place is a named boolean argument that you set to true and the block itself is an unnamed block argument. So the correct code is equivalent to this:
items.sort --in-place=true (: | a b | a[1] < b[1] ? 1 : -1)
For the --if-absent case, the argument is a named block argument, so you have to pass it a block. Blocks are stack-allocated and governed by special rules so they cannot outlive the surrounding method activation. You can read more about it here: https://docs.toit.io/language/blocks-and-lambdas.
;but here
=:
seems required;By trial and error I figured out how to make it compile but it seems like both situations are the same?
example.txt
The text was updated successfully, but these errors were encountered: