Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for functions w/ return values #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions docs/source/scilla-in-depth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ keyword.
end

where ``vname : vtype`` specifies the name and type of each parameter and
multiple parameters are separated by ``,``.
multiple parameters are separated by ``,``.

Once a procedure is defined it is available to be invoked from
transitions and procedures in the rest of the contract file. It is not
Expand All @@ -349,26 +349,50 @@ actual arguments to the procedure:
v2 = ...;
foo v1 v2;

All arguments must be supplied when the procedure is invoked. A
procedure does not return a result.

All arguments must be supplied when the procedure is invoked.

A procedure can return a result. To use this, the user should specify a return
type in the signature and use the ``_return :=`` statement to return a value:

.. code-block:: ocaml

procedure inc (a : UInt32) : Uint32
result = builtin add a one;
_return := result
end

The ``_return :=`` statement breaks control flow and terminates the procedure.
If a procedure contains a return type in its signature, return statements must
be present in all the branches of the code.

The invocation syntax of procedures with return values is the same, but the
user should specify a local variable for the return value:

.. code-block:: ocaml

two = inc one

.. note::

The invocation syntax of library functions and procedures with return
values is the same. Hence, name conflicts are possible when there is a
library function and a procedure with the same name. In this case, the
interpreter will treat such calls as procedure calls.

.. note::

The implicit transition parameters ``_sender``, ``_origin`` and ``_amount`` are
implicitly passed to all the procedures that a transition
calls. There is therefore no need to declare those parameters
explicitly when defining a procedure.

.. note::

Procedure parameters cannot be (or contain) maps. If a procedure
needs to access a map, it is therefore necessary to either make the
procedure directly access the contract field containing the map, or
use a library function to perform the necessary computations on the
map.
Procedure parameters and return type cannot be (or contain) maps. If a
procedure needs to access a map, it is therefore necessary to either make
the procedure directly access the contract field containing the map, or use
a library function to perform the necessary computations on the map.


Expressions
************

Expand Down