* __Sendable capabilities__. If we want to send references to a different actor, we must make sure that the global and local aliases make the same guarantees. It'd be unsafe to send a `trn` to another actor, since we could possibly hold `box` references locally. Only `iso`, `val`, and `tag` have the same global and local restrictions – all of which are in the main diagonal of the matrix.
* __Ephemeral subtyping__. If we have an ephemeral capability (for instance, `iso^` after consuming an isolated variable), we can be more permissive for the new alias, i.e. remove restrictions, such as allowing local aliases with read capabilities, and receive the reference into a `trn^`; or both read and write, which gives us `ref`. The same is true for more global alias, and we can get `val`, `box`, or `tag`. Visually, this would be equivalent to walking downwards and/or to-the-right starting from the capability in the matrix.
* __Recovering capabilities__. This is when we "lift" a capability, from a mutable reference to `iso` or an immutable reference to `val`. The matrix equivalent would be walking upwards starting from the capability – quite literally lifting in this case.
* __Aliasing__. With a bit more of imagination, it's possible to picture aliasing `iso` and `trn` as reflecting them on the secondary diagonal of the matrix onto `tag` and `box`, respectively. The reason for that lies on which restrictions arise from the local guarantees. An `iso` doesn't allow different aliases to read or write, which `tag` enforces; and `trn` doesn't allow different aliases to write but allows them to do local reads, fitting `box`'s restrictions.

We want to emphasize that trying to apply the reference capability matrix to some capabilities problems is not guaranteed to work (viewpoint adaptation is one example). The matrix is the original definition of the reference capabilities, presented here as a mnemonic device. Whenever you struggle with reference capabilities, we recommend that you reread the corresponding section of this chapter to understand why something is not allowed by the compiler.


592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311


# Example program
The following takes an reverse-alphabetical array of Strings ("third", "second", "first"),
and sorts it in place alphabetically using the default String Comparator.

It outputs:

> first
> second
> third

```pony
use "collections"

actor Main
new create(env:Env) =>
let array = [ "third"; "second"; "first" ]
let sorted_array = Sort[Array[String], String](array)
for e in sorted_array.values() do
env.out.print(e) // prints "first \n second \n third"
end


ts
else
compile_error "perf_end only supported on x86"
end

fun _clock_gettime(clock: _Clock): (I64, I64) =>
"""
Return a clock time on linux and bsd.
"""
ifdef lp64 and (linux or bsd) then
var ts: (I64, I64) = (0, 0)
@clock_gettime(clock(), addressof ts)
ts
elseif ilp32 and (linux or bsd) then
var ts: (I32, I32) = (0, 0)
@clock_gettime(clock(), addressof ts)
(ts._1.i64(), ts._2.i64())
else
compile_error "no clock_gettime"
end


include <string.h>

extern char *get_string()
{
return "hello world\n";
}

extern size_t serialise_space(char *s)
{
// space for the size and the string (without the null)
return 4 + strlen(s);
}

extern void serialise(char *buff, char *s)
{
size_t sz = strlen(s);
unsigned char *ubuff = (unsigned char *) buff;
// write the size as a 32-bit big-endian integer
ubuff[0] = (sz >> 24) & 0xFF;
ubuff[1] = (sz >> 16) & 0xFF;


# Numeric Literals

Numeric literals can be used to encode any signed or unsigned integer or floating point number.

In most cases Pony is able to infer the concrete type of the literal from the context where it is used (e.g. assignment to a field or local variable or as argument to a method/behaviour call).

It is possible to help the compiler determine the concrete type of the literal using a constructor of one of the numeric types:

* `U8`, `U16`, `U32`, `U64`, `U128`, `USize`, `ULong`
* `I8`, `I16`, `I32`, `I64`, `I128`, `ISize`, `ILong`
* `F32`, `F64`

```pony
let my_explicit_unsigned: U32 = 42_000
let my_constructor_unsigned = U8(1)
let my_constructor_float = F64(1.234)
```

Integer literals can be given as decimal, hexadecimal or binary:


812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831


Bool val


412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431


Defining division as partial leads to code littered with `try`s attempting to deal with the possibility of division by zero. Even if you had asserted that your denominator was not zero, you'd still need to protect against divide by zero because, at this time, the compiler can't detect that value dependent typing.

Pony also offers [Unsafe Division](/expressions/arithmetic.md#unsafe-integer-arithmetic), which declares division by zero as undefined, as in C:

```pony
// the value of x is undefined
let x = I64(1) /~ I64(0)
```

But declaring this case as undefined does not help us out here. As a programmer you'd still need to guard that case in order to not poison your program with undefined values or risking terminating your program with a `SIGFPE`. So, in order to maintain a practical API and avoid undefined behaviour, _normal_ division on integers in Pony is defined to be `0`. To avoid `0`s silently creeping through your divisions, use [Partial or Checked Division](/expressions/arithmetic.md#partial-and-checked-arithmetic).


SignedInteger[A: SignedInteger[A, B] val, B: UnsignedInteger[B] val]¶
[Source]
trait val SignedInteger[A: SignedInteger[A, B] val, B: UnsignedInteger[B] val] is
Integer[A] val

Implements¶

Integer[A] val

Constructors¶
create¶
[Source]


"""
A random integer in [-2^15, 2^15)
"""
u16().i16()

fun ref i32(): I32 =>
"""
A random integer in [-2^31, 2^31)
"""
u32().i32()

fun ref i64(): I64 =>
"""
A random integer in [-2^63, 2^63)
"""
u64().i64()

fun ref i128(): I128 =>
"""
A random integer in [-2^127, 2^127)


target: String val

Returns¶

Bool val

set_time_at¶
[Source]
Set the last access and modification times of the directory to the given
values.
fun box set_time_at(
target: String val,
atime: (I64 val , I64 val),
mtime: (I64 val , I64 val))
: Bool val

Parameters¶


fun box ipctl_defttl()
: I32 val

Returns¶

I32 val

ipctl_directedbroadcast¶
[Source]
fun box ipctl_directedbroadcast()
: I32 val

Returns¶

I32 val

ipctl_fastforwarding¶
[Source]


[Source]
Erases content. The direction to erase is dictated by the direction
parameter. Use EraseLeft to erase everything from the cursor to the
beginning of the line. Use EraseLine to erase the entire line. Use
EraseRight to erase everything from the cursor to the end of the line.
The default direction is EraseRight.
fun box erase(
direction: (EraseLeft val | EraseLine val | EraseRight val) = reference)
: String val

Parameters¶

direction: (EraseLeft val | EraseLine val | EraseRight val) = reference

Returns¶

String val

reset¶


"""
Pure Pony implementaton of C macros for investigating
the status returned by `waitpid()`.
"""

fun exited(wstatus: I32): Bool =>
termsig(wstatus) == 0

fun exit_code(wstatus: I32): I32 =>
(wstatus and 0xff00) >> 8

fun signaled(wstatus: I32): Bool =>
((termsig(wstatus) + 1) >> 1).i8() > 0

fun termsig(wstatus: I32): I32 =>
(wstatus and 0x7f)

fun stopped(wstatus: I32): Bool =>
(wstatus and 0xff) == 0x7f


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

u64_unsafe¶
[Source]
fun box u64_unsafe()
: U64 val

Returns¶

U64 val

u128_unsafe¶
[Source]


U64 val

mul_unsafe¶
[Source]
fun box mul_unsafe(
y: U64 val)
: U64 val

Parameters¶

y: U64 val

Returns¶

U64 val

div_unsafe¶
[Source]


Parameters¶

that: ASCIIAllWithNUL val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: ASCIIAllWithNUL val)
: Bool val

Parameters¶

that: ASCIIAllWithNUL val


_count = _count + 1
_iter.next()?
end
end)

fun ref last(): A ? =>
"""
Return the last value of the iterator.


Parameters¶

name: String val

Returns¶

None val

complete_action¶
[Source]
Complete an expected action successfully.
If all expected actions are completed successfully,
the property is considered successful.
If 1 action fails, the property is considered failing.
If the action name was not expected, i.e. was not registered using
expect_action, nothing happens.
fun val complete_action(
name: String val)


fun box ipproto_dstopts()
: I32 val

Returns¶

I32 val

ipproto_egp¶
[Source]
fun box ipproto_egp()
: I32 val

Returns¶

I32 val

ipproto_emcon¶
[Source]


fun box tipc_ok()
: I32 val

Returns¶

I32 val

tipc_published¶
[Source]
fun box tipc_published()
: I32 val

Returns¶

I32 val

tipc_reserved_types¶
[Source]


None val

shift¶
[Source]
Removes the head value, raising an error if the head is empty.
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.shift() end  // Returns "a" and my_list is ["b"; "c"]

fun ref shift()
: A^ ?

Returns¶

A^ ?

append¶
[Source]
Append len elements from a sequence, starting from the given offset.


Returns¶

Bool val

ge¶
[Source]
Returns true if the flags set on this are a superset of the flags set on
that or they are the same. Flags is only partially ordered, so ge is not
the opposite of lt.
fun box ge(
that: Flags[A, B] box)
: Bool val

Parameters¶

that: Flags[A, B] box

Returns¶


[Source]
fun box divc(
y: ILong val)
: (ILong val , Bool val)

Parameters¶

y: ILong val

Returns¶

(ILong val , Bool val)

remc¶
[Source]
fun box remc(
y: ILong val)
: (ILong val , Bool val)


"""
if not_expect is actual then
_fail(_fmt_msg(loc, "Assert isn't failed. " + msg
+ " Expected (" + (digestof not_expect).string() + ") isnt ("
+ (digestof actual).string() + ")"))
return false
end

_runner.log(
_fmt_msg(loc, "Assert isn't passed. " + msg
+ " Got (" + (digestof not_expect).string() + ") isnt ("
+ (digestof actual).string() + ")"),
true)
true

fun assert_eq[A: (Equatable[A] #read & Stringable #read)](
expect: A,
actual: A,
msg: String = "",
loc: SourceLoc = __loc)


new val create()
: FormatFix val^

Returns¶

FormatFix val^

Public Functions¶
eq¶
[Source]
fun box eq(
that: FormatFix val)
: Bool val

Parameters¶

that: FormatFix val

Returns¶


partition¶
[Source]
Builds a pair of lists, the first of which is made up of the elements
satisfying the supplied predicate and the second of which is made up of
those that do not.
fun val partition(
f: {(val->A): Bool}[A] box)
: ((Cons[A] val | Nil[A] val) , (Cons[A] val | Nil[A] val))

Parameters¶

f: {(val->A): Bool}[A] box

Returns¶

((Cons[A] val | Nil[A] val) , (Cons[A] val | Nil[A] val))

drop¶
[Source]


FormatHexBare¶
[Source]
primitive val FormatHexBare is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


(I64 val , Bool val)

divc¶
[Source]
fun box divc(
y: I64 val)
: (I64 val , Bool val)

Parameters¶

y: I64 val

Returns¶

(I64 val , Bool val)

remc¶
[Source]


612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631


fun box ipproto_comp()
: I32 val

Returns¶

I32 val

ipproto_cphb¶
[Source]
fun box ipproto_cphb()
: I32 val

Returns¶

I32 val

ipproto_cpnx¶
[Source]


_set_both(node)
end

fun ref append_node(node: ListNode[A]) =>
"""
Adds a node to the tail of the list.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let new_tail = ListNode[String]("0")
my_list.append_node(new_head) // ["a"; "b"; "c", "0"]
```
"""
match _tail
| let tail': ListNode[A] =>
tail'.append(node)
else
_set_both(node)
end


552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


fun box ipctl_acceptsourceroute()
: I32 val

Returns¶

I32 val

ipctl_defmtu¶
[Source]
fun box ipctl_defmtu()
: I32 val

Returns¶

I32 val

ipctl_defttl¶
[Source]


U128 val ?

fld_unsafe¶
[Source]
fun box fld_unsafe(
y: U128 val)
: U128 val

Parameters¶

y: U128 val

Returns¶

U128 val

mod¶
[Source]


652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671


fun box rds_trans_tcp()
: I32 val

Returns¶

I32 val

rose_access_barred¶
[Source]
fun box rose_access_barred()
: I32 val

Returns¶

I32 val

rose_defer¶
[Source]


FilePermissionDenied val)

eq¶
[Source]
fun box eq(
that: OpenFile val)
: Bool val

Parameters¶

that: OpenFile val

Returns¶

Bool val

ne¶
[Source]


seq.pony

1
2
3
4
5
6
7
8
9
10
11


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311


y: A

Returns¶

A

mod¶
[Source]
fun box mod(
y: A)
: A

Parameters¶

y: A

Returns¶


Readline¶
[Source]
Line editing, history, and tab completion.
class ref Readline is
ANSINotify ref

Implements¶

ANSINotify ref

Constructors¶
create¶


y: A

Returns¶

(A , Bool val)

subc¶
[Source]
Subtract y from this integer and return the result and a flag indicating overflow.
fun box subc(
y: A)
: (A , Bool val)

Parameters¶

y: A

Returns¶


Unsafe operation.
If any input of the operation is +/- infinity or NaN, the result is
undefined.
The operation isn't required to fully comply to IEEE 754 semantics.
"""
this !=~ y

fun lt_unsafe(y: box->A): Bool =>
"""
Unsafe operation.
If any input of the operation is +/- infinity or NaN, the result is
undefined.
The operation isn't required to fully comply to IEEE 754 semantics.
"""
this <~ y

fun le_unsafe(y: box->A): Bool =>
"""
Unsafe operation.
If any input of the operation is +/- infinity or NaN, the result is


v: Vec[A] val

Returns¶

VecKeys[A] ref^

Public Functions¶
has_next¶
[Source]
fun box has_next()
: Bool val

Returns¶

Bool val

next¶
[Source]


y: U8 val

Returns¶

U8 val

div_unsafe¶
[Source]
fun box div_unsafe(
y: U8 val)
: U8 val

Parameters¶

y: U8 val

Returns¶


fun box sctp_selective_ack()
: I32 val

Returns¶

I32 val

sctp_set_debug_level¶
[Source]
fun box sctp_set_debug_level()
: I32 val

Returns¶

I32 val

sctp_set_dynamic_primary¶
[Source]


assert.pony

1
2
3
4
5
6
7
8
9
10
11


DoNotOptimise[U64](_fib(_n))
DoNotOptimise.observe()

fun _fib(n: U64): U64 =>
if n < 2 then 1
else _fib(n - 1) + _fib(n - 2)
end

class iso _Timer is AsyncMicroBenchmark
// Asynchronous benchmark of timer.
let _ts: Timers = Timers
let _ns: U64

new iso create(ns: U64) =>
_ns = ns

fun name(): String =>
"_Timer (" + _ns.string() + " ns)"

fun apply(c: AsyncBenchContinue) =>


fun string(): String iso^ =>
match message
| let m: String =>
recover
let etc = error_type.string()
let err = String(etc.size() + 2 + m.size())
err.append(consume etc)
err.append(": ")
err.append(m)
err
end
else
error_type.string()
end

type ProcessErrorType is
( ExecveError
| PipeError
| ForkError


I32 val ?

mul_partial¶
[Source]
fun box mul_partial(
y: I32 val)
: I32 val ?

Parameters¶

y: I32 val

Returns¶

I32 val ?

div_partial¶
[Source]


: Bool val

Parameters¶

target: String val
mode: FileMode box

Returns¶

Bool val

chownat¶
[Source]
Set the FileMode for some path relative to this directory.
fun box chownat(
target: String val,
uid: U32 val,
gid: U32 val)
: Bool val


primitive I64 is SignedInteger[I64, U64]
new create(value: I64) => value
new from[A: (Number & Real[A] val)](a: A) => a.i64()

new min_value() => -0x8000_0000_0000_0000
new max_value() => 0x7FFF_FFFF_FFFF_FFFF

fun abs(): U64 => if this < 0 then (-this).u64() else this.u64() end
fun bit_reverse(): I64 => @"llvm.bitreverse.i64"(this.u64()).i64()
fun bswap(): I64 => @"llvm.bswap.i64"(this.u64()).i64()
fun popcount(): U64 => @"llvm.ctpop.i64"(this.u64())
fun clz(): U64 => @"llvm.ctlz.i64"(this.u64(), false)
fun ctz(): U64 => @"llvm.cttz.i64"(this.u64(), false)

fun clz_unsafe(): U64 =>
"""
Unsafe operation.
If this is 0, the result is undefined.
"""
@"llvm.ctlz.i64"(this.u64(), true)


ASCIIAll val^

Public Functions¶
apply¶
[Source]
fun box apply()
: String val

Returns¶

String val

eq¶
[Source]
fun box eq(
that: ASCIIAll val)
: Bool val


Debug package¶
Provides facilities to create output to either STDOUT or STDERR that will
only appear when the platform is debug configured. To create a binary with
debug configured, pass the -d flag to ponyc when compiling e.g.:
ponyc -d
Example code¶
use "debug"

actor Main
new create(env: Env) =>
Debug.out("This will only be seen when configured for debug info")
env.out.print("This will always be seen")


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


while (i = i - 1) > 0 do
_sift_down(i, n)
end

fun ref _sift_up(n: USize) =>
var idx = n
try
while true do
let parent_idx = (idx - 1) / 2
if (parent_idx == idx) or not P(_data(idx)?, _data(parent_idx)?) then
break
end
_data.swap_elements(parent_idx, idx)?
idx = parent_idx
end
end

fun ref _sift_down(start: USize, n: USize): Bool =>
var idx = start
try


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


fun box ip_recvdstaddr()
: I32 val

Returns¶

I32 val

ip_recverr¶
[Source]
fun box ip_recverr()
: I32 val

Returns¶

I32 val

ip_recvflowid¶
[Source]


1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131


fun box ipx_rt_8022()
: I32 val

Returns¶

I32 val

ipx_rt_bluebook¶
[Source]
fun box ipx_rt_bluebook()
: I32 val

Returns¶

I32 val

ipx_rt_routed¶
[Source]


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


_available = _available - 1

if offset < data.size() then
node()? = (data, offset)
else
_chunks.shift()?
end
r

fun peek_u8(offset: USize = 0): U8 ? =>
"""
Peek at a U8 at the given offset. Raise an error if there isn't enough
data.
"""
_peek_byte(offset)?

fun peek_i8(offset: USize = 0): I8 ? =>
"""
Peek at an I8.
"""


be _after_iteration_done_cont(e: U64) =>
if _n == _aggregator.iterations then
_bench.after(_after_cont)
else
_bench.before_iteration(_before_iteration_cont)
end

be _after_done_cont(e: U64) =>
_aggregator.complete(_name, _a)

be _fail() =>
_ponybench._fail(_name)

fun ref _gc_next_behavior() =>
@pony_triggergc(@pony_ctx())

class val AsyncBenchContinue
let _run_async: _RunAsync
let _f: {(U64)} val


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


fun box descr()
: String val

Returns¶

String val

required¶
[Source]
Returns true iff this option is required to be present in the command line.
fun box required()
: Bool val

Returns¶

Bool val

help_string¶


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191


fun box ipx_frame_etherii()
: I32 val

Returns¶

I32 val

ipx_frame_none¶
[Source]
fun box ipx_frame_none()
: I32 val

Returns¶

I32 val

ipx_frame_snap¶
[Source]


Constructors¶
from_u64¶
[Source]
new ref from_u64(
x: U64 val = 5489)
: SplitMix64 ref^

Parameters¶

x: U64 val = 5489

Returns¶

SplitMix64 ref^

create¶
[Source]


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48use "collections"
use "promises"

actor Registrar


## Reading from a `ref` variable

A `ref` origin doesn't modify its fields at all. This is because a `ref` origin doesn't make any guarantees that are incompatible with its fields.


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591


Proxy support¶
Using the proxy_via callback in a TCPConnectionNotify it is possible
to implement proxies. The function takes the intended destination host
and service as parameters and returns a 2-tuple of the proxy host and
service.
The proxy TCPConnectionNotify should decorate another implementation of
TCPConnectionNotify passing relevent data through.
Example proxy implementation¶
actor Main
new create(env: Env) =>
MyClient.create(
"example.com", // we actually want to connect to this host
"80",
ExampleProxy.create("proxy.example.com", "80")) // we connect via this proxy

actor MyClient
new create(host: String, service: String, proxy: Proxy = NoProxy) =>
let conn: TCPConnection = TCPConnection.create(
TCPConnectAuth(env.root),
proxy.apply(MyConnectionNotify.create()),


iter.pony

1
2
3
4
5
6
7
8
9
10
11


--ratio=1.039 or -R=1.039
to yield an option value like
cmd.option("ratio").f64() == F64(1.039).
new val f64(
name': String val,
descr': String val = "",
short': (U8 val | None val) = reference,
default': (F64 val | None val) = reference)
: OptionSpec val^

Parameters¶

name': String val
descr': String val = ""
short': (U8 val | None val) = reference
default': (F64 val | None val) = reference

Returns¶

OptionSpec val^


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291


Stringable¶
[Source]
Things that can be turned into a String.
interface box Stringable

Public Functions¶
string¶
[Source]
Generate a string representation of this object.
fun box string()
: String iso^

Returns¶


# Writing a C library for Pony

Writing your own C library for use by Pony is almost as easy as using existing libraries.

Let's look at a complete example of a C function we may wish to provide to Pony. Let's consider a pure Pony implementation of a [Jump Consistent Hash](https://arxiv.org/abs/1406.2294):

```pony
// Jump consistent hashing in Pony, with an inline pseudo random generator
// https://arxiv.org/abs/1406.2294

fun jch(key: U64, buckets: U32): I32 =>
var k = key
var b = I64(0)
var j = I64(0)

while j < buckets.i64() do
b = j
k = (k * 2862933555777941757) + 1
j = ((b + 1).f64() * (I64(1 << 31).f64() / ((k >> 33) + 1).f64())).i64()
end


552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571


env.out.print(pony + " " + pony_hex_escaped + " " + pony_unicode_escape)
for b in pony.values() do
env.out.print(Format.int[U8](b, FormatHex))
end

```

All string literals support multi-line strings:

```pony

let stacked_ponies = "
🐎
🐎
🐎
"
```


if not path.caps(FileRead) or (_fd == -1) then
error
end

let path' = path.path
let fd' = _fd

recover
let list = Array[String]

ifdef posix then
if fd' == -1 then
error
end

let h =
ifdef linux or bsd then
let fd =
@openat(fd', ".".cstring(),
@ponyint_o_rdonly()


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151"""


Parameters¶

n: U32 val = 0

Returns¶

String val

cursor¶
[Source]
Move the cursor to line y, column x. 0 is the same as 1. This indexes from
the top left corner of the screen.
fun box cursor(
x: U32 val = 0,
y: U32 val = 0)
: String val

Parameters¶


# Scheme indicators

The string we give to a `use` command is known as the _specifier_. This consists of a _scheme_ indicator and a _locator_, separated by a colon. The scheme indicator tells the `use` command what we want it to do, for example, the scheme indicator for including a package is "package". If no colon is found within the specifier string then the use command assumes you meant "package".

The following two use commands are exactly equivalent:

```pony
use "foo"
use "package:foo"
```

If you are using a locator string that includes a colon, for example, an absolute path in Windows, then you __have__ to include the "package" scheme specifier:

```pony
use "C:/foo/bar"  // Error, scheme "C" is unknown
use "package:C:/foo/bar"  // OK
```

To allow use commands to be portable across operating systems, and to avoid confusion with escape characters, '/' should always be used as the path separator in use commands, even on Windows.


F64 val

sqrt_unsafe¶
[Source]
Unsafe operation.
If this is negative, the result is undefined.
fun box sqrt_unsafe()
: F64 val

Returns¶

F64 val

cbrt¶
[Source]
fun box cbrt()
: F64 val


fun box ip_dontfrag()
: I32 val

Returns¶

I32 val

ip_drop_membership¶
[Source]
fun box ip_drop_membership()
: I32 val

Returns¶

I32 val

ip_drop_source_membership¶
[Source]


max: USize val = 100

Returns¶

Generator[String val] box

ascii_letters¶
[Source]
Create a generator for strings of ASCII letters,
with a minimum length of min (default: 0)
and a maximum length of max (default: 100).
fun box ascii_letters(
min: USize val = 0,
max: USize val = 100)
: Generator[String val] box

Parameters¶

min: USize val = 0


value: A

Returns¶

B ?


fun box rds_info_first()
: I32 val

Returns¶

I32 val

rds_info_ib_connections¶
[Source]
fun box rds_info_ib_connections()
: I32 val

Returns¶

I32 val

rds_info_iwarp_connections¶
[Source]


"""
let _disposables: Array[DisposableActor] = Array[DisposableActor]
"""
Disosable actors that are disposed of after every round.
"""
var _shrinker: Iterator[T^] = _EmptyIterator[T^]
var _sample_repr: String = ""
var _pass: Bool = true

new create(
p1: Property1[T] iso,
params: PropertyParams,
notify: PropertyResultNotify,
logger: PropertyLogger,
env: Env
) =>
_env = env
_prop1 = consume p1
_params = params
_logger = logger


eq¶
[Source]
fun box eq(
that: CommonPrefix val)
: Bool val

Parameters¶

that: CommonPrefix val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: CommonPrefix val)
: Bool val


452
453
454
455
456use "signals"
use "files"
use @pony_os_errno[I32]()
use @ponyint_wnohang[I32]() if posix
use @ponyint_win_process_create[USize](appname: Pointer[U8] tag,
cmdline: Pointer[U8] tag, environ: Pointer[U8] tag, wdir: Pointer[U8] tag,
stdin_fd: U32, stdout_fd: U32, stderr_fd: U32,
error_code: Pointer[U32], error_msg: Pointer[Pointer[U8]] tag)
use @ponyint_win_process_wait[I32](hProc: USize, code: Pointer[I32])
use @ponyint_win_process_kill[I32](hProc: USize)
use @execve[I32](path: Pointer[U8] tag, argp: Pointer[Pointer[U8] tag] tag,
envp: Pointer[Pointer[U8] tag] tag)
use @fork[I32]()
use @chdir[I32](path: Pointer[U8] tag)
use @dup2[I32](fildes: U32, fildes2: U32)
use @write[ISize](fd: U32, buf: Pointer[U8] tag, size: USize)


Iterator[A] ref^

compare¶
[Source]
fun box compare(
that: HashSet[A, H] box)
: (Less val | Equal val | Greater val)

Parameters¶

that: HashSet[A, H] box

Returns¶

(Less val | Equal val | Greater val)

ne¶
[Source]


fun box mknodat()
: U64 val

Returns¶

U64 val

renameat¶
[Source]
fun box renameat()
: U64 val

Returns¶

U64 val

symlinkat¶
[Source]


452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191


I16 val

i32¶
[Source]
fun box i32()
: I32 val

Returns¶

I32 val

i64¶
[Source]
fun box i64()
: I64 val

Returns¶


fun fld(y: I128): I128 => _SignedArithmetic.fld[I128, U128](this, y)

fun fld_unsafe(y: I128): I128 =>
_SignedUnsafeArithmetic.fld_unsafe[I128, U128](this, y)

fun mod(y: I128): I128 =>
_SignedArithmetic.mod[I128, U128](this, y)

fun mod_unsafe(y: I128): I128 =>
_SignedUnsafeArithmetic.mod_unsafe[I128, U128](this, y)

fun hash(): USize => u128().hash()
fun hash64(): U64 => u128().hash64()

fun string(): String iso^ =>
_ToString._u128(abs().u128(), this < 0)

fun mul(y: I128): I128 =>
(u128() * y.u128()).i128()


ascii(min, max, ASCIIPrintable)

fun ascii_numeric(
min: USize = 0,
max: USize = 100)
: Generator[String]
=>
"""
Create a generator for strings of numeric ASCII characters,
with a minimum length of `min` (default: 0)
and a maximum length of `max` (default: 100).
"""
ascii(min, max, ASCIIDigits)

fun ascii_letters(
min: USize = 0,
max: USize = 100)
: Generator[String]
=>
"""


Bool val

shuffle[T: T]¶
[Source]
fun ref shuffle[T: T](
array: Array[T] ref)
: None val

Parameters¶

array: Array[T] ref

Returns¶

None val


1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311


Returns¶

I16 val

i32_unsafe¶
fun box i32_unsafe()
: I32 val

Returns¶

I32 val

i64_unsafe¶
fun box i64_unsafe()
: I64 val

Returns¶


fun fld_partial(y: ISize): ISize ? =>
_SignedPartialArithmetic.fld_partial[ISize, USize](this, y)?

fun mod_partial(y: ISize): ISize ? =>
_SignedPartialArithmetic.mod_partial[ISize, USize](this, y)?

primitive I128 is SignedInteger[I128, U128]
new create(value: I128) => value
new from[A: (Number & Real[A] val)](a: A) => a.i128()

new min_value() => -0x8000_0000_0000_0000_0000_0000_0000_0000
new max_value() => 0x7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF

fun abs(): U128 => if this < 0 then (-this).u128() else this.u128() end
fun bit_reverse(): I128 => @"llvm.bitreverse.i128"(this.u128()).i128()
fun bswap(): I128 => @"llvm.bswap.i128"(this.u128()).i128()
fun popcount(): U128 => @"llvm.ctpop.i128"(this.u128())
fun clz(): U128 => @"llvm.ctlz.i128"(this.u128(), false)
fun ctz(): U128 => @"llvm.cttz.i128"(this.u128(), false)


actor Main
new create(env:Env) =>
try
let ini_file = File(FilePath(FileAuth(env.root), "example.ini"))
let sections = IniParse(ini_file.lines())?
for section in sections.keys() do
env.out.print("Section name is: " + section)
for key in sections(section)?.keys() do
env.out.print(key + " = " + sections(section)?(key)?)
end
end
end

Public Types¶

primitive Ini
type IniError
primitive IniIncompleteSection
type IniMap
primitive IniNoDelimiter


# Object Capabilities

Pony's capabilities-secure type system is based on the object-capability model. That sounds complicated, but really it's elegant and simple. The core idea is this:

> A capability is an unforgeable token that (a) designates an object and (b) gives the program the authority to perform a specific set of actions on that object.

So what's that token? It's an address. A pointer. A reference. It's just... an object.


1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231


fun box i16()
: I16 val

Returns¶

I16 val

i32¶
[Source]
fun box i32()
: I32 val

Returns¶

I32 val

i64¶
[Source]


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


There are a lot of functions in List. The following code picks out a few common examples.
It outputs:
A new empty list has 0 nodes.
Adding one node to our empty list means it now has a size of 1.
The first (index 0) node has the value: A single String
A list created by appending our second single-node list onto our first has size: 2
The List nodes of our first list are now:
A single String
Another String
Append *moves* the nodes from the second list so that now has 0 nodes.
A list created from an array of three strings has size: 3
First
Second
Third
Mapping over our three-node list produces a new list of size: 3
Each node-value in the resulting list is now far more exciting:
First BOOM!
Second BOOM!
Third BOOM!
Filtering our three-node list produces a new list of size: 2


mkdir¶
[Source]
Creates the directory. Will recursively create each element. Returns true
if the directory exists when we're done, false if it does not. If we do not
have the FileStat permission, this will return false even if the directory
does exist.
fun val mkdir(
must_create: Bool val = false)
: Bool val

Parameters¶

must_create: Bool val = false

Returns¶

Bool val

remove¶


Parameters¶

sock: UDPSocket ref
data: Array[U8 val] iso
from: NetAddress val

Returns¶

None val

closed¶
[Source]
Called when the socket is closed.
fun ref closed(
sock: UDPSocket ref)
: None val

Parameters¶


592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611


_ptr._offset(src_idx)._copy_to(dst._ptr._offset(dst_idx), len)

if dst._size < (dst_idx + len) then
dst._size = dst_idx + len
end

fun ref remove(i: USize, n: USize) =>
"""
Remove n elements from the array, beginning at index i.
"""
if i < _size then
let count = n.min(_size - i)
_size = _size - count
_ptr._offset(i)._delete(count, _size - i)
end

fun ref clear() =>
"""
Remove all elements from the array.
"""


fun box so_select_err_queue()
: I32 val

Returns¶

I32 val

so_setclp¶
[Source]
fun box so_setclp()
: I32 val

Returns¶

I32 val

so_setfib¶
[Source]


772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791


match l
| let cons: Cons[A] =>
_flat_map[B](cons.tail(), f, _rev_prepend[B](f(cons.head()), acc))
else
acc.reverse()
end

fun tag _rev_prepend[B](l: List[B], target: List[B]): List[B] =>
"""
Prepends l in reverse order onto target
"""
match l
| let cns: Cons[B] =>
_rev_prepend[B](cns.tail(), target.prepend(cns.head()))
else
target
end

fun val for_each(f: {(val->A)} box) =>
"""


from: AmbientAuth val

Returns¶

ApplyReleaseBackpressureAuth val^

Public Functions¶
eq¶
[Source]
fun box eq(
that: ApplyReleaseBackpressureAuth val)
: Bool val

Parameters¶

that: ApplyReleaseBackpressureAuth val

Returns¶


Bool val

lt¶
[Source]
fun box lt(
y: box->A)
: Bool val

Parameters¶

y: box->A

Returns¶

Bool val

le¶


Bool val

llp64¶
[Source]
fun box llp64()
: Bool val

Returns¶

Bool val

ilp32¶
[Source]
fun box ilp32()
: Bool val

Returns¶


if idx_del <= mask then
return (idx_del, false)
else
return (idx, false)
end
| _MapDeleted =>
if idx_del > mask then
idx_del = idx
end
end

idx = (h + ((i + (i * i)) / 2)) and mask
end
end

(idx_del, false)

fun ref _resize(len: USize) =>
"""
Change the available space.


class MyUDPNotify is UDPNotify
fun ref received(
sock: UDPSocket ref,
data: Array[U8] iso,
from: NetAddress)
=>
sock.write(consume data, from)

fun ref not_listening(sock: UDPSocket ref) =>
None

actor Main
new create(env: Env) =>
UDPSocket(UDPAuth(env.root),
MyUDPNotify, "", "8989")

The client is implemented like this:
use "net"

class MyUDPNotify is UDPNotify


"""
The Generator for the first argument to your `property3` method.
"""

fun gen2(): Generator[T2]
"""
The Generator for the second argument to your `property3` method.
"""

fun gen3(): Generator[T3]
"""
The Generator for the third argument to your `property3` method.
"""

fun gen(): Generator[(T1, T2, T3)] =>
Generators.zip3[T1, T2, T3](
gen1(),
gen2(),
gen3())


num_samples': USize val = 100
seed': U64 val = call
max_shrink_rounds': USize val = 10
max_generator_retries': USize val = 5
timeout': U64 val = 60000000000
async': Bool val = false

Returns¶

PropertyParams val^

Public fields¶
let seed: U64 val¶
[Source]

let num_samples: USize val¶
[Source]


fun box sctp_cc_rfc2581()
: I32 val

Returns¶

I32 val

sctp_cc_rtcc¶
[Source]
fun box sctp_cc_rtcc()
: I32 val

Returns¶

I32 val

sctp_closed¶
[Source]


Returns¶

Bool val

eq¶
[Source]
Return true if this address is that address.
fun tag eq(
that: Pointer[A] tag)
: Bool val

Parameters¶

that: Pointer[A] tag

Returns¶

Bool val


"""
try
_index = 0
var x = _state(0)?
var i: USize = 0

while i < _m() do
x = _lower(i, x)?
i = i + 1
end

x = _state(_m())?
i = _m()

while i < _n1() do
x = _upper(i, x)?
i = i + 1
end

_wrap()?


Resume reading on file descriptor.
"""
match near_fd
| _stdout.near_fd => _pending_reads(_stdout)
| _stderr.near_fd => _pending_reads(_stderr)
end

fun ref _write_final(data: ByteSeq) =>
"""
Write as much as possible to the pipe if it is open and there are no
pending writes. Save everything unwritten into _pending and apply
backpressure.
"""
if (not _closed) and not _stdin.is_closed() and (_pending.size() == 0) then
// Send as much data as possible.
(let len, let errno) = _stdin.write(data, 0)

if len == -1 then // write error
if errno == _EAGAIN() then
// Resource temporarily unavailable, send data later.


[Source]
Generate a value and also return a shrink result,
even if the generator does not return any when calling generate.
fun box generate_and_shrink(
rnd: Randomness ref)
: (T^ , Iterator[T^] ref) ?

Parameters¶

rnd: Randomness ref

Returns¶

(T^ , Iterator[T^] ref) ?

iter¶
[Source]
fun box iter(
rnd: Randomness ref)


y: box->A)
: Bool val

Parameters¶

y: box->A

Returns¶

Bool val

ge¶
[Source]
fun box ge(
y: box->A)
: Bool val

Parameters¶


Ini¶
[Source]
A streaming parser for INI formatted lines of test.
primitive val Ini

Constructors¶
create¶
[Source]
new val create()
: Ini val^

Returns¶


[Source]
fun box mul_unsafe(
y: ILong val)
: ILong val

Parameters¶

y: ILong val

Returns¶

ILong val

div_unsafe¶
[Source]
fun box div_unsafe(
y: ILong val)
: ILong val


It's also possible to use a _capture list_ to create new names for things. A capture list is a second parenthesised list after the parameters:

```pony
new create(env:Env) =>
foo({(s: String)(myenv = env) => myenv.out.print(s) })
```

The type of a lambda is also declared using curly brackets. Within the brackets, the function parameter types are specified within parentheses followed by an optional colon and return type. The example above uses `{(String)}` to be the type of a lambda function that takes a `String` as an argument and returns nothing.

If the lambda object is not declared with a specific reference capability, the reference capability is inferred from the structure of the lambda. If the lambda does not have any captured references, it will be `val` by default; if it does have captured references, it will be `ref` by default. The following is an example of a `val` lambda object:

```pony
use "collections"

actor Main
new create(env:Env) =>
let l = List[U32]
l.>push(10).>push(20).>push(30).push(40)
let r = reduce(l, 0, {(a:U32, b:U32): U32 => a + b })


Randomness¶
[Source]
Source of randomness, providing methods for generatic uniformly distributed
values from a given closed interval: [min, max]
in order for the user to be able to generate every possible value for a given
primitive numeric type.
All primitive number method create numbers in range [min, max)
class ref Randomness

Constructors¶
create¶
[Source]
new ref create(


The Generator for the first argument to your property3 method.
fun box gen1()
: Generator[T1] box

Returns¶

Generator[T1] box

gen2¶
[Source]
The Generator for the second argument to your property3 method.
fun box gen2()
: Generator[T2] box

Returns¶

Generator[T2] box


fun box i64_unsafe()
: I64 val

Returns¶

I64 val

i128_unsafe¶
[Source]
fun box i128_unsafe()
: I128 val

Returns¶

I128 val

ilong_unsafe¶
[Source]


fun box rds_info_recv_messages()
: I32 val

Returns¶

I32 val

rds_info_retrans_messages¶
[Source]
fun box rds_info_retrans_messages()
: I32 val

Returns¶

I32 val

rds_info_send_messages¶
[Source]


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91


USize val

space¶
[Source]
Returns the space available for data, not including the null terminator.
fun box space()
: USize val

Returns¶

USize val

reserve¶
[Source]
Reserve space for len bytes. An additional byte will be reserved for the
null terminator.
fun ref reserve(
len: USize val)


if _idx == leaves.size() then
_leaf_nodes.shift()?
_idx = 0
end
(_i = _i + 1, v)


next'()?
else
error
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


else
(let r, let o) =
@"llvm.ssub.with.overflow.i64"(this.i64(), y.i64())
(r.ilong(), o)
end

fun mulc(y: ILong): (ILong, Bool) =>
ifdef ilp32 or llp64 then
(let r, let o) =
@"llvm.smul.with.overflow.i32"(this.i32(), y.i32())
(r.ilong(), o)
else
_SignedCheckedArithmetic._mul_checked[ULong, ILong](this, y)
end

fun divc(y: ILong): (ILong, Bool) =>
_SignedCheckedArithmetic.div_checked[ILong, ULong](this, y)

fun remc(y: ILong): (ILong, Bool) =>
_SignedCheckedArithmetic.rem_checked[ILong, ULong](this, y)


y: ULong val

Returns¶

ULong val

op_or¶
[Source]
fun box op_or(
y: ULong val)
: ULong val

Parameters¶

y: ULong val

Returns¶


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291


"""
"<" + _name + ">"

fun deb_string(): String =>
_name + "[" + _typ.string() + "]" +
if not _required then "(=" + _default.string() + ")" else "" end

class _StringSeq is ReadSeq[String]
"""
_StringSeq is a wrapper / helper class for working with String sequence
values while parsing. It assists in collecting the strings as they are
parsed, and producing a ReadSeq[String] as a result.
"""
let strings: pc.Vec[String]

new val empty() =>
strings = pc.Vec[String]

new val from_string(s: String) =>
strings = (pc.Vec[String]).push(s)


852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871


FileTime¶
[Source]
primitive val FileTime

Constructors¶
create¶
[Source]
new val create()
: FileTime val^

Returns¶

FileTime val^


CapRights0¶
[Source]
Version 0 of the capsicum cap_rights_t structure.
class ref CapRights0

Constructors¶
create¶
[Source]
Initialises with no rights.
new ref create()
: CapRights0 ref^

Returns¶


192
193
194use @pony_asio_event_create[AsioEventID](owner: AsioEventNotify, fd: U32,
flags: U32, nsec: U64, noisy: Bool)
use @pony_asio_event_unsubscribe[None](event: AsioEventID)
use @pony_asio_event_destroy[None](event: AsioEventID)
use @pony_os_stdin_read[USize](buffer: Pointer[U8] tag, size: USize)

interface InputNotify
"""
Notification for data arriving via an input stream.
"""
fun ref apply(data: Array[U8] iso) =>
"""
Called when data is available on the stream.
"""
None

fun ref dispose() =>
"""


exclusion_group¶
fun box exclusion_group()
: String val

Returns¶

String val

timed_out¶
fun ref timed_out(
h: TestHelper val)
: None val

Parameters¶

h: TestHelper val

Returns¶


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371


fun box exattr_list()
: U64 val

Returns¶

U64 val

exattr_set¶
[Source]
fun box exattr_set()
: U64 val

Returns¶

U64 val

acl_check¶
[Source]


end

fun f64(): F64 =>
if this == 0 then
return 0
end

var a = this
let sd = bitwidth() - clz()
var e = (sd - 1).u64()

if sd > 53 then
match sd
| 54 => a = a << 1
| 55 => None
else
a = (a >> (sd - 55)) or
if (a and (-1 >> ((bitwidth() + 55) - sd))) != 0 then 1 else 0 end
end


fun bright_cyan(): String =>
"""
Bright cyan text.
"""
"\x1B[96m"

fun bright_grey(): String =>
"""
Bright grey text.
"""
"\x1B[37m"

fun black_bg(): String =>
"""
Black background.
"""
"\x1B[40m"

fun red_bg(): String =>


Raise the signal.
"""
SignalRaise(_sig)

be dispose() =>
"""
Dispose of the signal handler.
"""
_dispose()

be _event_notify(event: AsioEventID, flags: U32, arg: U32) =>
"""
Called when the signal is received, or when the AsioEventID can be
destroyed.
"""
if AsioEvent.disposable(flags) then
@pony_asio_event_destroy(event)
elseif event is _event then
if not _notify(arg) then
_dispose()


fun box rose_ship_absent()
: I32 val

Returns¶

I32 val

rose_t1¶
[Source]
fun box rose_t1()
: I32 val

Returns¶

I32 val

rose_t2¶
[Source]


# Use for external libraries

To link an external library to Pony code another variant of the use command is used. The `lib` specifier is used to tell the compiler you want to link to a library. For example:

```pony
use "lib:foo"
```

As with other `use` commands a condition may be specified. This is particularly useful when the library has slightly different names on different platforms.

Here's a real example from the standard library:

```pony
use "path:/usr/local/opt/libressl/lib" if osx
use "lib:ssl" if not windows
use "lib:crypto" if not windows
use "lib:libssl-32" if windows
use "lib:libcrypto-32" if windows

use @SSL_load_error_strings[None]()


Bool val

x86¶
[Source]
fun box x86()
: Bool val

Returns¶

Bool val

arm¶
[Source]
fun box arm()
: Bool val

Returns¶


# Structs are "classes for FFI"

A `struct` is a class like mechanism used to pass data back and forth with C code via Pony's Foreign Function Interface.

Like classes, Pony structs can contain both fields and methods. Unlike classes, Pony structs have the same binary layout as C structs and can be transparently used in C functions.  Structs do not have a type descriptor, which means they cannot be used in algebraic types or implement traits/interfaces.


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451


fun box u32()
: U32 val

Returns¶

U32 val

u64¶
[Source]
fun box u64()
: U64 val

Returns¶

U64 val

u128¶
[Source]


fun box divrem(
y: I8 val)
: (I8 val , I8 val)

Parameters¶

y: I8 val

Returns¶

(I8 val , I8 val)

rem¶
[Source]
fun box rem(
y: I8 val)
: I8 val

Parameters¶


972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991


Second BOOM!
Third BOOM!
Filtering our three-node list produces a new list of size: 2
Second BOOM!
Third BOOM!
The size of our first partitioned list (matches predicate): 1
The size of our second partitioned list (doesn't match predicate): 1
Our matching partition elements are:
Second BOOM!

```pony
use "collections"

actor Main
new create(env:Env) =>

// Create a new empty List of type String
let my_list = List[String]()

env.out.print("A new empty list has " + my_list.size().string() + " nodes.") // 0


: String val

Returns¶

String val

grey_bg¶
[Source]
Grey background.
fun box grey_bg()
: String val

Returns¶

String val

white_bg¶
[Source]


The full list of infix operators that are aliases for functions is:

---

| Operator | Method         | Description                   | Note                           |
| -------- | -------------- | ----------------------------- | ------------------------------ |
| `+`      | `add()`          | Addition                      |
| `-`      | `sub()`          | Subtraction                   |
| `*`      | `mul()`          | Multiplication                |
| `/`      | `div()`          | Division                      |
| `%`      | `rem()`          | Remainder                     |
| `%%`     | `mod()`          | Modulo                        | Starting with version `0.26.1` |
| `<<`     | `shl()`          | Left bit shift                |
| `>>`     | `shr()`          | Right bit shift               |
| `and`    | `op_and()`       | And, both bitwise and logical |
| `or`     | `op_or()`        | Or, both bitwise and logical  |
| `xor`    | `op_xor()`       | Xor, both bitwise and logical |
| `==`     | `eq()`           | Equality                      |
| `!=`     | `ne()`           | Non-equality                  |


"""
Set the last access and modification times of the directory to now.
"""
_FileDes.touch(_fd, path)

fun set_time(atime: (I64, I64), mtime: (I64, I64)): Bool =>
"""
Set the last access and modification times of the directory to the given
values.
"""
_FileDes.set_time(_fd, path, atime, mtime)

fun ref lines(): FileLines =>
"""
Returns an iterator for reading lines from the file.
"""
FileLines(this)

fun ref dispose() =>
"""


752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771


y: A

Returns¶

A ?

divrem_partial¶
[Source]
fun box divrem_partial(
y: A)
: (A , A) ?

Parameters¶

y: A

Returns¶


fun box ip_unicast_if()
: I32 val

Returns¶

I32 val

ip_xfrm_policy¶
[Source]
fun box ip_xfrm_policy()
: I32 val

Returns¶

I32 val

local_connwait¶
[Source]


1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111


that: ForkError val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: ForkError val)
: Bool val

Parameters¶

that: ForkError val

Returns¶


552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571


copysign¶
[Source]
fun box copysign(
sign: F32 val)
: F32 val

Parameters¶

sign: F32 val

Returns¶

F32 val

hash¶
[Source]
fun box hash()
: USize val


| 180 => 1087 | 181 => 1091 | 182 => 1093 | 183 => 1097 | 184 => 1103
| 185 => 1109 | 186 => 1117 | 187 => 1123 | 188 => 1129 | 189 => 1151
| 190 => 1153 | 191 => 1163 | 192 => 1171 | 193 => 1181 | 194 => 1187
| 195 => 1193 | 196 => 1201 | 197 => 1213 | 198 => 1217 | 199 => 1223
| 200 => 1229 | 201 => 1231 | 202 => 1237 | 203 => 1249 | 204 => 1259
| 205 => 1277 | 206 => 1279 | 207 => 1283 | 208 => 1289 | 209 => 1291
| 210 => 1297 | 211 => 1301 | 212 => 1303 | 213 => 1307 | 214 => 1319
| 215 => 1321 | 216 => 1327 | 217 => 1361 | 218 => 1367 | 219 => 1373
| 220 => 1381 | 221 => 1399 | 222 => 1409 | 223 => 1423 | 224 => 1427
| 225 => 1429 | 226 => 1433 | 227 => 1439 | 228 => 1447 | 229 => 1451
| 230 => 1453 | 231 => 1459 | 232 => 1471 | 233 => 1481 | 234 => 1483
| 235 => 1487 | 236 => 1489 | 237 => 1493 | 238 => 1499 | 239 => 1511
| 240 => 1523 | 241 => 1531 | 242 => 1543 | 243 => 1549 | 244 => 1553
| 245 => 1559 | 246 => 1567 | 247 => 1571 | 248 => 1579 | 249 => 1583
| 250 => 1597 | 251 => 1601 | 252 => 1607 | 253 => 1609 | 254 => 1613
| 255 => 1619
else 0
end

fun _low_prime_table_size(): USize => 256


Returns¶

Bool val

chmod¶
[Source]
Set the FileMode for a path.
fun box chmod(
mode: FileMode box)
: Bool val

Parameters¶

mode: FileMode box

Returns¶

Bool val


### Example

```pony
Iter[I64]([1; 2; 3; 4; 5; 6].values())
.skip(3)
```
`4 5 6`

```pony
Iter[I64]([1; 2; 3].values())
.skip(3)
.has_next()
```
`false`
"""
var c = n
try
while _iter.has_next() and (c > 0) do
_iter.next()?
c = c - 1


fun box ipproto_carp()
: I32 val

Returns¶

I32 val

ipproto_cftp¶
[Source]
fun box ipproto_cftp()
: I32 val

Returns¶

I32 val

ipproto_chaos¶
[Source]


data: F32 val)
: None val

Parameters¶

data: F32 val

Returns¶

None val

f32_be¶
[Source]
Write an F32 to the buffer in big-endian byte order.
fun ref f32_be(
data: F32 val)
: None val

Parameters¶


[Source]
Unsafe operation.
If any input or output of the operation is +/- infinity or NaN, the result
is undefined.
The operation isn't required to fully comply to IEEE 754 semantics.
fun box divrem_unsafe(
y: A)
: (A , A)

Parameters¶

y: A

Returns¶

(A , A)

rem_unsafe¶
[Source]


that: ExecveError val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: ExecveError val)
: Bool val

Parameters¶

that: ExecveError val

Returns¶


let qpc = pc._1.u64() or (pc._2.u64() << 32)
(qpc, qpf)
else
compile_error "no QueryPerformanceCounter"
end


792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811


I128 val

op_not¶
[Source]
fun box op_not()
: I128 val

Returns¶

I128 val

add¶
[Source]
fun box add(
y: I128 val)
: I128 val

Parameters¶


fun box shr_unsafe(
y: U32 val)
: I32 val

Parameters¶

y: U32 val

Returns¶

I32 val

string¶
[Source]
fun box string()
: String iso^

Returns¶


ListNodes[A, this->ListNode[A] ref] ref^

values¶
[Source]
Return an iterator on the values in the List in forward order.
let my_list = List[String].from(["a"; "b"; "c"])
let values = my_list.values()  // value "a" is before value "c"

fun box values()
: ListValues[A, this->ListNode[A] ref] ref^

Returns¶

ListValues[A, this->ListNode[A] ref] ref^

rvalues¶
[Source]


A ?

mul_partial¶
[Source]
fun box mul_partial(
y: A)
: A ?

Parameters¶

y: A

Returns¶

A ?

div_partial¶


y: U8 val

Returns¶

(U8 val , Bool val)

mulc¶
[Source]
fun box mulc(
y: U8 val)
: (U8 val , Bool val)

Parameters¶

y: U8 val

Returns¶


A

asin¶
[Source]
fun box asin()
: A

Returns¶

A

atan¶
[Source]
fun box atan()
: A

Returns¶


reverse.pony

1
2
3
4
5
6
7
8
9
10
11


params: PropertyParams val,
notify: PropertyResultNotify val,
logger: PropertyLogger val,
env: Env val)
: PropertyRunner[T] tag^

Parameters¶

p1: Property1[T] iso
params: PropertyParams val
notify: PropertyResultNotify val
logger: PropertyLogger val
env: Env val

Returns¶

PropertyRunner[T] tag^

Public Behaviours¶


832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851


fun box u128_unsafe()
: U128 val

Returns¶

U128 val

ulong_unsafe¶
[Source]
fun box ulong_unsafe()
: ULong val

Returns¶

ULong val

usize_unsafe¶
[Source]


U64(0xA)
"0xA"
]
```

Here `my_stringable_array` is coerced to `Array[Stringable] ref`. This works because `Stringable` is a trait that both `String` and `U64` implement.

It is also possible to return an array with a different [Reference Capability](/reference-capabilities/index.md) than `ref` just by specifying it on the type:

```pony
let my_immutable_array: Array[Stringable] val =
[
U64(0xBEEF)
"0xBEEF"
]
```

This way array literals can be used for creating arrays of any [Reference Capability](/reference-capabilities/index.md).


read_int[A: ((I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Integer[A] val)]¶
[Source]
Read an integer from the specified location in this string. The integer
value read and the number of bytes consumed are reported.
The base parameter specifies the base to use, 0 indicates using the prefix,
if any, to detect base 2, 10 or 16.
If no integer is found at the specified location, then (0, 0) is returned,
since no characters have been used.
An integer out of range for the target type throws an error.
A leading minus is allowed for signed integer types.
Underscore characters are allowed throughout the integer and are ignored.
fun box read_int[A: ((I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |
ULong val | USize val) & Integer[A] val)](
offset: ISize val = 0,
base: U8 val = 0)
: (A , USize val) ?


# Using `box->` as a viewpoint

There's one more way we use arrow types, and it's also related to generics. Sometimes we want to talk about a type parameter as it is seen by some unknown type, _as long as that type can read the type parameter_.

In other words, the unknown type will be a subtype of `box`, but that's all we know. Here's an example from the standard library:

```pony
interface Comparable[A: Comparable[A] box]
fun eq(that: box->A): Bool => this is that
fun ne(that: box->A): Bool => not eq(that)
```

Here, we say that something is `Comparable[A]` if and only if it has functions `eq` and `ne` and those functions have a single parameter of type `box->A` and return a `Bool`. In other words, whatever `A` is bound to, we only need to be able to read it.


872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891


Unsafe operation.
If any input or output of the operation is +/- infinity or NaN, the result
is undefined.
The operation isn't required to fully comply to IEEE 754 semantics.
fun box rem_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶

A

mod_unsafe¶
[Source]
Unsafe operation.


# Simple subtypes

Subtyping is about _substitutability_. That is, if we need to supply a certain type, what other types can we substitute instead? Reference capabilities are one important component. We can start by going through a few simpler cases, and then we will talk about the full chart.

First, let's focus on the four capabilities `ref`, `val`, `box`, and `tag`. These have a very useful property: they alias to themselves (and unalias to themselves, as well). This will make the subtyping a lot simpler to work with. Afterwards we can talk about `iso` and `trn`, whose subtyping is more intricate.

To keep things brief, let's add a small shorthand. We will use the `<:` symbol to mean "is a subtype of", or you can read it as "can be used as".

* `ref <: box`. A `ref` can be written to and read from, while `box` only needs the ability to read.
* `val <: box`. A `val` can be read from and is globally immutable, while `box` only requires the ability to read.
* `box <: tag`. A `box` can be read from, while a `tag` doesn't have any permissions at all. In fact, anything can be used as `tag`.

That's all there is to those four. A `ref` could have other mutable aliases, so it can't become `val`, which requires global uniqueness. Likewise,
`val` can't become `ref` since it can't be used to write (and there could be other `val` aliases requiring immutability).

Also keep in mind, subtyping is _transitive_. That means that since `val <: box` and `box <: tag`, we also get `val <: tag`. The basic cases will be explained below, and transitivity can be used to derive all other subtyping relationships for capabilities.


y: USize val

Returns¶

USize val

shr_unsafe¶
[Source]
fun box shr_unsafe(
y: USize val)
: USize val

Parameters¶

y: USize val

Returns¶


172
173
174
175
176
177
178
179
180primitive Sig
"""
Define the portable signal numbers. Other signals can be used, but they are
not guaranteed to be portable.
"""
fun hup(): U32 => 1
fun int(): U32 => 2
fun quit(): U32 => 3

fun ill(): U32 =>
ifdef linux or bsd or osx then 4
else compile_error "no SIGINT"


Equatable[NetAddress val] ref

Constructors¶
create¶
[Source]
new iso create()
: NetAddress iso^

Returns¶

NetAddress iso^

Public Functions¶
ip4¶
[Source]
Returns true for an IPv4 address.
fun box ip4()


fun box i16()
: I16 val

Returns¶

I16 val

i32¶
[Source]
fun box i32()
: I32 val

Returns¶

I32 val

i64¶
[Source]


# Why is this useful?

This most straightforward use of `recover` is to get an `iso` that you can pass to another actor. But it can be used for many other things as well, such as:

* Creating a cyclic immutable data structure. That is, you can create a complex mutable data structure inside a `recover` expression, "lift" the resulting `ref` to a `val`.
* "Borrow" an `iso` as a `ref`, do a series of complex mutable operations on it, and return it as an `iso` again.
* "Extract" a mutable field from an `iso` and return it as an `iso`.


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131


Assert that the gived test function does not throw an error when run.
"""
try
test()?
log(_format_loc(loc) + "Assert no error passed. " + msg, true)
true
else
fail(_format_loc(loc) + "Assert no error failed. " + msg)
true
end

fun assert_is[A](
expect: A,
actual: A,
msg: String = "",
loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the 2 given expressions resolve to the same instance


Bool val

lt¶
[Source]
fun box lt(
y: box->A)
: Bool val

Parameters¶

y: box->A

Returns¶

Bool val

le¶
[Source]


Parameters¶

token': String val
msg': String val

Returns¶

SyntaxError val^

Public Functions¶
token¶
[Source]
fun box token()
: String val

Returns¶

String val


fun box sctp_cookie_ack()
: I32 val

Returns¶

I32 val

sctp_cookie_echo¶
[Source]
fun box sctp_cookie_echo()
: I32 val

Returns¶

I32 val

sctp_cookie_echoed¶
[Source]


new val create(
auth: AmbientAuth val)
: OutputSerialisedAuth val^

Parameters¶

auth: AmbientAuth val

Returns¶

OutputSerialisedAuth val^

Public Functions¶
eq¶
[Source]
fun box eq(
that: OutputSerialisedAuth val)
: Bool val


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


[Source]
Create a timer handler with the specified number of slop bits. No slop bits
means trying for nanosecond resolution. 10 slop bits is approximately
microsecond resolution, 20 slop bits is approximately millisecond
resolution.
new tag create(
slop: USize val = 20)
: Timers tag^

Parameters¶

slop: USize val = 20

Returns¶

Timers tag^

Public Behaviours¶
apply¶


sig.pony

1
2
3
4
5
6
7
8
9
10
11


(A , Bool val)

fld_partial¶
[Source]
fun box fld_partial(
y: A)
: A ?

Parameters¶

y: A

Returns¶

A ?

fld_unsafe¶


fun tipc_top_srv():I32 => @pony_os_sockopt_option(I32(1082))
fun tipc_wait_forever():I32 => @pony_os_sockopt_option(I32(1083))
fun tipc_withdrawn():I32 => @pony_os_sockopt_option(I32(1084))
fun tipc_zone_scope():I32 => @pony_os_sockopt_option(I32(1085))
fun ttcp_client_snd_wnd():I32 => @pony_os_sockopt_option(I32(1086))
fun udp_cork():I32 => @pony_os_sockopt_option(I32(1087))
fun udp_encap():I32 => @pony_os_sockopt_option(I32(1088))
fun udp_encap_espinudp():I32 => @pony_os_sockopt_option(I32(1089))
fun udp_encap_espinudp_maxfraglen():I32 => @pony_os_sockopt_option(I32(1090))
fun udp_encap_espinudp_non_ike():I32 => @pony_os_sockopt_option(I32(1091))
fun udp_encap_espinudp_port():I32 => @pony_os_sockopt_option(I32(1092))
fun udp_encap_l2tpinudp():I32 => @pony_os_sockopt_option(I32(1093))
fun udp_nocksum():I32 => @pony_os_sockopt_option(I32(1094))
fun udp_no_check6_rx():I32 => @pony_os_sockopt_option(I32(1095))
fun udp_no_check6_tx():I32 => @pony_os_sockopt_option(I32(1096))
fun udp_vendor():I32 => @pony_os_sockopt_option(I32(1097))
fun so_rcvtimeo_old():I32 => @pony_os_sockopt_option(I32(1098))
fun so_rcvtimeo_new():I32 => @pony_os_sockopt_option(I32(1099))
fun so_sndtimeo_old():I32 => @pony_os_sockopt_option(I32(1100))
fun so_sndtimeo_new():I32 => @pony_os_sockopt_option(I32(1101))


fun box so_sndtimeo_old()
: I32 val

Returns¶

I32 val

so_sndtimeo_new¶
[Source]
fun box so_sndtimeo_new()
: I32 val

Returns¶

I32 val

eq¶
[Source]


complete_shrink¶
[Source]
be complete_shrink(
failed_repr: String val,
last_repr: String val,
shrink_round: (_Shrink val | _Run val),
success: Bool val)

Parameters¶

failed_repr: String val
last_repr: String val
shrink_round: (_Shrink val | _Run val)
success: Bool val

do_shrink¶
[Source]
be do_shrink(
failed_repr: String val)


fun box bytewidth()
: USize val

Returns¶

USize val

min¶
[Source]
fun box min(
y: ULong val)
: ULong val

Parameters¶

y: ULong val

Returns¶


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391


After GC, an actor will next be GC'd at a heap memory usage N times its
current value. This is a floating point value. Defaults to 2.0.

var ponynoyield: Bool val¶
[Source]
Do not yield the CPU when no work is available.

var ponynoblock: Bool val¶
[Source]
Do not send block messages to the cycle detector.

var ponypin: Bool val¶
[Source]
Pin scheduler threads to CPU cores. The ASIO thread can also be pinned if
--ponypinasio is set.

var ponypinasio: Bool val¶
[Source]
Pin the ASIO thread to a CPU the way scheduler threads are pinned to CPUs.
Requires --ponypin to be set to have any effect.


| None => env.out.print("x is None")
end
```

Here __x__ would be `None`.

You can also avoid needing `None` at all by providing a __default value__ for when the loop has __0 iterations__ by providing an `else` block.

```pony
actor Main
new create(env: Env) =>
var x: String =
for name in Array[String].values() do
name
else
"no names!"
end
env.out.print("x is " + x)
```


492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311


Bool val

ldexp¶
[Source]
fun box ldexp(
x: A,
exponent: I32 val)
: A

Parameters¶

x: A
exponent: I32 val

Returns¶

A


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371


(I16 val , Bool val)

fldc¶
[Source]
fun box fldc(
y: I16 val)
: (I16 val , Bool val)

Parameters¶

y: I16 val

Returns¶

(I16 val , Bool val)

modc¶
[Source]


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31


(u8()?.u64() << 24) or (u8()?.u64() << 16) or
(u8()?.u64() << 8) or u8()?.u64()
end
else
error
end

fun ref u64_le(): U64 ? =>
"""
Get a little-endian U64.
"""
let num_bytes = U64(0).bytewidth()
if _available >= num_bytes then
let node = _chunks.head()?
(var data, var offset) = node()?
if (data.size() - offset) >= num_bytes then
let r =
ifdef littleendian then
data.read_u64(offset)?
else


fun box so_sndbufforce()
: I32 val

Returns¶

I32 val

so_sndlowat¶
[Source]
fun box so_sndlowat()
: I32 val

Returns¶

I32 val

so_sndtimeo¶
[Source]


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271


Returns¶

List[this->A!] ref^

map[B: B]¶
[Source]
Builds a new List by applying a function to every element of the List.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.map[String]( {(s: String): String => "m: " + s } )  // other_list is ["m: a"; "m: b"; "m: c"]

fun box map[B: B](
f: {(this->A!): B^}[A, B] box)
: List[B] ref^

Parameters¶

f: {(this->A!): B^}[A, B] box

Returns¶


property_helper.pony

1
2
3
4
5
6
7
8
9
10
11


var exponent: U32 = 0
var mantissa = @frexp(f64(), addressof exponent)
(mantissa.f32(), exponent)

fun log(): F32 => @"llvm.log.f32"(this)
fun log2(): F32 => @"llvm.log2.f32"(this)
fun log10(): F32 => @"llvm.log10.f32"(this)
fun logb(): F32 => @logbf(this)

fun pow(y: F32): F32 => @"llvm.pow.f32"(this, y)
fun powi(y: I32): F32 =>
ifdef windows then
pow(y.f32())
else
@"llvm.powi.f32"(this, y)
end

fun sqrt(): F32 =>
if this < 0.0 then
_nan()


112
113
114
115
116
117
118
119
120
121
122
123use "buffered"

class FileLines is Iterator[String iso^]
"""
Iterate over the lines in a file.

Returns lines without trailing line breaks.
Advances the file cursor to the end of each line returned from `next`.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


fun ref unique[H: HashFunction[A] val = HashIs[A]](): Iter[A!]^ =>
"""
Return an iterator that filters out elements that have already been
produced. Uniqueness is determined by the HashFunction `H`.


fun add_partial(y: U128): U128 ? =>
_UnsignedPartialArithmetic.add_partial[U128](this, y)?

fun sub_partial(y: U128): U128 ? =>
_UnsignedPartialArithmetic.sub_partial[U128](this, y)?

fun mul_partial(y: U128): U128 ? =>
_UnsignedPartialArithmetic.mul_partial[U128](this, y)?

fun div_partial(y: U128): U128 ? =>
_UnsignedPartialArithmetic.div_partial[U128](this, y)?

fun rem_partial(y: U128): U128 ? =>
_UnsignedPartialArithmetic.rem_partial[U128](this, y)?

fun divrem_partial(y: U128): (U128, U128) ? =>
_UnsignedPartialArithmetic.divrem_partial[U128](this, y)?

type Unsigned is (U8 | U16 | U32 | U64 | U128 | ULong | USize)


Bool val

gt¶
[Source]
fun box gt(
y: I64 val)
: Bool val

Parameters¶

y: I64 val

Returns¶

Bool val

hash64¶
[Source]


fun box ipv6_priority_13()
: I32 val

Returns¶

I32 val

ipv6_priority_14¶
[Source]
fun box ipv6_priority_14()
: I32 val

Returns¶

I32 val

ipv6_priority_15¶
[Source]


Bool val

le¶
[Source]
fun box le(
y: USize val)
: Bool val

Parameters¶

y: USize val

Returns¶

Bool val

ge¶
[Source]


fun box u128()
: U128 val

Returns¶

U128 val

ulong¶
[Source]
fun box ulong()
: ULong val

Returns¶

ULong val

usize¶
[Source]


var _i: USize = -1
var _count: USize = 0

new create(map: M) =>
"""
Creates an iterator for the given map.
"""
_map = map

fun has_next(): Bool =>
"""
True if it believes there are remaining entries. May not be right if values
were added or removed from the map.
"""
_count < _map.size()

fun ref next(): M->K ? =>
"""
Returns the next key, or raises an error if there isn't one. If keys are
added during iteration, this may not return all keys.


492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511


op_and¶
[Source]
Return a set with the elements that are in both this and that.
fun val op_and(
that: (HashSet[A, H] val | Iterator[A] ref))
: HashSet[A, H] val

Parameters¶

that: (HashSet[A, H] val | Iterator[A] ref)

Returns¶

HashSet[A, H] val

op_xor¶
[Source]


Parameters¶

auth: TCPConnectAuth val
notify: TCPConnectionNotify iso
host: String val
service: String val
from: String val = ""
read_buffer_size: USize val = 16384
yield_after_reading: USize val = 16384
yield_after_writing: USize val = 16384

Returns¶

TCPConnection tag^

ip6¶
[Source]
Connect via IPv6.


ArgSpec val^

i64¶
[Source]
Creates an Arg with an I64 typed value that can be used like
<cmd> 42
to yield an arg value like
cmd.arg("count").i64() == I64(42).
new val i64(
name': String val,
descr': String val = "",
default': (I64 val | None val) = reference)
: ArgSpec val^

Parameters¶

name': String val
descr': String val = ""
default': (I64 val | None val) = reference


y: I8 val

Returns¶

I8 val

neg¶
[Source]
fun box neg()
: I8 val

Returns¶

I8 val

eq¶
[Source]


Set[A: (Hashable #read & Equatable[A] #read)]¶
[Source]
type Set[A: (Hashable #read & Equatable[A] #read)] is
HashSet[A, HashEq[A] val] ref

Type Alias For¶

HashSet[A, HashEq[A] val] ref


y: U16 val

Returns¶

U16 val

mul¶
[Source]
fun box mul(
y: U16 val)
: U16 val

Parameters¶

y: U16 val

Returns¶


"""
let num_bytes = U32(0).bytewidth()
ifdef bigendian then
_current.push_u32(data)
else
_current.push_u32(data.bswap())
end
_size = _size + num_bytes

fun ref i32_le(data: I32) =>
"""
Write an I32 to the buffer in little-endian byte order.
"""
u32_le(data.u32())

fun ref i32_be(data: I32) =>
"""
Write an I32 to the buffer in big-endian byte order.
"""
u32_be(data.u32())


Check whether the set contains the value.
fun box contains(
value: val->A)
: Bool val

Parameters¶

value: val->A

Returns¶

Bool val

add¶
[Source]
Return a set with the value added.
fun val add(
value: val->A)
: HashSet[A, H] val


712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731


fun so_setfib():I32 => @pony_os_sockopt_option(I32(902))
fun so_sndbuf():I32 => @pony_os_sockopt_option(I32(903))
fun so_sndbufforce():I32 => @pony_os_sockopt_option(I32(904))
fun so_sndlowat():I32 => @pony_os_sockopt_option(I32(905))
fun so_sndtimeo():I32 => @pony_os_sockopt_option(I32(906))
fun so_timestamp():I32 => @pony_os_sockopt_option(I32(907))
fun so_timestamping():I32 => @pony_os_sockopt_option(I32(908))
fun so_timestampns():I32 => @pony_os_sockopt_option(I32(909))
fun so_timestamp_monotonic():I32 => @pony_os_sockopt_option(I32(910))
fun so_type():I32 => @pony_os_sockopt_option(I32(911))
fun so_upcallclosewait():I32 => @pony_os_sockopt_option(I32(912))
fun so_update_accept_context():I32 => @pony_os_sockopt_option(I32(913))
fun so_useloopback():I32 => @pony_os_sockopt_option(I32(914))
fun so_user_cookie():I32 => @pony_os_sockopt_option(I32(915))
fun so_vendor():I32 => @pony_os_sockopt_option(I32(916))
fun so_vm_sockets_buffer_max_size():I32 => @pony_os_sockopt_option(I32(917))
fun so_vm_sockets_buffer_min_size():I32 => @pony_os_sockopt_option(I32(918))
fun so_vm_sockets_buffer_size():I32 => @pony_os_sockopt_option(I32(919))
fun so_vm_sockets_connect_timeout():I32 => @pony_os_sockopt_option(I32(920))
fun so_vm_sockets_nonblock_txrx():I32 => @pony_os_sockopt_option(I32(921))


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211


Generator[(T1 , T2 , T3)] box

zip4[T1: T1, T2: T2, T3: T3, T4: T4]¶
[Source]
Zip four generators into a generator of a 4-tuple
containing the values generated by those four generators.
fun box zip4[T1: T1, T2: T2, T3: T3, T4: T4](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
gen4: Generator[T4] box)
: Generator[(T1 , T2 , T3 , T4)] box

Parameters¶

gen1: Generator[T1] box
gen2: Generator[T2] box
gen3: Generator[T3] box


"""
Write an iterable collection of ByteSeqs.
"""
for bytes in data.values() do
_write(bytes)
end

be flush() =>
"""
Flush any data out to the os (ignoring failures).
"""
@pony_os_std_flush(_stream)

fun ref _write(data: ByteSeq) =>
"""
Write the bytes without explicitly flushing.
"""
@pony_os_std_write(_stream, data.cpointer(), data.size())

fun ref _print(data: ByteSeq) =>


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351


(U8 val , Bool val)

divc¶
[Source]
fun box divc(
y: U8 val)
: (U8 val , Bool val)

Parameters¶

y: U8 val

Returns¶

(U8 val , Bool val)

remc¶
[Source]


fun ref _upper(i: USize, x: U64): U64 ? =>
let y = _state(i + 1)?
_state(i)? = _state(i - _m())? xor _mix(x, y)
y

fun ref _wrap(): U64 ? =>
let x = _state(_n1())?
let y = _state(0)?
_state(_n1())? = _state(_m() - 1)? xor _mix(x, y)
y


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


| ASCIIPunctuation
| ASCIILettersLower
| ASCIILettersUpper
| ASCIILetters
| ASCIIPrintable
| ASCIINonPrintable
| ASCIIAll
| ASCIIAllWithNUL)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


fun box eq(
that: Debug val)
: Bool val

Parameters¶

that: Debug val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: Debug val)
: Bool val

Parameters¶


String iso^


fun box udp_encap_espinudp_maxfraglen()
: I32 val

Returns¶

I32 val

udp_encap_espinudp_non_ike¶
[Source]
fun box udp_encap_espinudp_non_ike()
: I32 val

Returns¶

I32 val

udp_encap_espinudp_port¶
[Source]


fun box rem_unsafe(
y: USize val)
: USize val

Parameters¶

y: USize val

Returns¶

USize val

neg_unsafe¶
[Source]
fun box neg_unsafe()
: USize val

Returns¶


: N

Parameters¶

n: N

Returns¶

N

real¶
[Source]
fun ref real()
: F64 val

Returns¶

F64 val


352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371


Get a little-endian I16.
fun ref i16_le()
: I16 val ?

Returns¶

I16 val ?

u32_be¶
[Source]
Get a big-endian U32.
fun ref u32_be()
: U32 val ?

Returns¶

U32 val ?


format.pony

1
2
3
4
5
6
7
8
9
10
11


U16 val

op_and¶
[Source]
fun box op_and(
y: U16 val)
: U16 val

Parameters¶

y: U16 val

Returns¶

U16 val

op_or¶
[Source]


fun ref writev(
data: ByteSeqIter box)
: Bool val

Parameters¶

data: ByteSeqIter box

Returns¶

Bool val

queue¶
[Source]
Queue data to be written
NOTE: Queue'd data will always be written before normal print/write
requested data
fun ref queue(
data: (String box | Array[U8 val] box))


fun box tcpolen_fast_open_empty()
: I32 val

Returns¶

I32 val

tcpolen_fast_open_max¶
[Source]
fun box tcpolen_fast_open_max()
: I32 val

Returns¶

I32 val

tcpolen_fast_open_min¶
[Source]


# Authorization-friendly interface

Consider the above example again, but this time let's think of the `Connect` actor being part of a 3rd party package that we are building. Our goal is to write the actor in such a way that users of our package can grant it only the authority necessary for it to function.

As the package author, it is then our responsibility to realize that the minimal authority possible is the `TCPConnectAuth`. We should only request `TCPConnectAuth` from our users. Our current implementation already satisfies this requirement. Rather than requesting a less specific authority like `AmbientAuth` from our users and creating the `TCPConnectAuth` in our library, we only ask for the `TCPConnetAuth` that is required.


gen¶
[Source]
fun box gen()
: Generator[(T1 , T2)] box

Returns¶

Generator[(T1 , T2)] box

property¶
[Source]
fun ref property(
arg1: (T1 , T2),
h: PropertyHelper val)
: None val ?

Parameters¶

arg1: (T1 , T2)


# Raising and handling errors

An error is raised with the command `error`. At any point, the code may decide to declare an `error` has occurred. Code execution halts at that point, and the call chain is unwound until the nearest enclosing error handler is found. This is all checked at compile time so errors cannot cause the whole program to crash.

Error handlers are declared using the `try`-`else` syntax.

```pony
try
callA()
if not callB() then error end
callC()
else
callD()
end
```

In the above code `callA()` will always be executed and so will `callB()`. If the result of `callB()` is true then we will proceed to `callC()` in the normal fashion and `callD()` will not then be executed.

However, if `callB()` returns false, then an error will be raised. At this point, execution will stop and the nearest enclosing error handler will be found and executed. In this example that is, our else block and so `callD()` will be executed.


[Source]
Set the last access and modification times of a path to now.
fun box touch()
: Bool val

Returns¶

Bool val

set_time¶
[Source]
Set the last access and modification times of a path to the given values.
fun box set_time(
atime: (I64 val , I64 val),
mtime: (I64 val , I64 val))
: Bool val

Parameters¶


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

u64_unsafe¶
[Source]
fun box u64_unsafe()
: U64 val

Returns¶

U64 val

u128_unsafe¶
[Source]


fun box mod_partial(
y: I32 val)
: I32 val ?

Parameters¶

y: I32 val

Returns¶

I32 val ?

shl¶
[Source]
fun box shl(
y: U32 val)
: I32 val

Parameters¶


fun box mod(
y: A)
: A

Parameters¶

y: A

Returns¶

A

eq¶
[Source]
fun box eq(
y: box->A)
: Bool val

Parameters¶


Parameters¶

spec': OptionSpec val
value': (Bool val | String val | I64 val |
U64 val | F64 val | _StringSeq val)

Returns¶

Option val^

Public Functions¶
spec¶
[Source]
fun box spec()
: OptionSpec val

Returns¶


fun box netlink_netfilter()
: I32 val

Returns¶

I32 val

netlink_nflog¶
[Source]
fun box netlink_nflog()
: I32 val

Returns¶

I32 val

netlink_no_enobufs¶
[Source]


fun val remove(i: USize, n: USize): Vec[A] ? =>
"""
Return a vector with n elements removed, beginning at index i.
"""
if i >= _size then error end
var vec = this
for _ in mut.Range(0, n) do vec = vec.pop()? end
for idx in mut.Range(i, _size - n) do
vec = vec.update(idx, this(idx + n)?)?
end
vec

fun val push(value: val->A): Vec[A] =>
"""
Return a vector with the value added to the end.
"""
// push tail into root when it becomes full
let size' = _size + 1
let tail = recover val _tail.clone() .> push(value) end
if tail.size() < 32 then


fun box read()
: U64 val

Returns¶

U64 val

write¶
[Source]
fun box write()
: U64 val

Returns¶

U64 val

seek_tell¶
[Source]


fun box ip_old_fw_resetlog()
: I32 val

Returns¶

I32 val

ip_old_fw_zero¶
[Source]
fun box ip_old_fw_zero()
: I32 val

Returns¶

I32 val

ip_onesbcast¶
[Source]


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


that: Serialise val

Returns¶

Bool val


FormatHex¶
[Source]
primitive val FormatHex is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


fun ref dispose(
process: ProcessMonitor ref,
child_exit_status: (Exited val | Signaled val))
: None val

Parameters¶

process: ProcessMonitor ref
child_exit_status: (Exited val | Signaled val)

Returns¶

None val


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451


fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

isize_unsafe¶
[Source]
fun box isize_unsafe()
: ISize val

Returns¶

ISize val

u8_unsafe¶
[Source]


fun box ipproto_mux()
: I32 val

Returns¶

I32 val

ipproto_nd¶
[Source]
fun box ipproto_nd()
: I32 val

Returns¶

I32 val

ipproto_nhrp¶
[Source]


Bool val

ne¶
[Source]
fun box ne(
that: FormatOctalBare val)
: Bool val

Parameters¶

that: FormatOctalBare val

Returns¶

Bool val


Returns¶

Bool val


fun ref zip3[B, C, D](i2: Iterator[B], i3: Iterator[C], i4: Iterator[D])
: Iter[(A, B, C, D)]^
=>
"""
Zip four iterators together so that each call to next() results in
a tuple with the next value of each of the iterators. The number of
items returned is the minimum of the number of items returned by the
iterators.
"""
Iter[(A, B, C, D)](
object is Iterator[(A, B, C, D)]
let _i1: Iterator[A] = _iter
let _i2: Iterator[B] = i2
let _i3: Iterator[C] = i3
let _i4: Iterator[D] = i4

fun ref has_next(): Bool =>
_i1.has_next()
and _i2.has_next()


# Tuples

A __tuple__ type is a sequence of types. For example, if we wanted something that was a `String` followed by a `U64`, we would write this:

```pony
var x: (String, U64)
x = ("hi", 3)
x = ("bye", 7)
```

All type expressions are written in parentheses, and the elements of a tuple are separated by a comma. We can also destructure a tuple using assignment:

```pony
(var y, var z) = x
```

Or we can access the elements of a tuple directly:

```pony
var y = x._1


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71


: Bool val

Parameters¶

expect: A
actual: A
msg: String val = ""
loc: SourceLoc val = __loc

Returns¶

Bool val

assert_isnt[A: A]¶
[Source]
Assert that the 2 given expressions resolve to different instances.
fun box assert_isnt[A: A](
not_expect: A,
actual: A,


let f = recover Flags[A, B] end
f._value = this._value xor that._value
f

fun without(that: Flags[A, B] box): Flags[A, B] iso^ =>
"""
The flags in this that are not in that.
"""
let f = recover Flags[A, B] end
f._value = this._value and not that._value
f

fun clone(): Flags[A, B] iso^ =>
"""
Create a clone.
"""
let f = recover Flags[A, B] end
f._value = this._value
f


seek_start¶
[Source]
Set the cursor position relative to the start of the file.
fun ref seek_start(
offset: USize val)
: None val

Parameters¶

offset: USize val

Returns¶

None val

seek_end¶
[Source]


fun ref push_u32[B: (A & Real[B] val & U8) = A](value: U32) =>
"""
Add a U32 to the end of the array. This is only allowed for an array of U8s.
"""
let u32_bytes = U32(0).bytewidth()
reserve(_size + u32_bytes)
_ptr._offset(_size)._convert[U32]()._update(0, value)
_size = _size + u32_bytes

fun ref push_u64[B: (A & Real[B] val & U8) = A](value: U64) =>
"""
Add a U64 to the end of the array. This is only allowed for an array of U8s.
"""
let u64_bytes = U64(0).bytewidth()
reserve(_size + u64_bytes)
_ptr._offset(_size)._convert[U64]()._update(0, value)
_size = _size + u64_bytes

fun ref push_u128[B: (A & Real[B] val & U8) = A](value: U128) =>
"""


: U8 val

Returns¶

U8 val

u16¶
[Source]
fun ref u16()
: U16 val

Returns¶

U16 val

u32¶
[Source]
fun ref u32()


_notify = notify
_rnd = Randomness(_params.seed)
_gen = _prop1.gen()

// RUNNING PROPERTIES //

be complete_run(round: _Round, success: Bool) =>
"""
Complete a property run.

This behaviour is called from the PropertyHelper
or from the actor itself.
"""

// verify that this is an expected call
if this._current_round != round then
_logger.log("unexpected " + if success then "finish" else "fail" end + " msg for " + round.string() +
". expecting " + this._current_round.string(), true)
return


fun box u32()
: U32 val

Returns¶

U32 val

u64¶
[Source]
fun box u64()
: U64 val

Returns¶

U64 val

u128¶
[Source]


path' is relative to the existing FilePath,
and the existing FilePath must be a prefix of the resulting path.
The resulting FilePath will have capabilities that are the intersection of
the supplied capabilities and the capabilities of the existing FilePath.
new val from(
base: FilePath val,
path': String val,
caps': Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] val = recover)
: FilePath val^ ?

Parameters¶

base: FilePath val
path': String val
caps': Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] val = recover

Returns¶

FilePath val^ ?


info¶
[Source]
Return a FileInfo for this directory. Raise an error if the fd is invalid
or if we don't have FileStat permission.
fun box info()
: FileInfo val ?

Returns¶

FileInfo val ?

chmod¶
[Source]
Set the FileMode for this directory.
fun box chmod(
mode: FileMode box)
: Bool val


I64 val

i128¶
[Source]
fun box i128()
: I128 val

Returns¶

I128 val

ilong¶
[Source]
fun box ilong()
: ILong val

Returns¶


y: U128 val

Returns¶

Bool val

ne¶
[Source]
fun box ne(
y: U128 val)
: Bool val

Parameters¶

y: U128 val

Returns¶


new val create(
value: I128 val)
: I128 val^

Parameters¶

value: I128 val

Returns¶

I128 val^

from[A: ((I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val | F32 val | F64 val) & Real[A] val)]¶
[Source]
new val from[A: ((I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |
ULong val | USize val | F32 val |


let c2 = that._ptr._apply(k)
if
not ((c1 == c2) or
(ignore_case and ((c1 or 0x20) == (c2 or 0x20)) and
((c1 or 0x20) >= 'a') and ((c1 or 0x20) <= 'z')))
then
// this and that differ here
return if c1.i32() > c2.i32() then Greater else Less end
end

j = j + 1
k = k + 1
i = i - 1
end
Equal

fun eq(that: String box): Bool =>
"""
Returns true if the two strings have the same contents.
"""


WalkHandler¶
[Source]
A handler for FilePath.walk.
interface ref WalkHandler

Public Functions¶
apply¶
[Source]
fun ref apply(
dir_path: FilePath val,
dir_entries: Array[String val] ref)
: None val


(U64 val , Bool val)

add_partial¶
[Source]
fun box add_partial(
y: U64 val)
: U64 val ?

Parameters¶

y: U64 val

Returns¶

U64 val ?

sub_partial¶
[Source]


```pony
class Larry
fun name(): String => "Larry"
```

Here, we have a class `Larry` that has a `name` function with the same signature. But `Larry` does __not__ provide `Named`!

__Wait, why not?__ Because `Larry` doesn't say it `is Named`. Remember, traits are __nominal__: a type that wants to provide a trait has to explicitly declare that it does. And `Larry` doesn't.

You can also do nominal subtyping using the keyword `interface`. __Interfaces__ in Pony are primarily used for structural subtyping. Like traits, interfaces can also have default method implementations, but in order to use default method implementations, an interface must be used in a nominal fashion. For example:

```pony
interface HasName
fun name(): String => "Bob"

class Bob is HasName

class Larry
fun name(): String => "Larry"


end

_pass = success // in case of sync property - signal failure

if not success then
// found a bad example, try to shrink it
if not _shrinker.has_next() then
_logger.log("no shrinks available")
fail(_sample_repr, 0)
else
// prepare next round
_prepare_next_round()
// set rounds to shrinking
this._current_round = _Shrink.create(0) // reset rounds for shrinking
// start shrinking process
do_shrink(_sample_repr)
end
else
// property holds, recurse
_prepare_next_round()


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


# Intersections

An __intersection__ uses a `&` (pronounced "and" when reading the type) between its elements. It represents the exact opposite of a union: it is a _single_ value that is _all_ of the specified types, at the same time!

This can be very useful for combining traits or interfaces, for example. Here's something from the standard library:

```pony
type Map[K: (Hashable box & Comparable[K] box), V] is HashMap[K, V, HashEq[K]]
```

That's a fairly complex type alias, but let's look at the constraint of `K`. It's `(Hashable box & Comparable[K] box)`, which means `K` is `Hashable` _and_ it is `Comparable[K]`, at the same time.


ArrayPairs[A: A, B: Array[A] #read]¶
[Source]
class ref ArrayPairs[A: A, B: Array[A] #read] is
Iterator[(USize val , B->A)] ref

Implements¶

Iterator[(USize val , B->A)] ref

Constructors¶
create¶
[Source]


fun box sub(
y: A)
: A

Parameters¶

y: A

Returns¶

A

mul¶
[Source]
fun box mul(
y: A)
: A

Parameters¶


Real[A] val^

max_value¶
[Source]
new val max_value()
: Real[A] val^

Returns¶

Real[A] val^

Public Functions¶
abs¶
[Source]
fun box abs()
: B

Returns¶


OptionSpec val

bool¶
[Source]
Returns the option value as a Bool, defaulting to false.
fun box bool()
: Bool val

Returns¶

Bool val

string¶
[Source]
Returns the option value as a String, defaulting to empty.
fun box string()
: String val


(USize val , Bool val)

fld_partial¶
[Source]
fun box fld_partial(
y: USize val)
: USize val ?

Parameters¶

y: USize val

Returns¶

USize val ?

fld_unsafe¶
[Source]


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171


// Not a continuation byte.
err
else
(((c.u32() << 6) + c2.u32()) - 0x3080, 2)
end
end
elseif c < 0xF0 then
// 3-byte.
if (i + 2) >= _size then
// Not enough bytes.
err
else
let c2 = _ptr._apply(i + 1)
let c3 = _ptr._apply(i + 2)
if
// Not continuation bytes.
((c2 and 0xC0) != 0x80) or
((c3 and 0xC0) != 0x80) or
// Overlong encoding.
((c == 0xE0) and (c2 < 0xA0))


"""
if _connected then
set_tcp_nodelay(state)
end

fun ref set_keepalive(secs: U32) =>
"""
Sets the TCP keepalive timeout to approximately `secs` seconds. Exact
timing is OS dependent. If `secs` is zero, TCP keepalive is disabled. TCP
keepalive is disabled by default. This can only be set on a connected
socket.
"""
if _connected then
@pony_os_keepalive(_fd, secs)
end

be _event_notify(event: AsioEventID, flags: U32, arg: U32) =>
"""
Handle socket events.
"""


Exited¶
[Source]
Process exit status: Process exited with an exit code.
class val Exited is
Stringable box,
Equatable[(Exited val | Signaled val)] ref

Implements¶

Stringable box
Equatable[(Exited val | Signaled val)] ref


292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311


use @list_push[None](list: Pointer[_List], data: Pointer[None])
use @list_pop[Pointer[None]](list: Pointer[_List])

primitive _List
```

We can use these declarations to create lists of different types, and insert elements into them:

```pony
struct Point
var x: U64 = 0
var y: U64 = 0

let list_of_points = @list_create()
@list_push(list_of_points, NullablePointer[Point].create(Point))

let list_of_strings = @list_create()
@list_push(list_of_strings, "some data".cstring())
```


fun box ge(
y: I32 val)
: Bool val

Parameters¶

y: I32 val

Returns¶

Bool val

gt¶
[Source]
fun box gt(
y: I32 val)
: Bool val

Parameters¶


# Passing

For an object to be mutable, we need to be sure that no _other_ actor can read from or write to that object. The three mutable reference capabilities (`iso`, `trn`, and `ref`) all make that guarantee.

But what if we want to pass a mutable object from one actor to another? To do that, we need to be sure that the actor that is _sending_ the mutable object also _gives up_ the ability to both read from and write to that object.

This is exactly what `iso` does. It is _read and write unique_, there can only be one reference at a time that can be used for reading or writing. If you send an `iso` object to another actor, you will be giving up the ability to read from or write to that object.

__So I should use `iso` when I want to pass a mutable object between actors?__ Yes! If you don't need to pass it, you can just use `ref` instead.


InputNotify¶
[Source]
Notification for data arriving via an input stream.
interface ref InputNotify

Public Functions¶
apply¶
[Source]
Called when data is available on the stream.
fun ref apply(
data: Array[U8 val] iso)
: None val


fun box divrem_partial(
y: ULong val)
: (ULong val , ULong val) ?

Parameters¶

y: ULong val

Returns¶

(ULong val , ULong val) ?

shl¶
[Source]
fun box shl(
y: ULong val)
: ULong val

Parameters¶


Property2[T1: T1, T2: T2]¶
[Source]
trait ref Property2[T1: T1, T2: T2] is
Property1[(T1 , T2)] ref

Implements¶

Property1[(T1 , T2)] ref

Public Functions¶
gen1¶
[Source]


le¶
fun box le(
y: F64 val)
: Bool val

Parameters¶

y: F64 val

Returns¶

Bool val

ge¶
fun box ge(
y: F64 val)
: Bool val

Parameters¶


fun box tcp_mss_desired()
: I32 val

Returns¶

I32 val

tcp_nodelay¶
[Source]
fun box tcp_nodelay()
: I32 val

Returns¶

I32 val

tcp_noopt¶
[Source]


with a minimum length of min (default: 0)
and a maximum length of max (default: 100).
fun box byte_string(
gen: Generator[U8 val] box,
min: USize val = 0,
max: USize val = 100)
: Generator[String val] box

Parameters¶

gen: Generator[U8 val] box
min: USize val = 0
max: USize val = 100

Returns¶

Generator[String val] box

ascii¶


String iso^

add_unsafe¶
[Source]
fun box add_unsafe(
y: USize val)
: USize val

Parameters¶

y: USize val

Returns¶

USize val

sub_unsafe¶
[Source]


fun box ipx_frame_8022()
: I32 val

Returns¶

I32 val

ipx_frame_8023¶
[Source]
fun box ipx_frame_8023()
: I32 val

Returns¶

I32 val

ipx_frame_etherii¶
[Source]


None val

set_up¶
fun ref set_up(
h: TestHelper val)
: None val ?

Parameters¶

h: TestHelper val

Returns¶

None val ?

tear_down¶
fun ref tear_down(


i = i + copy_len
_chunks.shift()?
end

let trunc_len: USize =
if keep_line_breaks then
0
elseif (len >= 2) and (out.at_offset(-2)? == '\r') then
2
else
1
end
out.truncate(len - trunc_len)

consume out

fun ref u8(): U8 ? =>
"""
Get a U8. Raise an error if there isn't enough data.


Create with the specified seed. Returned values are deterministic for a
given seed.
new ref create(
x: U64 val = 5489,
y: U64 val = 0)
: XorOshiro128Plus ref^

Parameters¶

x: U64 val = 5489
y: U64 val = 0

Returns¶

XorOshiro128Plus ref^

Public Functions¶
next¶
[Source]


We can also get elements out of the list, although we won't be able to do anything with them:

```pony
// Compiler error: couldn't find 'x' in 'Pointer'
let point_x = @list_pop(list_of_points)
point.x

// Compiler error: wanted Pointer[U8 val] ref^, got Pointer[None val] ref
let head = String.from_cstring(@list_pop(list_of_strings))
```

We can fix this problem by adding an explicit return type when calling `list_pop`:

```pony
// OK
let point = @list_pop[Point](list_of_points)
let x_coord = point.x

// OK
let pointer = @list_pop[Pointer[U8]](list_of_strings)


952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971


as a `ValueAndShrink[T]` instance, a tuple of `(T^, Seq[T])`.
This helps propagating shrink results through all kinds of Generator
combinators like `filter`, `map` and `flat_map`.

If implementing a custom `Generator` based on another one,
with a Generator Combinator, you should use shrunken values
returned by `generate` to also return shrunken values based on them.

If generating an example value is costly, it might be more efficient
to simply return the generated value and only shrink in big steps or do no
shrinking at all.
If generating values is lightweight, shrunken values should also be
returned.
"""
_gen.generate(rnd)?

fun shrink(t: T): ValueAndShrink[T] =>
"""
Simplify the given value.


PropertyRunner[T: T]¶
[Source]
Actor executing a Property1 implementation
in a way that allows garbage collection between single
property executions, because it uses recursive behaviours
for looping.
actor tag PropertyRunner[T: T]

Constructors¶
create¶
[Source]
new tag create(
p1: Property1[T] iso,


[Source]
fun box op_xor(
y: ILong val)
: ILong val

Parameters¶

y: ILong val

Returns¶

ILong val

op_not¶
[Source]
fun box op_not()
: ILong val

Returns¶


class IntPropertySample
type IntUnitTest
primitive PonyCheck
class Poperator
trait Property1
class Property1UnitTest
trait Property2
class Property2UnitTest
trait Property3
class Property3UnitTest
trait Property4
class Property4UnitTest
class PropertyHelper
interface PropertyLogger
class PropertyParams
interface PropertyResultNotify
actor PropertyRunner
class Randomness
type ValueAndShrink
type WeightedGenerator


Public Functions¶
bsd¶
[Source]
fun box bsd()
: Bool val

Returns¶

Bool val

freebsd¶
[Source]
fun box freebsd()
: Bool val

Returns¶


Parameters¶

that: String box

Returns¶

Bool val

gt¶
[Source]
fun box gt(
that: String box)
: Bool val

Parameters¶

that: String box

Returns¶


let my_list = List[String].from(["a"; "b"; "c"])
try my_list.tail()? end // Returns a ListNode[String] containing "c"
```
"""
_tail as this->ListNode[A]

fun ref prepend_node(node: ListNode[A]) =>
"""
Adds a node to the head of the list.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let new_head = ListNode[String]("0")
my_list.prepend_node(new_head) // ["0", "a"; "b"; "c"]
```
"""
match _head
| let head': ListNode[A] =>
head'.prepend(node)
else


data: (String val | Array[U8 val] val)

write¶
[Source]
Write to STDIN of the child process.
be write(
data: (String val | Array[U8 val] val))

Parameters¶

data: (String val | Array[U8 val] val)

printv¶
[Source]
Print an iterable collection of ByteSeqs.
be printv(
data: ByteSeqIter val)


[Source]
Run the test.
Raising an error is interpreted as a test failure.
fun ref apply(
h: TestHelper val)
: None val ?

Parameters¶

h: TestHelper val

Returns¶

None val ?

timed_out¶
[Source]
Tear down a possibly hanging test.
Called when the timeout specified by to long_test() expires.


if j < 0 then
return 0
elseif (j == 0) and (this == s) then
return 1
end

try
while k <= j do
k = find(s, k)? + s.size().isize()
i = i + 1
end
end

i

fun at(s: String box, offset: ISize = 0): Bool =>
"""
Returns true if the substring s is present at the given offset.
"""
let i = offset_to_index(offset)


CLI Package¶
The CLI package provides enhanced Posix+GNU command line parsing with the
feature of commands that can be specified in a hierarchy.
See RFC-0038 for more background.
The general EBNF of a command line is:
command_line ::= root_command (option | command)* (option | arg)*
command ::= alphanum_word
alphanum_word ::= alphachar(alphachar | numchar | '_' | '-')*
option ::= longoption | shortoptionset
longoption ::= '--'alphanum_word['='arg | ' 'arg]
shortoptionset := '-'alphachar[alphachar]...['='arg | ' 'arg]
arg := boolarg | intarg | floatarg | stringarg
boolarg := 'true' | 'false'


ne¶
[Source]
fun box ne(
that: MinHeapPriority[A] val)
: Bool val

Parameters¶

that: MinHeapPriority[A] val

Returns¶

Bool val


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111


912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931


Public Functions¶
eq¶
[Source]
fun box eq(
that: EraseRight val)
: Bool val

Parameters¶

that: EraseRight val

Returns¶

Bool val

ne¶
[Source]


if alloc > len then
_alloc = alloc
else
_alloc = len
end
end

_ptr = ptr

fun _copy_to(
ptr: Pointer[this->A!],
copy_len: USize,
from_offset: USize = 0,
to_offset: USize = 0)
=>
"""
Copy copy_len elements from this to that at specified offsets.
"""
_ptr._offset(from_offset)._copy_to(ptr._offset(to_offset), copy_len)


Create a generator for `MapIs` from a generator of key-value tuples.
The generated maps will have a size up to `max`,
but tend to have fewer entries depending on the source generator `gen`.

If the generator generates key-value pairs with
duplicate keys (based on identity),
the pair that is generated later will overwrite earlier entries in the map.
"""
Generator[MapIs[K, V]](
object is GenObj[MapIs[K, V]]
fun generate(rnd: Randomness): GenerateResult[MapIs[K, V]] =>
let size = rnd.usize(0, max)

let result: MapIs[K, V] =
MapIs[K, V].create(size).>concat(
Iter[(K^, V^)](gen.value_iter(rnd))
.take(size)
)
let shrink_iter: Iterator[MapIs[K, V]^] =
Iter[USize](CountdownIter(size, 0)) //Range(size, 0, -1))


fun box sctp_partial_delivery_point()
: I32 val

Returns¶

I32 val

sctp_pcb_copy_flags¶
[Source]
fun box sctp_pcb_copy_flags()
: I32 val

Returns¶

I32 val

sctp_pcb_flags_accepting¶
[Source]


None val

skip¶
[Source]
Skip the first n values of the iterator.
Example¶
Iter[I64]([1; 2; 3; 4; 5; 6].values())
.skip(3)

4 5 6
Iter[I64]([1; 2; 3].values())
.skip(3)
.has_next()

false
fun ref skip(
n: USize val)
: Iter[A] ref^


A

op_or¶
[Source]
fun box op_or(
y: A)
: A

Parameters¶

y: A

Returns¶

A

op_xor¶
[Source]


fun ipv6_fl_a_put():I32 => @pony_os_sockopt_option(I32(122))
fun ipv6_fl_a_renew():I32 => @pony_os_sockopt_option(I32(123))
fun ipv6_fl_f_create():I32 => @pony_os_sockopt_option(I32(124))
fun ipv6_fl_f_excl():I32 => @pony_os_sockopt_option(I32(125))
fun ipv6_fl_f_reflect():I32 => @pony_os_sockopt_option(I32(126))
fun ipv6_fl_f_remote():I32 => @pony_os_sockopt_option(I32(127))
fun ipv6_fl_s_any():I32 => @pony_os_sockopt_option(I32(128))
fun ipv6_fl_s_excl():I32 => @pony_os_sockopt_option(I32(129))
fun ipv6_fl_s_none():I32 => @pony_os_sockopt_option(I32(130))
fun ipv6_fl_s_process():I32 => @pony_os_sockopt_option(I32(131))
fun ipv6_fl_s_user():I32 => @pony_os_sockopt_option(I32(132))
fun ipv6_hoplimit():I32 => @pony_os_sockopt_option(I32(133))
fun ipv6_hopopts():I32 => @pony_os_sockopt_option(I32(134))
fun ipv6_ipsec_policy():I32 => @pony_os_sockopt_option(I32(135))
fun ipv6_join_anycast():I32 => @pony_os_sockopt_option(I32(136))
fun ipv6_leave_anycast():I32 => @pony_os_sockopt_option(I32(137))
fun ipv6_minhopcount():I32 => @pony_os_sockopt_option(I32(138))
fun ipv6_mtu():I32 => @pony_os_sockopt_option(I32(139))
fun ipv6_mtu_discover():I32 => @pony_os_sockopt_option(I32(140))
fun ipv6_multicast_hops():I32 => @pony_os_sockopt_option(I32(141))


fun box divrem(
y: U32 val)
: (U32 val , U32 val)

Parameters¶

y: U32 val

Returns¶

(U32 val , U32 val)

rem¶
[Source]
fun box rem(
y: U32 val)
: U32 val

Parameters¶


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151


fun box usize()
: USize val

Returns¶

USize val

f32¶
[Source]
fun box f32()
: F32 val

Returns¶

F32 val

f64¶
[Source]


fun box pvd_config()
: I32 val

Returns¶

I32 val

rds_cancel_sent_to¶
[Source]
fun box rds_cancel_sent_to()
: I32 val

Returns¶

I32 val

rds_cmsg_atomic_cswp¶
[Source]


(I8 val , Bool val)

fldc¶
[Source]
fun box fldc(
y: I8 val)
: (I8 val , Bool val)

Parameters¶

y: I8 val

Returns¶

(I8 val , Bool val)

modc¶
[Source]


msg: String val,
verbose: Bool val = false)
: None val

Parameters¶

msg: String val
verbose: Bool val = false

Returns¶

None val

fail¶
[Source]
Flag the test as having failed.
fun box fail(
msg: String val = "Test failed")
: None val


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191