Placement of `do` in choices
- LucianoOP 2
I find it very confusing that for choices the placement of the
dotoken is handled differently forcontrollerfirst vschoicefirst syntax.With
controllerfirst, you can leave thedoblock at the end of the statement, like so:controller counterparty can Sell : ContractId FinancialContract with obligations: Obligations do ...But with choice first, this doesn’t compile:
choice EnterInto : ContractId MasterAgreement with requestor : Party controller requestor do create MasterAgreement with bearer = requestor, counterpartyBut moving the
doone line down does:choice EnterInto : ContractId MasterAgreement with requestor : Party controller requestor do create MasterAgreement with bearer = requestor, counterpartyIs this intentional? Why this difference?
- Nick_Chapman 2
Yes, this is somewhat unfortunate.
The difference stems from the fact that the older
controller-first syntax includes thecankeyword, which allows the parser to know when the list of controller-parties is finished – because in general there can be multiple controller parties:controller counterparty1, counterparty2 can Sell : ContractId FinancialContract with obligations: Obligations do ...The layout rules of DAML then insert implicit braces to make the party-list explicit. These braces can be provided explicitly if you like, making the following parse valid:
controller { counterparty1, counterparty2 } can Sell : ContractId FinancialContract with obligations: Obligations do ...However, in the newer
choice-first syntax, there is nocankeyword to mark the end of the controller-parties. So the end of the party list (even a singleton list) must be marked either with a line break (allowing layout to do it’s stuff):choice EnterInto : ContractId MasterAgreement with requestor : Party controller requestor do create MasterAgreement with bearer = requestor, counterpartyOr, again, explicit braces may be inserted. Which allows the entire controller declaration on a single line:
choice EnterInto : ContractId MasterAgreement with requestor : Party controller { requestor } do create MasterAgreement with bearer = requestor, counterpartyOr, split after the
do, if you prefer:choice EnterInto : ContractId MasterAgreement with requestor : Party controller { requestor } do create MasterAgreement with bearer = requestor, counterparty - Luciano 1
would this also be solved by allowing a
canin the choice-first syntax? - Nick_Chapman 1
It’s possible having a keyword at this point would also get you the layout you want, without explicit braces. However there are problems with using
canbecause it has the wrong layout behaviour as a consequence of the oldcontroller-first syntax.In the old syntax,
canis is followed by a list of Choice declarations, in braces, explicit or implicit. In the new syntax,canwould be followed by the choice-body expression, which does not have braces. - Levente_Barczy
Hi, for that very reason, I put the
doon the next line in achoicechoice. Also note the double indentedwith:choice MyChoiceName: ContractId SomeTemplate with arg1: Foo party: Party controller party do theThings...Note that this way, the
doblocks line up exactly between the two choices syntaxes.
Luciano:choice EnterInto : ContractId MasterAgreement with requestor : Party controller requestor do create MasterAgreement with bearer = requestor, counterparty