aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-11-21 21:11:43 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2016-11-21 21:11:43 +0800
commit42a84946d2dca1880082a07d6408f5b88b966f9c (patch)
treef271aeae4f2df22762b2718df3392c8b257a104c /docs
parentaa48008cc72c6f44db2cbd30a1bee522be67ecd8 (diff)
downloaddexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar.gz
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar.bz2
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar.lz
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar.xz
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.tar.zst
dexon-solidity-42a84946d2dca1880082a07d6408f5b88b966f9c.zip
Fix function type examples
Diffstat (limited to 'docs')
-rw-r--r--docs/types.rst16
1 files changed, 11 insertions, 5 deletions
diff --git a/docs/types.rst b/docs/types.rst
index b22ad7d4..693e2095 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -314,10 +314,13 @@ followed by the function identifier together in a single ``bytes24`` type.
Example that shows how to use internal function types::
+ pragma solidity ^0.4.5;
+
library ArrayUtils {
// internal functions can be used in internal library functions because
// they will be part of the same code context
function map(uint[] memory self, function (uint) returns (uint) f)
+ internal
returns (uint[] memory r)
{
r = new uint[](self.length);
@@ -327,8 +330,9 @@ Example that shows how to use internal function types::
}
function reduce(
uint[] memory self,
- function (uint) returns (uint) f
+ function (uint x, uint y) returns (uint) f
)
+ internal
returns (uint r)
{
r = self[0];
@@ -336,7 +340,7 @@ Example that shows how to use internal function types::
r = f(r, self[i]);
}
}
- function range(uint length) returns (uint[] memory r) {
+ function range(uint length) internal returns (uint[] memory r) {
r = new uint[](length);
for (uint i = 0; i < r.length; i++) {
r[i] = i;
@@ -346,7 +350,7 @@ Example that shows how to use internal function types::
contract Pyramid {
using ArrayUtils for *;
- function pyramid(uint l) return (uint) {
+ function pyramid(uint l) returns (uint) {
return ArrayUtils.range(l).map(square).reduce(sum);
}
function square(uint x) internal returns (uint) {
@@ -359,6 +363,8 @@ Example that shows how to use internal function types::
Another example that uses external function types::
+ pragma solidity ^0.4.5;
+
contract Oracle {
struct Request {
bytes data;
@@ -377,12 +383,12 @@ Another example that uses external function types::
}
contract OracleUser {
- Oracle constant oracle = 0x1234567; // known contract
+ Oracle constant oracle = Oracle(0x1234567); // known contract
function buySomething() {
oracle.query("USD", oracleResponse);
}
function oracleResponse(bytes response) {
- if (msg.sender != oracle) throw;
+ if (msg.sender != address(oracle)) throw;
// Use the data
}
}