Skip to content

Commit

Permalink
public function returns true without explicitly return syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Feb 19, 2020
1 parent 8b78105 commit 2b9d760
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import
Alternatively, the contact above can be broken into three files. The ``Pay2PubKeyHash`` contact ``import``\s other two contracts as dependencies.
This allows reusing contracts written by others and forms the basis of contract libraries.

A contract can be instantiated by ``new``. A ``public`` function returns ``true`` if it runs to completion and ``false`` otherwise.
Thus, it can be called from ``require``, which takes boolean expression as input.
A contract can be instantiated by ``new``. A ``public`` function can be called from ``require``, which takes boolean expression as input.

.. code-block:: solidity
Expand Down
21 changes: 21 additions & 0 deletions docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ sCrypt enables developers to define their own functions as exemplified below:
They are only visible within the contract, similar to ``private`` functions in Solidity.

public function
---------------
A public function returns ``true`` if it runs to completion and ``false`` otherwise. Its ``returns`` and ``return`` parts are omitted.
In other words,

.. code-block:: solidity
public function sum(int a) returns (bool) {
require(a == 0);
return true;
}
is shortened to

.. code-block:: solidity
public function sum(int a) {
require(a == 0);
}
``return``
----------
Due to the lack of native ``return`` symantics support in script, a function currently must end with a ``return`` statement and it is the only valid place for a ``return`` statement.
Expand All @@ -28,6 +48,7 @@ This requirement may be relaxed in the future. This is usually not a problem sin
return -a;
}
}
can be rewritten as

.. code-block:: solidity
Expand Down

0 comments on commit 2b9d760

Please sign in to comment.