Skip to content

Commit

Permalink
Update local-objects-classes.adoc (#2986)
Browse files Browse the repository at this point in the history
Split the code examples into multiple lines to align with the Motoko Style guides.
  • Loading branch information
christyjacob4 authored Dec 12, 2021
1 parent 6922cdf commit ec0d504
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions doc/modules/language-guide/pages/local-objects-classes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,21 @@ To illustrate the role and use of object subtyping in {proglang}, consider imple
[source, motoko]
....
object bumpCounter {
var c = 0; public func bump() : Nat { c += 1; c };
var c = 0;
public func bump() : Nat {
c += 1;
c
};
};
....

The object `bumpCounter` has the following object type, exposing exactly one operation, `bump`:

[source.no-repl, motoko]
....
{ bump : () -> Nat }
{
bump : () -> Nat ;
}
....

This type exposes the most common operation, and one that only permits certain behavior.
Expand Down Expand Up @@ -311,8 +317,14 @@ import Buffer "mo:base/Buffer";
class Counter<X>(init : Buffer.Buffer<X>) {
var buffer = init.clone();
public func add(x : X) : Nat { buffer.add(x); buffer.size() };
public func reset() { buffer := init.clone() };
public func add(x : X) : Nat {
buffer.add(x);
buffer.size()
};
public func reset() {
buffer := init.clone()
};
};
....

Expand Down Expand Up @@ -353,7 +365,7 @@ The constituents of the body marked `public` contribute to the resulting objects

===== Another example: `Bits`

As another example, let's consider the task of walking the bits of a `Nat`ural number. For this example, we could define the following:
As another example, let's consider the task of walking the bits of a natural number (type `Nat`). For this example, we could define the following:

[source, motoko]
....
Expand Down

0 comments on commit ec0d504

Please sign in to comment.