Most of the CameLIGO syntax follows the OCaml syntax, however, there are a few syntactic shortcuts available in one but not the other.
Consecutive '-' operators
In OCaml, you can do :
But this has been forbidden in CameLIGO, you have to add parentheses instead:
Unary '+' operator
This is possible in OCaml but not CameLIGO :
'type in' statements
In CameLIGO, you can declare types locally to an expression. For example, here is a function returning a list of integers :
Entry point declarations
Although it is possible to execute code at the top-level using e.g.
ligo run test contract.mligo,
a CameLIGO program will need one or more entry points in order to be published as an on-chain contract.
These are "main" functions which can be invoked by sending a transaction to
the blockchain. An entry point must have the type
parameter -> storage -> operation list * storage, where the
must be the same for all entry points in a given contract, but different
entry points will typically use different parameter types.
An entry point will take the value of the parameter passed in the transaction,
and the value of the permanent on-chain storage, and will return a list of new transactions initiated from the contract (i.e. transfers of 0 or more tokens to other contracts or to implicit account addresses), and a new value
for the on-chain storage. The next transaction sent to that contract will use
the updated storage, and so on. In order to provide a pure function that may
consult the storage without modifying it, one can use
@view instead of
@entry. A view can be called by another contract without generating a
transaction (i.e., the call is performed synchronously, instead of returning a delayed transaction which would run after the end of this contract's execution), and the view can return any value (since it cannot produce new transactions nor an updated storage, it simply returns the desired output value).
begin ... end sequences
In OCaml, the last instruction of a
begin ... end sequence can be terminated by a semicolon
;, but not in CameLIGO.
Name punning permits record assignments without repeating the right-hand side if it is the same as the record field name. Although possible in OCaml, this is not yet avaiable in CameLIGO.