Skip to content

Commit

Permalink
add static function
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Apr 5, 2020
1 parent 377be4c commit c19ba83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ is functionally equivalent to
return true;
}
static function
---------------
A static function can be called with contract name without an instantiated contract, similar to a static function in Javascript or C++.

.. code-block:: solidity
contract Foo {
static function sum(int a, int b) returns (int) {
return a + b;
}
function double(int x) returns (int) {
return this.sum(x, x);
}
}
contract Bar {
public function unlock(int y) {
require(y == Foo.sum(1, 2));
}
}
``return``
----------
Due to the lack of native ``return`` semantics support in script, a function currently must end with a ``return`` statement and it is the only valid place for a ``return`` statement.
Expand Down
2 changes: 1 addition & 1 deletion docs/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Formal Specification
var &::= formal;\\
formal &::= \mathrm{TYPE}\ \mathrm{ID}\\
constructor &::= \mathrm{constructor}([formal[,\ formal]^*])\ \{\ [stmt]^*\ \}\\
function &::= \mathrm{[public]}\ \mathrm{function}\ \mathrm{ID}([formal[,\ formal]^*])\ \mathrm{[returns}\ (\mathrm{TYPE]})\ \{\ [stmt]^*\ \mathrm{[return}\ expr;]\ \}\\
function &::= \mathrm{[public|static]}\ \mathrm{function}\ \mathrm{ID}([formal[,\ formal]^*])\ \mathrm{[returns}\ (\mathrm{TYPE]})\ \{\ [stmt]^*\ \mathrm{[return}\ expr;]\ \}\\
stmt &::= \mathrm{TYPE}\ \mathrm{ID} = expr;\\
&\ \ \ |\ \ \mathrm{ID}\ \mathrm{ID} = \mathrm{new}\ \mathrm{ID}(expr^*);\\
&\ \ \ |\ \ \mathrm{ID} = expr;\\
Expand Down

0 comments on commit c19ba83

Please sign in to comment.