fun box u128()
: U128 val

Returns¶

U128 val

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

Returns¶

ULong val

usize¶
[Source]


1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351


: None val

Parameters¶

h: TestHelper val

Returns¶

None val

label¶
[Source]
Report the test label, returning an empty string for none.
It can be later use to filter tests which we want to run, by labels.
fun box label()
: String val

Returns¶


ANSITerm¶
[Source]
Handles ANSI escape codes from stdin.
actor tag ANSITerm

Constructors¶
create¶
[Source]
Create a new ANSI term.
new tag create(
notify: ANSINotify iso,
source: DisposableActor tag,
timers: Timers tag = reference)


fun box mkdirat()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

mknodat¶
[Source]


Returns¶

None val

filter¶
[Source]
Filtering the empty list yields the empty list.
fun box filter(
f: {(val->A): Bool}[A] box)
: Nil[A] val

Parameters¶

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

Returns¶

Nil[A] val


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


fun box min(
y: I8 val)
: I8 val

Parameters¶

y: I8 val

Returns¶

I8 val

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

Parameters¶


fun ip_bound_if():I32 => @pony_os_sockopt_option(I32(242))
fun ip_checksum():I32 => @pony_os_sockopt_option(I32(243))
fun ip_default_multicast_loop():I32 => @pony_os_sockopt_option(I32(244))
fun ip_default_multicast_ttl():I32 => @pony_os_sockopt_option(I32(245))
fun ip_dontfrag():I32 => @pony_os_sockopt_option(I32(246))
fun ip_drop_membership():I32 => @pony_os_sockopt_option(I32(247))
fun ip_drop_source_membership():I32 => @pony_os_sockopt_option(I32(248))
fun ip_dummynet3():I32 => @pony_os_sockopt_option(I32(249))
fun ip_dummynet_configure():I32 => @pony_os_sockopt_option(I32(250))
fun ip_dummynet_del():I32 => @pony_os_sockopt_option(I32(251))
fun ip_dummynet_flush():I32 => @pony_os_sockopt_option(I32(252))
fun ip_dummynet_get():I32 => @pony_os_sockopt_option(I32(253))
fun ip_faith():I32 => @pony_os_sockopt_option(I32(254))
fun ip_flowid():I32 => @pony_os_sockopt_option(I32(255))
fun ip_flowtype():I32 => @pony_os_sockopt_option(I32(256))
fun ip_freebind():I32 => @pony_os_sockopt_option(I32(257))
fun ip_fw3():I32 => @pony_os_sockopt_option(I32(258))
fun ip_fw_add():I32 => @pony_os_sockopt_option(I32(259))
fun ip_fw_del():I32 => @pony_os_sockopt_option(I32(260))
fun ip_fw_flush():I32 => @pony_os_sockopt_option(I32(261))


log(
_format_loc(loc) + "Assert " + check + " passed. " + msg
+ " Got (" + (digestof expect).string() + ") is ("
+ (digestof actual).string() + ")",
true)
true

fun assert_eq[A: (Equatable[A] #read & Stringable #read)]
(expect: A, actual: A, msg: String = "", loc: SourceLoc = __loc): Bool
=>
"""
Assert that the 2 given expressions are equal.
"""
_check_eq[A]("eq", expect, actual, msg, loc)

fun _check_eq[A: (Equatable[A] #read & Stringable)]
(check: String, expect: A, actual: A, msg: String, loc: SourceLoc)
: Bool
=>


: None val

Parameters¶

node: ListNode[A] ref

Returns¶

None val

append_list¶
[Source]
Empties the provided List by appending all elements onto the receiving List.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = List[String].from(["d"; "e"; "f"])
my_list.append_list(other_list)  // my_list is ["a"; "b"; "c"; "d"; "e"; "f"], other_list is empty

fun ref append_list(
that: List[A] ref)


Property3UnitTest[T1: T1, T2: T2, T3: T3]¶
[Source]
class iso Property3UnitTest[T1: T1, T2: T2, T3: T3] is
UnitTest ref

Implements¶

UnitTest ref

Constructors¶
create¶
[Source]


overhead¶
[Source]
fun box overhead()
: AsyncMicroBenchmark iso^

Returns¶

AsyncMicroBenchmark iso^

before¶
[Source]
fun ref before(
c: AsyncBenchContinue val)
: None val

Parameters¶

c: AsyncBenchContinue val


fun box ip_pmtudisc_probe()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_portrange¶
[Source]


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


fun ref remove(that: CapRights0) =>
"""
Remove the rights in that from this.
"""
ifdef freebsd or "capsicum" then
@cap_rights_remove(addressof _r0, addressof that._r0)
end

fun ref clear() =>
"""
Clear all rights.
"""
ifdef freebsd or "capsicum" then
@__cap_rights_init(_version(), addressof _r0, U64(0))
end

fun contains(that: CapRights0): Bool =>
"""
Check that this is a superset of the rights in that.


White background.
fun box white_bg()
: String val

Returns¶

String val

bright_red_bg¶
[Source]
Bright red background.
fun box bright_red_bg()
: String val

Returns¶

String val


# The effect of annotations

Annotations are entirely implementation-specific. In other words, the Pony compiler (or any other tool that processes Pony programs) is free to take any action for any annotation that it encounters, including not doing anything at all. Annotations starting with `ponyint` are reserved by the compiler for internal use and shouldn't be used by external tools.


fun box sctp_auto_asconf()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_bindx_add_addr¶
[Source]


Collections package¶
The Collections package provides a variety of collection classes,
including map, set, range, heap, ring buffer, list, and flags.
Map - Hashmap by strutural equality (use MapIs for identity equality).
Set - A set built on top of Map using structural equility (use SetIs for identity equality).
Range - Iterate over a range of numbers with optional step size.
BinaryHeap - A priority queue implemented as a binary heap -- use a BinaryHeapPriority parameter to determine priority.
RingBuffer - A ring buffer with fixed size.
List - A doubly linked list.
Flags - A set of single bit flags (size determined upon creation).
Public Types¶

class BinaryHeap


fun rds_info_iwarp_connections():I32 => @pony_os_sockopt_option(I32(462))
fun rds_info_last():I32 => @pony_os_sockopt_option(I32(463))
fun rds_info_message_flag_ack():I32 => @pony_os_sockopt_option(I32(464))
fun rds_info_message_flag_fast_ack():I32 => @pony_os_sockopt_option(I32(465))
fun rds_info_recv_messages():I32 => @pony_os_sockopt_option(I32(466))
fun rds_info_retrans_messages():I32 => @pony_os_sockopt_option(I32(467))
fun rds_info_send_messages():I32 => @pony_os_sockopt_option(I32(468))
fun rds_info_sockets():I32 => @pony_os_sockopt_option(I32(469))
fun rds_info_tcp_sockets():I32 => @pony_os_sockopt_option(I32(470))
fun rds_rdma_canceled():I32 => @pony_os_sockopt_option(I32(471))
fun rds_rdma_dontwait():I32 => @pony_os_sockopt_option(I32(472))
fun rds_rdma_dropped():I32 => @pony_os_sockopt_option(I32(473))
fun rds_rdma_fence():I32 => @pony_os_sockopt_option(I32(474))
fun rds_rdma_invalidate():I32 => @pony_os_sockopt_option(I32(475))
fun rds_rdma_notify_me():I32 => @pony_os_sockopt_option(I32(476))
fun rds_rdma_other_error():I32 => @pony_os_sockopt_option(I32(477))
fun rds_rdma_readwrite():I32 => @pony_os_sockopt_option(I32(478))
fun rds_rdma_remote_error():I32 => @pony_os_sockopt_option(I32(479))
fun rds_rdma_silent():I32 => @pony_os_sockopt_option(I32(480))
fun rds_rdma_success():I32 => @pony_os_sockopt_option(I32(481))


let r =
ifdef bigendian then
data.read_u64(offset)?
else
data.read_u64(offset)?.bswap()
end

offset = offset + num_bytes
_available = _available - num_bytes

if offset < data.size() then
node()? = (data, offset)
else
_chunks.shift()?
end
r
else
// single array did not have all the bytes needed
(u8()?.u64() << 56) or (u8()?.u64() << 48) or
(u8()?.u64() << 40) or (u8()?.u64() << 32) or


i: U32 val

Returns¶

F32 val^

from[B: ((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[B] val)]¶
[Source]
new val from[B: ((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[B] val)](
a: B)
: F32 val^

Parameters¶


392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411


# Classes

Just like other object-oriented languages, Pony has __classes__. A class is declared with the keyword `class`, and it has to have a name that starts with a capital letter, like this:

```pony
class Wombat
```

__Do all types start with a capital letter?__ Yes! And nothing else starts with a capital letter. So when you see a name in Pony code, you will instantly know whether it's a type or not.


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


ne¶
[Source]
Returns false if the sets contain the same elements.
fun box ne(
that: HashSet[A, H] box)
: Bool val

Parameters¶

that: HashSet[A, H] box

Returns¶

Bool val

lt¶
[Source]
Returns true if every element in this is also in that, and this has fewer
elements than that.


fun val update(key: K, value: val->V): HashMap[K, V, H] =>
"""
Update the value associated with the provided key.
"""
(let r, let insertion) =
try
_root.update(0, H.hash(key).u32(), key, value)?
else
(_root, false) // should not occur
end
let s = if insertion then _size + 1 else _size end
_create(r, s)

fun val remove(k: K): HashMap[K, V, H] ? =>
"""
Try to remove the provided key from the Map.
"""
_create(_root.remove(0, H.hash(k).u32(), k)?, _size - 1)


new ref create(
choice': U8 val,
int1': U128 val,
int2': U128 val)
: IntPairPropertySample ref^

Parameters¶

choice': U8 val
int1': U128 val
int2': U128 val

Returns¶

IntPairPropertySample ref^

Public fields¶
let choice: U8 val¶
[Source]


Array[NetAddress val] iso^

ip6¶
[Source]
Gets all IPv6 addresses for a host and service.
fun box ip6(
auth: DNSAuth val,
host: String val,
service: String val)
: Array[NetAddress val] iso^

Parameters¶

auth: DNSAuth val
host: String val
service: String val

Returns¶


env.pony

1
2
3
4
5
6
7
8
9
10
11


U64 val^

max_value¶
[Source]
new val max_value()
: U64 val^

Returns¶

U64 val^

Public Functions¶
next_pow2¶
[Source]
fun box next_pow2()
: U64 val

Returns¶


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


If the property fails using an assertion method of
[PropertyHelper](pony_check-PropertyHelper.md),
the failed example will be shrunken by the generator
to obtain a smaller and more informative, still failing, sample
for reporting.

"""
use "pony_test"

primitive PonyCheck
fun for_all[T](gen: Generator[T] val, h: TestHelper): ForAll[T] =>
"""
Convenience method for running 1 to many properties as part of
one PonyTest UnitTest.

Example:

```pony
class MyTestWithSomeProperties is UnitTest
fun name(): String => "mytest/withMultipleProperties"


else
_fd = ifdef windows then
@_open(path.path.cstring(), @ponyint_o_rdonly())
else
@open(path.path.cstring(), @ponyint_o_rdonly())
end

if _fd == -1 then
_errno = _get_error()
else
try
_FileDes.set_rights(_fd, path, writeable)?
else
_errno = FileError
end
end
end

new _descriptor(fd: I32, from: FilePath) ? =>
"""


532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551


end

node

fun ref remove(i: USize): ListNode[A] ? =>
"""
Remove the i-th node, raising an error if the index is out of bounds, and
returning the removed node.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.remove(0)? end // Returns a ListNode[String] containing "a" and List now contains ["b"; "c"]
```
"""
index(i)? .> remove()

fun ref clear() =>
"""
Empties the list.
"""


Parameters¶

n: N

Returns¶

N

real¶
[Source]
A random number in [0, 1)
fun ref real()
: F64 val

Returns¶

F64 val


F32 val ?

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

Returns¶

F64 val ?

f64_le¶
[Source]
Get a little-endian F64.
fun ref f64_le()
: F64 val ?


Parameters¶

that: AsioEvent val

Returns¶

Bool val


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


Parameters¶

y: B

Returns¶

A

popcount¶
[Source]
fun box popcount()
: B

Returns¶

B

clz¶


|         | (2) intersection                                                                |
| `@`     | FFI call                                                                        |
| `//`    | comments                                                                        |
| `/* */` | multi-line or block comments                                                    |
| `=>`    | (1) start of a function body                                                    |
|         | (2) starts the code of a matching branch                                        |
| `->`    | (1) arrow type                                                                  |
|         | (2) viewpoint                                                                   |
| `._i`   | where `i = 1,2,…`  means the item at position i in the tuple                                |
| `<:`    | "is a subtype of" or "can be substituted for"                                   |


fun box sctp_add_streams()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_asconf¶
[Source]


1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651


fun generate(rnd: Randomness): GenerateResult[box->T] =>
if do_shrink then
(_t, Iter[box->T].repeat_value(_t))
else
_t
end
end)

fun none[T: None](): Generator[(T | None)] => Generators.unit[(T | None)](None)

fun repeatedly[T](f: {(): T^ ?} box): Generator[T] =>
"""
Generate values by calling the lambda `f` repeatedly,
once for every invocation of `generate`.

`f` needs to return an ephemeral type `T^`, that means
in most cases it needs to consume its returned value.
Otherwise we would end up with
an alias for `T` which is `T!`.
(e.g. `String iso` would be returned as `String iso!`,


auth_failed¶
[Source]
A raw TCPConnection has no authentication mechanism. However, when
protocols are wrapped in other protocols, this can be used to report an
authentication failure in a lower level protocol (e.g. SSL).
fun ref auth_failed(
conn: TCPConnection ref)
: None val

Parameters¶

conn: TCPConnection ref

Returns¶

None val

sent¶


Returns¶

F64 val

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

Returns¶

F64 val

atan2¶
[Source]
fun box atan2(
y: F64 val)
: F64 val


fn: {(T): Generator[U]}[T, U] box

Returns¶

Generator[U] box

union[U: U]¶
[Source]
Create a generator that produces the value of this generator or the other
with the same probability, returning a union type of this generator and
the other one.
fun box union[U: U](
other: Generator[U] box)
: Generator[(T | U)] box

Parameters¶

other: Generator[U] box


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


fun box dccp_sockopt_server_timewait()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dccp_sockopt_tx_ccid¶
[Source]


CapError¶
[Source]
primitive val CapError

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

Returns¶

CapError val^


insert_if_absent¶
[Source]
Set a value in the map if the key doesn't already exist in the Map.
Saves an extra lookup when doing a pattern like:
if not my_map.contains(my_key) then
my_map(my_key) = my_value
end

Returns the value, the same as insert, allowing 'insert_if_absent'
to be used as a drop-in replacement for insert.
fun ref insert_if_absent(
key: K,
value: V)
: V!

Parameters¶

key: K
value: V


fun box ne(
that: FileBadFileNumber val)
: Bool val

Parameters¶

that: FileBadFileNumber val

Returns¶

Bool val


fun box sctp_reset_assoc()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_reuse_port¶
[Source]


Assert that the contents of the 2 given ReadSeqs are equal.
The type parameter of this function is the type parameter of the
elements in both ReadSeqs. For instance, when comparing two Array[U8],
you should call this method as follows:
fun apply(h: TestHelper) =>
let a: Array[U8] = [1; 2; 3]
let b: Array[U8] = [1; 2; 3]
h.assert_array_eq[U8](a, b)

fun box assert_array_eq[A: (Equatable[A] #read & Stringable #read)](
expect: ReadSeq[A] box,
actual: ReadSeq[A] box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val

Parameters¶

expect: ReadSeq[A] box
actual: ReadSeq[A] box


Return an iterator for the elements in the heap. The order of elements is
arbitrary.
fun box values()
: ArrayValues[A, this->Array[A] ref] ref^

Returns¶

ArrayValues[A, this->Array[A] ref] ref^


list: TestList tag)
: PonyTest tag^

Parameters¶

env: Env val
list: TestList tag

Returns¶

PonyTest tag^

Public Behaviours¶
apply¶
[Source]
Run the given test, subject to our filters and options.
be apply(
test: UnitTest iso)


Bool val

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

Returns¶

Bool val

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

Returns¶


fun box usize()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64¶
[Source]


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


fun box min(
y: I16 val)
: I16 val

Parameters¶

y: I16 val

Returns¶

I16 val

max¶
[Source]
fun box max(
y: I16 val)
: I16 val

Parameters¶


: USize val

Returns¶

USize val

i8¶
[Source]
fun ref i8()
: I8 val

Returns¶

I8 val

i16¶
[Source]
fun ref i16()


Parser¶
Programs then use the CommandSpec they've built to instantiate a parser to
parse any given command line. This is often env.args(), but could also be
commands from files or other input sources. The result of a parse is either a
parsed command, a command help, or a syntax error object.
Commands¶
Programs then match the object returned by the parser to determine what kind
it is. Errors and help requests typically print messages and exit. For
commands, the fullname can be matched and the effective values for the
command's options and arguments can be retrieved.
Example program¶
This program echos its command line arguments with the option of uppercasing
them.
use "cli"

actor Main
new create(env: Env) =>
let cs =
try
CommandSpec.leaf("echo", "A sample echo program", [


f: {ref(A!): B ?}[A, B] ref)
: Iter[B] ref^

Parameters¶

f: {ref(A!): B ?}[A, B] ref

Returns¶

Iter[B] ref^

filter_stateful¶
[Source]
Allows filtering of elements based on a stateful adapter, similar to
filter.
fun ref filter_stateful(
f: {ref(A!): Bool ?}[A] ref)
: Iter[A!] ref^


then
return false
end

try
let path' = FilePath.from(path, target, path.caps)?

ifdef linux or bsd then
0 == @fchownat(_fd, target.cstring(), uid, gid, I32(0))
else
path'.chown(uid, gid)
end
else
false
end

fun touchat(target: String): Bool =>
"""
Set the last access and modification times of the directory to now.
"""


# How to create Arrays with values

Single values can be separated by semicolon or newline.

```pony
let dice: Array[U32] = [1; 2; 3
4
5
6
]
```


fun box ne(
that: EraseLine val)
: Bool val

Parameters¶

that: EraseLine val

Returns¶

Bool val


fun ref i64(
min: I64 val = call,
max: I64 val = call)
: I64 val

Parameters¶

min: I64 val = call
max: I64 val = call

Returns¶

I64 val

i128¶
[Source]
Generate a I128 in closed interval [min, max]
(default: [min_value, max_value]).
Behavior is undefined if min > max.


FileOK¶
[Source]
primitive val FileOK

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

Returns¶

FileOK val^


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


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

Parameters¶

that: IniParse val

Returns¶

Bool val

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


OptionSpec.bool("upper", "Uppercase words"
where short' = 'U', default' = false)
], [
ArgSpec.string_seq("words", "The words to echo")
])? .> add_help()?
else
env.exitcode(-1)  // some kind of coding error
return
end

let cmd =
match CommandParser(cs).parse(env.args, env.vars)
| let c: Command => c
| let ch: CommandHelp =>
ch.print_help(env.out)
env.exitcode(0)
return
| let se: SyntaxError =>
env.out.print(se.string())
env.exitcode(1)


if not _required then "=" + _default.string() else "" end

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

class val ArgSpec
"""
ArgSpec describes the specification of a positional Arg(ument). They have a
name, descr(iption), a typ(e), and a default value when they are not
required.

Args always come after a leaf command, and are assigned in their positional
order.
"""
let _name: String
let _descr: String
let _typ: _ValueType
let _default: _Value
let _required: Bool


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


 Base64 package

The Base64 package contains support for doing Base64 binary-to-text encodings.
We currently have support 3 encodings: PEM, MIME and URL.

To learn more about Base64, we suggest you check out the
[wikipedia entry](https://en.wikipedia.org/wiki/Base64).


String ref^

Public Functions¶
push_utf32¶
[Source]
Push a UTF-32 code point.
fun ref push_utf32(
value: U32 val)
: None val

Parameters¶

value: U32 val

Returns¶

None val


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


fun ref _mod(): (Bool, Bool, Bool) =>
"""
Set the modifier bools.
"""
let r = match _esc_mod
| 2 => (false, false, true)
| 3 => (false, true, false)
| 4 => (false, true, true)
| 5 => (true, false, false)
| 6 => (true, false, true)
| 7 => (true, true, false)
| 8 => (true, true, true)
else (false, false, false)
end

_esc_mod = 0
r

fun ref _keypad() =>
"""


: None val

Parameters¶

sock: UDPSocket ref

Returns¶

None val

not_listening¶
[Source]
Called if it wasn't possible to bind the socket to an address.
It is expected to implement proper error handling. You need to opt in to
ignoring errors, which can be implemented like this:
fun ref not_listening(sock: UDPSocket ref) =>
None

fun ref not_listening(


out.reserve((len + (step - 1)) / step)

if step == 1 then
copy_to(out, from, 0, len)
else
try
var i = from

while i < last do
out.push(this(i)?)
i = i + step
end
end
end
end

out

fun permute(indices: Iterator[USize]): Array[this->A!]^ ? =>
"""


end
true

fun ref errors(line: USize, err: IniError): Bool =>
false
end

if not Ini(lines, f) then
error
end

map


fun index(i: USize): this->ListNode[A] ? =>
"""
Gets the i-th node, raising an error if the index is out of bounds.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.index(0)? end // Returns a ListNode[String] containing "a"
```
"""
if i >= _size then
error
end

var node = _head as this->ListNode[A]
var j = USize(0)

while j < i do
node = node.next() as this->ListNode[A]
j = j + 1


fun box netrom_n2()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netrom_node¶
[Source]


112
113
114
115
116
117
118
119
120
121
122class Range[A: (Real[A] val & Number) = USize] is Iterator[A]
"""
Produces `[min, max)` with a step of `inc` for any `Number` type.

```pony
// iterating with for-loop
for i in Range(0, 10) do
env.out.print(i.string())
end


// Create a third List from a Seq(ence)
// (In this case a literal array of Strings)
let my_third_list = List[String].from(["First"; "Second"; "Third"])
env.out.print("A list created from an array of three strings has size: "
+ my_third_list.size().string()) // 3
for n in my_third_list.values() do
env.out.print("\t" + n.string())
end

// Map over the third List, concatenating some "BOOM!'s" into a new List
let new_list = my_third_list.map[String]({ (n) => n + " BOOM!" })
env.out.print("Mapping over our three-node list produces a new list of size: "
+ new_list.size().string()) // 3
env.out.print("Each node-value in the resulting list is now far more exciting:")
for n in new_list.values() do
env.out.print("\t" + n.string())
end

// Filter the new list to extract 2 elements


fun box ipv6_authhdr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_checksum¶
[Source]


interface tag _IPropertyRunner
"""
Interface for a PropertyRunner without the generic type parameter,
and only with the behaviours we are interested in.
"""

be expect_action(name: String, round: _Round)

be complete_action(name: String, round: _Round, ph: PropertyHelper)

be fail_action(name: String, round: _Round, ph: PropertyHelper)

be dispose_when_done(disposable: DisposableActor, round: _Round)

be log(msg: String, verbose: Bool = false)

class val PropertyHelper
"""
Helper for PonyCheck properties.


doesn't allocate a wrapper object: there is no containing object for that.
new ref create(
that: A)
: NullablePointer[A] ref^

Parameters¶

that: A

Returns¶

NullablePointer[A] ref^

none¶
[Source]
This returns a null pointer typed as a NullablePointer[A].
new ref none()
: NullablePointer[A] ref^


fun sem_getvalue(): U64 => _id(1, 1 << 2)
fun sem_post(): U64 => _id(1, 1 << 3)
fun sem_wait(): U64 => _id(1, 1 << 4)

fun event(): U64 => _id(1, 1 << 5)
fun kqueue_event(): U64 => _id(1, 1 << 6)
fun ioctl(): U64 => _id(1, 1 << 7)
fun ttyhook(): U64 => _id(1, 1 << 8)

fun pdgetpid(): U64 => _id(1, 1 << 9)
fun pdwait(): U64 => _id(1, 1 << 10)
fun pdkill(): U64 => _id(1, 1 << 11)

fun exattr_delete(): U64 => _id(1, 1 << 12)
fun exattr_get(): U64 => _id(1, 1 << 13)
fun exattr_list(): U64 => _id(1, 1 << 14)
fun exattr_set(): U64 => _id(1, 1 << 15)

fun acl_check(): U64 => _id(1, 1 << 16)


new val create(
value: F32 val = 0)
: F32 val^

Parameters¶

value: F32 val = 0

Returns¶

F32 val^

pi¶
[Source]
new val pi()
: F32 val^

Returns¶


let help_option = options(_help_name())?
if help_option.bool() then
return
if _spec is _root_spec() then
Help.general(_root_spec())
else
Help.for_command(_root_spec(), [_spec.name()])
end
end
end

// If it's a help command, return a general or specific CommandHelp.
if _spec.name() == _help_name() then
try
match args("command")?.string()
| "" => return Help.general(_root_spec())
| let c: String => return Help.for_command(_root_spec(), [c])
end
end
return Help.general(_root_spec())


let ip = recover NetAddress end
@pony_os_getaddr(addr, ip)
list.push(consume ip)
addr = @pony_os_nextaddr(addr)
end

@freeaddrinfo(result)
end

list


fun box sctp_bindx_add_addr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_blk_logging_enable¶
[Source]


is_sep(path(0)?) or _drive_letter(path)
else
is_sep(path(0)?)
end
else
false
end

fun join(path: String, next_path: String): String =>
"""
Join two paths together. If the next_path is absolute, simply return it.
The returned path will be cleaned.
"""
if path.size() == 0 then
clean(next_path)
elseif next_path.size() == 0 then
clean(path)
elseif is_abs(next_path) then
clean(next_path)
else


fun box map_of[K: (Hashable #read & Equatable[K] #read), V: V](
gen: Generator[(K , V)] box,
max: USize val = 100)
: Generator[HashMap[K, V, HashEq[K] val] ref] box

Parameters¶

gen: Generator[(K , V)] box
max: USize val = 100

Returns¶

Generator[HashMap[K, V, HashEq[K] val] ref] box

map_is_of[K: K, V: V]¶
[Source]
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.


Parameters¶

y: ISize val

Returns¶

ISize val

sub¶
[Source]
fun box sub(
y: ISize val)
: ISize val

Parameters¶

y: ISize val

Returns¶


Parameters¶

y: A

Returns¶

A

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

Parameters¶

y: A

Returns¶


i32¶
fun ref i32()
: I32 val

Returns¶

I32 val

i64¶
fun ref i64()
: I64 val

Returns¶

I64 val


if linux or bsd
use @unlinkat[I32](fd: I32, target: Pointer[U8] tag, flags: I32)
use @futimes[I32](fildes: I32, tv: Pointer[(ILong, ILong, ILong, ILong)])
if not windows
use @renameat[I32](fd: I32, from: Pointer[U8] tag, tofd: I32, to_path: Pointer[U8] tag)
if linux or bsd
use @symlinkat[I32](source: Pointer[U8] tag, fd: I32, dst: Pointer[U8] tag) if linux or bsd
use @futimesat[I32](fd: I32, path: Pointer[U8] tag,
timeval: Pointer[(ILong, ILong, ILong, ILong)]) if linux or bsd
use @fchownat[I32](fd: I32, path: Pointer[U8] tag, uid: U32, gid: U32, flags: I32) if linux or bsd
use @fchmodat[I32](fd: I32, path: Pointer[U8] tag, mode: U32, flag: I32) if linux or bsd
use @mkdirat[I32](fd: I32, path: Pointer[U8] tag, mode: U32)
use @fdopendir[Pointer[_DirectoryHandle]](fd: I32) if posix
use @opendir[Pointer[_DirectoryHandle]](name: Pointer[U8] tag) if posix
use @closedir[I32](dir: Pointer[_DirectoryHandle] tag) if posix
use @ponyint_unix_readdir[Pointer[U8] iso^](dir: Pointer[None] tag)
use @ponyint_windows_find_data[Pointer[_DirectoryEntry]]()
if windows
use @ponyint_windows_find_data_free[None](data: Pointer[_DirectoryEntry])
if windows


Called when ProcessMonitor terminates to cleanup ProcessNotify if a child
process was in fact started. `dispose` will not be called if a child process
was never started. The notify will know that a process was started and to
expect a `dispose` call by having received a `created` call.

`dispose` includes the exit status of the child process. If the process
finished, then `child_exit_status` will be an instance of [Exited](process-Exited.md).

The childs exit code can be retrieved from the `Exited` instance by using
[Exited.exit_code()](process-Exited.md#exit_code).

On Posix systems, if the process has been killed by a signal (e.g. through
the `kill` command), `child_exit_status` will be an instance of
[Signaled](process-Signaled.md) with the signal number that terminated the
process available via [Signaled.signal()](process-Signaled.md#signal).
"""


Itertools Package¶
The itertools package provides the Iter class for doing useful things with
iterators. It is Inspired by Python's itertools library, Rust's Iterator, and
Elixir's Enum and Stream.
Iter¶
The Iter class wraps iterators so that additional methods may be applied to it.
Some methods, such as fold and collect, run through the underlying iterator in
order to return a result. Others, such as map and filter, are lazy. This means
that they return another Iter so that the resulting values are computed one by
one as needed. Lazy methods return Iter types.
For example, the following code creates an Iter from the values of an array
containing the numbers 1 through 5, increments each number by one, filters out
any odd numbers, and prints the rest.


fun af_inet6():I32 => @pony_os_sockopt_option(I32(2))
fun bluetooth_proto_sco():I32 => @pony_os_sockopt_option(I32(3))
fun dccp_nr_pkt_types():I32 => @pony_os_sockopt_option(I32(4))
fun dccp_service_list_max_len():I32 => @pony_os_sockopt_option(I32(5))
fun dccp_single_opt_maxlen():I32 => @pony_os_sockopt_option(I32(6))
fun dccp_sockopt_available_ccids():I32 => @pony_os_sockopt_option(I32(7))
fun dccp_sockopt_ccid():I32 => @pony_os_sockopt_option(I32(8))
fun dccp_sockopt_ccid_rx_info():I32 => @pony_os_sockopt_option(I32(9))
fun dccp_sockopt_ccid_tx_info():I32 => @pony_os_sockopt_option(I32(10))
fun dccp_sockopt_change_l():I32 => @pony_os_sockopt_option(I32(11))
fun dccp_sockopt_change_r():I32 => @pony_os_sockopt_option(I32(12))
fun dccp_sockopt_get_cur_mps():I32 => @pony_os_sockopt_option(I32(13))
fun dccp_sockopt_packet_size():I32 => @pony_os_sockopt_option(I32(14))
fun dccp_sockopt_qpolicy_id():I32 => @pony_os_sockopt_option(I32(15))
fun dccp_sockopt_qpolicy_txqlen():I32 => @pony_os_sockopt_option(I32(16))
fun dccp_sockopt_recv_cscov():I32 => @pony_os_sockopt_option(I32(17))
fun dccp_sockopt_rx_ccid():I32 => @pony_os_sockopt_option(I32(18))
fun dccp_sockopt_send_cscov():I32 => @pony_os_sockopt_option(I32(19))
fun dccp_sockopt_server_timewait():I32 => @pony_os_sockopt_option(I32(20))
fun dccp_sockopt_service():I32 => @pony_os_sockopt_option(I32(21))


Only x is used, y is discarded.
new ref create(
x: U64 val = 5489,
y: U64 val = 0)
: SplitMix64 ref^

Parameters¶

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

Returns¶

SplitMix64 ref^

Public Functions¶
next¶
[Source]
fun ref next()


Returns¶

File iso^ ?

open_file¶
[Source]
Open for read only, failing if it doesn't exist.
fun box open_file(
target: String val)
: File iso^ ?

Parameters¶

target: String val

Returns¶

File iso^ ?


The classical list-reverse example:
use "collections"
use "pony_check"

class ListReverseProperty is Property1[List[USize]]
fun name(): String => "list/reverse"

fun gen(): Generator[List[USize]] =>
Generators.list_of[USize](Generators.usize())

fun property(arg1: List[USize], ph: PropertyHelper) =>
ph.array_eq[USize](arg1, arg1.reverse().reverse())

Integration into PonyTest¶
There are two ways of integrating a Property into
PonyTest:

In order to pass your Property to the PonyTest engine, you need to wrap it
inside a Property1UnitTest.


[Source]
fun box shr(
y: A)
: A

Parameters¶

y: A

Returns¶

A

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


U32 val

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

Returns¶

U64 val

u128¶
[Source]
fun box u128()
: U128 val

Returns¶


from: AmbientAuth val

Returns¶

NetAuth val^

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

Parameters¶

that: NetAuth val

Returns¶


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


fun box ipv6_priority_15()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_priority_9¶
[Source]


end

Public Types¶

primitive Base64


Bool val


{
void(*fun_ptr)();
};
```

In the same vein as bare functions, bare lambdas cannot specify captures, cannot use `this` neither as an identifier nor as a type, and cannot specify a receiver capability. In addition, a bare lambda object always has a `val` capability.

Classic lambda types and bare lambda types can never be subtypes of each other.


fun box netlink_broadcast_error()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_connector¶
[Source]


class HashSet
type List
primitive Lists
type Map
type MapIs
class MapKeys
class MapPairs
class MapValues
primitive Nil
type Set
type SetIs
class Vec
class VecKeys
class VecPairs
class VecValues


None val

difference¶
[Source]
Remove elements in this which are also in that. Add elements in that which
are not in this.
fun ref difference(
that: Iterator[A^] ref)
: None val

Parameters¶

that: Iterator[A^] ref

Returns¶

None val


create¶
[Source]
Create a node. Initially, it is not in any list.
new ref create(
item: (A | None val) = reference)
: ListNode[A] ref^

Parameters¶

item: (A | None val) = reference

Returns¶

ListNode[A] ref^

Public Functions¶
apply¶
[Source]
Return the item, if we have one, otherwise raise an error.


new val create(
from: FilePath val)
: FileInfo val^ ?

Parameters¶

from: FilePath val

Returns¶

FileInfo val^ ?

Public fields¶
let filepath: FilePath val¶
[Source]

let mode: FileMode val¶
[Source]
UNIX-style file mode.


Debug val^

Public Functions¶
apply¶
[Source]
If platform is debug configured, print either a single stringable or a
sequence of stringables. The default separator is ", ", and the default
output stream is stdout.
fun box apply(
msg: (Stringable box | ReadSeq[Stringable box] box),
sep: String val = ", ",
stream: (DebugOut val | DebugErr val) = reference)
: None val

Parameters¶

msg: (Stringable box | ReadSeq[Stringable box] box)
sep: String val = ", "
stream: (DebugOut val | DebugErr val) = reference


fun ref isize(
min: ISize val = call,
max: ISize val = call)
: ISize val

Parameters¶

min: ISize val = call
max: ISize val = call

Returns¶

ISize val

f32¶
[Source]
Generate a F32 in closed interval [min, max]
(default: [0.0, 1.0]).
fun ref f32(


"""

new val create(
base: FileAuth,
path': String,
caps': FileCaps val = recover val FileCaps .> all() end)
=>
"""
Create a new path to any location.

Unless absolute, path' will be relative to the program's working directory.

Capabilities are exactly as given.
"""
caps.union(caps')
path = Path.abs(path')

new val from(
base: FilePath,
path': String,


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


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


Parameters¶

c: AsyncBenchContinue val

Returns¶

None val

before_iteration¶
[Source]
fun ref before_iteration(
c: AsyncBenchContinue val)
: None val

Parameters¶

c: AsyncBenchContinue val


fun ref u16(
min: U16 val = call,
max: U16 val = call)
: U16 val

Parameters¶

min: U16 val = call
max: U16 val = call

Returns¶

U16 val

u32¶
[Source]
Generate a U32 in closed interval [min, max]
(default: [min_value, max_value]).
Behavior is undefined if min > max.


[Source]
fun ref u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶


# Actor literals

Normally, an object literal is an instance of an anonymous class. To make it an instance of an anonymous actor, just include one or more behaviours in the object literal definition.

```pony
object
be apply() => env.out.print("hi")
end
```

An actor literal is always returned as a `tag`.


fun so_proxyusr():I32 => @pony_os_sockopt_option(I32(882))
fun so_randomport():I32 => @pony_os_sockopt_option(I32(883))
fun so_rcvbuf():I32 => @pony_os_sockopt_option(I32(884))
fun so_rcvbufforce():I32 => @pony_os_sockopt_option(I32(885))
fun so_rcvlowat():I32 => @pony_os_sockopt_option(I32(886))
fun so_rcvtimeo():I32 => @pony_os_sockopt_option(I32(887))
fun so_rds_transport():I32 => @pony_os_sockopt_option(I32(888))
fun so_reuseaddr():I32 => @pony_os_sockopt_option(I32(889))
fun so_reuseport():I32 => @pony_os_sockopt_option(I32(890))
fun so_reuseshareuid():I32 => @pony_os_sockopt_option(I32(891))
fun so_rfcomm_fc_info():I32 => @pony_os_sockopt_option(I32(892))
fun so_rfcomm_mtu():I32 => @pony_os_sockopt_option(I32(893))
fun so_rxq_ovfl():I32 => @pony_os_sockopt_option(I32(894))
fun so_sco_conninfo():I32 => @pony_os_sockopt_option(I32(895))
fun so_sco_mtu():I32 => @pony_os_sockopt_option(I32(896))
fun so_security_authentication():I32 => @pony_os_sockopt_option(I32(897))
fun so_security_encryption_network():I32 => @pony_os_sockopt_option(I32(898))
fun so_security_encryption_transport():I32 => @pony_os_sockopt_option(I32(899))
fun so_select_err_queue():I32 => @pony_os_sockopt_option(I32(900))
fun so_setclp():I32 => @pony_os_sockopt_option(I32(901))


new val create()
: FormatExp val^

Returns¶

FormatExp val^

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

Parameters¶

that: FormatExp val

Returns¶


fun box dccp_sockopt_rx_ccid()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dccp_sockopt_server_timewait¶
[Source]


Iter[I64]([1; 2; 3].values())
.nth(2)

2
fun ref nth(
n: USize val)
: A ?

Parameters¶

n: USize val

Returns¶

A ?

run¶
[Source]
Iterate through the values of the iterator without a for loop. The


shift: Bool val

Returns¶

None val

fn_key¶
[Source]
fun ref fn_key(
i: U8 val,
ctrl: Bool val,
alt: Bool val,
shift: Bool val)
: None val

Parameters¶

i: U8 val
ctrl: Bool val


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


Checks whether the set contains the value.
"""
_map.contains(value)

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

fun ref set(value: A) =>
"""
Add a value to the set.
"""
_map(value) = consume value

fun ref unset(value: box->A!) =>
"""
Remove a value from the set.
"""


fun box ipx_rt_routed()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipx_special_none¶
[Source]


# Program Annotations

In Pony, we provide a special syntax for implementation-specific annotations to various elements of a program. The basic syntax is a comma-separated list of identifiers surrounded by backslashes:

```pony
\annotation1, annotation2\
```

Here, `annotation1` and `annotation2` can be any valid Pony identifier, i.e. a sequence of alphanumeric characters starting with a letter or an underscore.


(I64 val , Bool val)

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

Parameters¶

y: I64 val

Returns¶

I64 val ?

sub_partial¶
[Source]


try
test()?
_fail(_fmt_msg(loc, "Assert error failed. " + msg))
false
else
_runner.log(_fmt_msg(loc, "Assert error passed. " + msg), true)
true
end

fun assert_no_error(
test: {(): None ?} box,
msg: String = "",
loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the given test function does not throw an error when run.
"""
try
test()?


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


fun ip_unicast_if():I32 => @pony_os_sockopt_option(I32(342))
fun ip_xfrm_policy():I32 => @pony_os_sockopt_option(I32(343))
fun local_connwait():I32 => @pony_os_sockopt_option(I32(344))
fun local_creds():I32 => @pony_os_sockopt_option(I32(345))
fun local_peercred():I32 => @pony_os_sockopt_option(I32(346))
fun local_peerepid():I32 => @pony_os_sockopt_option(I32(347))
fun local_peereuuid():I32 => @pony_os_sockopt_option(I32(348))
fun local_peerpid():I32 => @pony_os_sockopt_option(I32(349))
fun local_peeruuid():I32 => @pony_os_sockopt_option(I32(350))
fun local_vendor():I32 => @pony_os_sockopt_option(I32(351))
fun max_tcpoptlen():I32 => @pony_os_sockopt_option(I32(352))
fun mcast_block_source():I32 => @pony_os_sockopt_option(I32(353))
fun mcast_exclude():I32 => @pony_os_sockopt_option(I32(354))
fun mcast_include():I32 => @pony_os_sockopt_option(I32(355))
fun mcast_join_group():I32 => @pony_os_sockopt_option(I32(356))
fun mcast_join_source_group():I32 => @pony_os_sockopt_option(I32(357))
fun mcast_leave_group():I32 => @pony_os_sockopt_option(I32(358))
fun mcast_leave_source_group():I32 => @pony_os_sockopt_option(I32(359))
fun mcast_msfilter():I32 => @pony_os_sockopt_option(I32(360))
fun mcast_unblock_source():I32 => @pony_os_sockopt_option(I32(361))


fun box ip_rsvp_vif_on()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_striphdr¶
[Source]


name = name'
_hunger_level = 0

new hungry(name': String, hunger': U64) =>
name = name'
_hunger_level = hunger'
```

Here, every `Wombat` begins a little bit thirsty, regardless of which constructor is called.


1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411


fun ref home(ctrl: Bool, alt: Bool, shift: Bool) =>
None

fun ref end_key(ctrl: Bool, alt: Bool, shift: Bool) =>
None

fun ref page_up(ctrl: Bool, alt: Bool, shift: Bool) =>
None

fun ref page_down(ctrl: Bool, alt: Bool, shift: Bool) =>
None

fun ref fn_key(i: U8, ctrl: Bool, alt: Bool, shift: Bool) =>
None

fun ref prompt(term: ANSITerm ref, value: String) =>
None

fun ref size(rows: U16, cols: U16) =>


Parameters¶

test: UnitTest iso


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


end
end
```

Note, All the `as` examples above could be written using a `match` statement where a failure to match results in `error`. For example, our last example written to use `match` would be:

```pony
actor Main
new create(env: Env) =>
let anys = Array[Any ref].>push(Wombat).>push(Capybara)
for any in anys.values() do
try
match any
| let critter: Critter =>
env.out.print(critter.wash())
else
error
end
end
end


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


The removed element is returned.
fun ref shift()
: A^ ?

Returns¶

A^ ?

append¶
[Source]
Append the elements from a sequence, starting from the given offset.
fun ref append(
seq: (ReadSeq[A] box & ReadElement[A^] box),
offset: USize val = 0,
len: USize val = call)
: None val

Parameters¶


new create(from: (AmbientAuth | NetAuth)) =>
None

primitive TCPAuth
new create(from: (AmbientAuth | NetAuth)) =>
None

primitive TCPListenAuth
new create(from: (AmbientAuth | NetAuth | TCPAuth)) =>
None

primitive TCPConnectAuth
new create(from: (AmbientAuth | NetAuth | TCPAuth)) =>
None


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


# Example program

To use PonyTest simply write a class for each test and a `TestList` type that tells the PonyTest object about the tests. Typically the `TestList` will be Main for the package.

The following is a complete program with 2 trivial tests.

```pony
use "pony_test"

actor Main is TestList
new create(env: Env) =>
PonyTest(env, this)

new make() =>
None

fun tag tests(test: PonyTest) =>
test(_TestAdd)
test(_TestSub)


SignalNotify¶
[Source]
Notifications for a signal.
interface ref SignalNotify

Public Functions¶
apply¶
[Source]
Called with the the number of times the signal has fired since this was
last called. Return false to stop listening for the signal.
fun ref apply(
count: U32 val)
: Bool val


fun box sctp_cause_invalid_param()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cause_missing_param¶
[Source]


```pony
// In package A
class Foo

// In package B
class Foo

// In your code
use "packageA"
use b = "packageB"

class Bar
var _x: Foo  // The Foo from package A
var _y: b.Foo  // The Foo from package B
```

__Can I just specify the full package path and forget about the use command, like I do in Java and C#?__ No, you can't do that in Pony. You can't refer to one package based on a `use` command for another package and you can't use types from a package without a use command for that package. Every package that you want to use must have its own `use` command.

__Are there limits on the names I can use for an alias?__ Use alias names have to start with a lower case letter. Other than that you can use whatever name you want, as long as you're not using that name for any other purpose in your file.


fun box rotr(
y: U32 val)
: U32 val

Parameters¶

y: U32 val

Returns¶

U32 val

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

Returns¶


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


end
consume res
})
(consume result, shrink_iter)
end
)

fun array_of[T](
gen: Generator[T],
min: USize = 0,
max: USize = 100)
: Generator[Array[T]]
=>
Generators.seq_of[T, Array[T]](gen, min, max)

fun shuffled_array_gen[T](
gen: Generator[Array[T]])
: Generator[Array[T]]
=>
Generator[Array[T]](


return false
end

data.truncate(len)
notify(consume data)

ifdef windows then
// Not allowed to call pony_os_stdin_read again yet, exit loop.
return true
end

sum = sum + len

if sum > (1 << 12) then
if _use_event then
_read_again()
end

break
end


: A

Parameters¶

y: A

Returns¶

A

sub_unsafe¶
[Source]
Unsafe operation.
If the operation overflows, the result is undefined.
fun box sub_unsafe(
y: A)
: A

Parameters¶


Returns¶

U32 val

term¶
[Source]
fun box term()
: U32 val

Returns¶

U32 val

urg¶
[Source]
fun box urg()
: U32 val


# Create empty functions in a class

```pony
class Test
fun alpha() =>
"""
"""
fun beta() =>
"""
"""
```


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


"""
if i < _size then
_size = _size - 1
_ptr._offset(i)._delete(1, _size - i)
else
error
end

fun ref truncate(len: USize) =>
"""
Truncate an array to the given length, discarding excess elements. If the
array is already smaller than len, do nothing.
"""
_size = _size.min(len)

fun ref trim_in_place(from: USize = 0, to: USize = -1) =>
"""
Trim the array to a portion of itself, covering `from` until `to`.
Unlike slice, the operation does not allocate a new array nor copy elements.
"""


Flatmapping a function from A to B over the empty list yields the
empty list of Bs.
"""
Nil[B]

fun for_each(f: {(val->A)} box) =>
"""
Applying a function to every member of the empty list is a no-op.
"""
None

fun filter(f: {(val->A): Bool} box): Nil[A] =>
"""
Filtering the empty list yields the empty list.
"""
this

fun fold[B](f: {(B, val->A): B^} box, acc: B): B =>
"""
Folding over the empty list yields the initial accumulator.


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

Parameters¶

y: I16 val

Returns¶

Bool val

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

Parameters¶


472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491


you can use `before_iteration` and `after_iteration` methods respectively
that run before/after each iteration.
"""
fun name(): String
fun config(): BenchConfig => BenchConfig
fun overhead(): AsyncMicroBenchmark^ => AsyncOverheadBenchmark
fun ref before(c: AsyncBenchContinue) => c.complete()
fun ref before_iteration(c: AsyncBenchContinue) => c.complete()
fun ref apply(c: AsyncBenchContinue) ?
fun ref after(c: AsyncBenchContinue) => c.complete()
fun ref after_iteration(c: AsyncBenchContinue) => c.complete()

interface tag BenchmarkList
fun tag benchmarks(bench: PonyBench)

// TODO documentation
class val BenchConfig
"""
Configuration of a benchmark.
"""


path: String val)
: String val

Parameters¶

path: String val

Returns¶

String val

rel¶
[Source]
Returns a path such that Path.join(to, Path.rel(to, target)) == target.
Raises an error if this isn't possible.
fun box rel(
to: String val,
target: String val)
: String val ?


Unsafe operation.
If the operation overflows, the result is undefined.
fun box mul_unsafe(
y: I128 val)
: I128 val

Parameters¶

y: I128 val

Returns¶

I128 val

divrem_unsafe¶
[Source]
Unsafe operation.
If y is 0, the result is undefined.
If the operation overflows, the result is undefined.


fun ref try_compacting(thing: Compactable) =>
if thing.size() > _threshold then
thing.compact()
end
```

The flexibility of `interface` has allowed us to define a type `Compactable` that we can use to allow our `Compactor` to accept a variety of data types including `Array`, `Map`, and `String` from the standard library.


fun box so_priority()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_protocol_info¶
[Source]


U8 val

abs¶
[Source]
fun box abs()
: U8 val

Returns¶

U8 val

bit_reverse¶
[Source]
fun box bit_reverse()
: U8 val

Returns¶


# Adding to `PONYPATH`

Assuming you just placed new Pony code under a directory called `pony` in your home directory here is how to inform `ponyc` that the directory contains Pony code via adding it to `PONYPATH`.


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


ULong val | USize val) & Integer[T] val)](
x: T,
h: PropertyHelper val)
: None val ?

Parameters¶

x: T
h: PropertyHelper val

Returns¶

None val ?

name¶
fun box name()
: String val

Returns¶


IniNoDelimiter¶
[Source]
primitive val IniNoDelimiter

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

Returns¶

IniNoDelimiter val^


fun box so_mark()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_max_pacing_rate¶
[Source]


the Pony runtime help:
actor Main
new create(env: Env) =>
env.out.print("Hello, world.")

fun @runtime_override_defaults(rto: RuntimeOptions) =>
rto.ponyhelp = true

struct ref RuntimeOptions

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

Returns¶

RuntimeOptions iso^


end

fun val concat(iter: Iterator[(val->K, val->V)]): HashMap[K, V, H] =>
"""
Add the K, V pairs from the given iterator to the map.
"""
var m = this
for (k, v) in iter do
m = m.update(k, v)
end
m

fun val add(key: K, value: val->V): HashMap[K, V, H] =>
"""
Return this Map with the given (key, value) mapping.
"""
update(key, value)

fun val sub(key: K): HashMap[K, V, H] =>
"""


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

Returns¶

String iso^

values¶
[Source]
Return an iterator over the bytes in the string.
fun box values()
: StringBytes ref^

Returns¶


I16 val ?

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

Parameters¶

y: I16 val

Returns¶

I16 val ?

div_partial¶
[Source]


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

Returns¶

U64 val

u128_unsafe¶
[Source]
fun box u128_unsafe()
: U128 val

Returns¶

U128 val


fun box so_incoming_cpu()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_l2cap_encrypted¶
[Source]


let cols = Array[(USize,String,String)]()
for a in args.values() do
cols.push((2, a.help_string(), a.descr()))
end
_Columns.write(w, cols)

fun _any_options(): Bool =>
if _spec.options().size() > 0 then
true
else
match _parent
| let p: CommandHelp => p._any_options()
else
false
end
end

fun _all_options(): Array[OptionSpec box] =>
let options = Array[OptionSpec box]()
_all_options_fill(options)


# Hello World -- Your First Pony Program

Now that you've successfully installed the Pony compiler, let's start programming! Our first program will be a very traditional one. We're going to print "Hello, world!". First, create a directory called `helloworld`:

```bash
mkdir helloworld
cd helloworld
```

__Does the name of the directory matter?__ Yes, it does. It's the name of your program! By default when your program is compiled, the resulting executable binary will have the same name as the directory your program lives in. You can also set the name using the --bin-name or -b options on the command line.


ReadElement[A: A]¶
[Source]
Used to show that a ReadSeq can return an element of a specific unmodified
type.
interface box ReadElement[A: A]

Public Functions¶
apply¶
[Source]
fun box apply(
i: USize val)
: A ?


requested data
"""
_pending_writev .> push((data.cpointer(), data.size()))
_pending_writev_total = _pending_writev_total + data.size()

fun ref queuev(data: ByteSeqIter box) =>
"""
Queue an iterable collection of ByteSeqs to be written
NOTE: Queue'd data will always be written before normal print/write
requested data
"""
for bytes in data.values() do
queue(bytes)
end

fun ref flush(): Bool =>
"""
Flush any queued data
"""
_pending_writes()


ForAll2[T1: T1, T2: T2]¶
[Source]
class ref ForAll2[T1: T1, T2: T2]

Constructors¶
create¶
[Source]
new ref create(
gen1': Generator[T1] val,
gen2': Generator[T2] val,
h: TestHelper val)
: ForAll2[T1, T2] ref^


U16 val^

max_value¶
[Source]
new val max_value()
: U16 val^

Returns¶

U16 val^

Public Functions¶
next_pow2¶
[Source]
fun box next_pow2()
: U16 val

Returns¶


Bool val


fun box somaxconn()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_acceptconn¶
[Source]


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


I128 val

popcount¶
[Source]
fun box popcount()
: U128 val

Returns¶

U128 val

clz¶
[Source]
fun box clz()
: U128 val

Returns¶


672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691


Returns¶

U32 val

kill¶
[Source]
fun box kill()
: U32 val

Returns¶

U32 val

bus¶
[Source]
fun box bus()
: U32 val


readline.pony

1
2
3
4
5
6
7
8
9
10
11


PrefixSpec¶
[Source]
trait val PrefixSpec


option: U32 val

Returns¶

U32 val

get_so_error¶
[Source]
Wrapper for the FFI call getsockopt(fd, SOL_SOCKET, SO_ERROR, ...)
fun ref get_so_error()
: (U32 val , U32 val)

Returns¶

(U32 val , U32 val)

get_so_rcvbuf¶
[Source]


U64 val


fun box bitwidth()
: U64 val

Returns¶

U64 val

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

Returns¶

USize val

min¶
[Source]


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

Returns¶

ISize val

u8¶
[Source]
fun box u8()
: U8 val

Returns¶

U8 val


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

actor _RunAsync is _Runner
let _ponybench: PonyBench
embed _aggregator: _Aggregator
let _name: String
let _bench: AsyncMicroBenchmark ref
var _start_time: U64 = 0
var _n: U64 = 0
var _a: U64 = 0

embed _before_cont: AsyncBenchContinue =
AsyncBenchContinue._create(this, recover this~_before_done_cont() end)
embed _before_iteration_cont: AsyncBenchContinue =
AsyncBenchContinue._create(this, recover this~_before_iteration_done_cont() end)
embed _iteration_cont: AsyncBenchContinue =
AsyncBenchContinue._create(this, recover this~_iteration_done_cont() end)
embed _after_iteration_cont: AsyncBenchContinue =
AsyncBenchContinue._create(this, recover this~_after_iteration_done_cont() end)


1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271


fun box sctp_sack_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_sack_rwnd_logging_enable¶
[Source]


fun box values()
: Iterator[this->A] ref^

Returns¶

Iterator[this->A] ref^


new _inf(negative: Bool) => compile_intrinsic

new from_bits(i: U64) => compile_intrinsic
fun bits(): U64 => compile_intrinsic
new from[B: (Number & Real[B] val)](a: B) => a.f64()

new min_value() =>
"""
Minimum negative value representable.
"""
from_bits(0xFFEF_FFFF_FFFF_FFFF)

new max_value() =>
"""
Maximum positive value representable.
"""
from_bits(0x7FEF_FFFF_FFFF_FFFF)

new min_normalised() =>
"""


"""
A Registrar keeps a map of lookup string to anything. Generally, this is used
to keep a directory of long-lived service-providing actors that can be
looked up name.
"""
embed _registry: Map[String, Any tag] = _registry.create()

be update(key: String, value: Any tag) =>
"""
Add, or change, a lookup mapping.
"""
_registry(key) = value

be remove(key: String, value: Any tag) =>
"""
Remove a mapping. This only takes effect if provided key currently maps to
the provided value. If the key maps to some other value (perhaps after
updating), the mapping won't be removed.
"""
try


String¶
[Source]
A String is an ordered collection of bytes.
Strings don't specify an encoding.
Example usage of some common String methods:
actor Main
new create(env: Env) =>
try
// construct a new string
let str = "Hello"

// make an uppercased version
let str_upper = str.upper()


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


ifndef __JCH_H_


PropertyResultNotify¶
[Source]
interface val PropertyResultNotify

Public Functions¶
fail¶
[Source]
Called when a Property has failed (did not hold for a sample)
or when execution raised an error.
Does not necessarily denote completeness of the property execution,
see complete(success: Bool) for that purpose.
fun box fail(
msg: String val)


None val

push¶
[Source]
Adds an element to the end of the sequence.
fun ref push(
value: A)
: None val

Parameters¶

value: A

Returns¶

None val


_value = 0

fun ref set(flag: A) =>
"""
Sets the flag.
"""
_value = _value or flag.value()

fun ref unset(flag: A) =>
"""
Unsets the flag.
"""
_value = _value and not flag.value()

fun ref flip(flag: A) =>
"""
Sets the flag if it is unset, unsets the flag if it is set.
"""
_value = _value xor flag.value()


[Source]
Start reading off this TCPConnection again after having been muted.
be unmute()

set_notify¶
[Source]
Change the notifier.
be set_notify(
notify: TCPConnectionNotify iso)

Parameters¶

notify: TCPConnectionNotify iso

dispose¶
[Source]
Close the connection gracefully once all writes are sent.
be dispose()


var _a: (A | _None) = _None
var _b: (B | _None) = _None

be fulfill_a(a: A) =>
match _b
| let b: B => p'((a, b))
else _a = a
end

be fulfill_b(b: B) =>
match _a
| let a: A => p'((a, b))
else _b = b
end
end

next[None](
{(a) => c.fulfill_a(a) },
{() => p'.reject() })


12
13
14
15
16
17
18
19primitive DoNotOptimise
"""
Contains functions preventing some compiler optimisations, namely dead code
removal. This is useful for benchmarking purposes.
"""

fun apply[A](obj: A) =>
"""
Prevent the compiler from optimising out obj and any computation it is
derived from. This doesn't prevent constant propagation.
"""
compile_intrinsic


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


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


iftype A <: U8 then
None
else
var i: A = _low_prime_table(table_end - 1)
while (i * i) <= n do
if (n %% i) == 0 then return false end
if (n %% (i + 2)) == 0 then return false end
i = i + 6
end
end
true


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


.collect[S](S.create(size))

// create shrink_iter with smaller seqs and elements generated from _gen.value_iter
let shrink_iter =
Iter[USize](CountdownIter(size, min)) //Range(size, min, -1))
// .skip(1)
.map_stateful[S^]({
(s: USize): S^ =>
Iter[T^](_gen.value_iter(rnd))
.take(s)
.collect[S](S.create(s))
})
(consume result, shrink_iter)
end)

fun iso_seq_of[T: Any #send, S: Seq[T] iso](
gen: Generator[T],
min: USize = 0,
max: USize = 100)
: Generator[S]


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


be complete_action(
name: String val,
round: (_Shrink val | _Run val),
ph: PropertyHelper val)

Parameters¶

name: String val
round: (_Shrink val | _Run val)
ph: PropertyHelper val

fail_action¶
[Source]
be fail_action(
name: String val,
round: (_Shrink val | _Run val),
ph: PropertyHelper val)

Parameters¶


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


U8 val ?

clone¶
[Source]
Returns a copy of the string. The resulting string is
null-terminated even if the original is not.
fun box clone()
: String iso^

Returns¶

String iso^

repeat_str¶
[Source]
Returns a copy of the string repeated num times with an optional
separator added inbetween repeats.


isn't one.
fun val canonical()
: FilePath val ?

Returns¶

FilePath val ?

exists¶
[Source]
Returns true if the path exists. Returns false for a broken symlink.
fun val exists()
: Bool val

Returns¶

Bool val


next()?
else
error
end
end
end)

fun ref all(f: {(A!): Bool ?} box): Bool =>
"""
Return false if at least one value of the iterator fails to match the
predicate `f`. This method short-circuits at the first value where the
predicate returns false, otherwise true is returned.


new create(
auth: StartProcessAuth,
backpressure_auth: ApplyReleaseBackpressureAuth,
notifier: ProcessNotify iso,
filepath: FilePath,
args: Array[String] val,
vars: Array[String] val,
wdir: (FilePath | None) = None,
process_poll_interval: U64 = Nanos.from_millis(100))
=>
"""
Create infrastructure to communicate with a forked child process and
register the asio events. Fork child process and notify our user about
incoming data via the notifier.
"""
_backpressure_auth = backpressure_auth
_notifier = consume notifier
_process_poll_interval = process_poll_interval

// We need permission to execute and the


Exited(_WaitPidStatus.exit_code(wstatus))
elseif _WaitPidStatus.signaled(wstatus) then
Signaled(_WaitPidStatus.termsig(wstatus).u32())
elseif _WaitPidStatus.stopped(wstatus) then
Signaled(_WaitPidStatus.stopsig(wstatus).u32())
elseif _WaitPidStatus.continued(wstatus) then
_StillRunning
else
// *shrug*
WaitpidError
end
| 0 => _StillRunning
else
WaitpidError
end
else
WaitpidError
end

primitive _WaitPidStatus


fun box sctp_pcb_flags_bound_v6()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_connected¶
[Source]


fun box remc(
y: U8 val)
: (U8 val , Bool val)

Parameters¶

y: U8 val

Returns¶

(U8 val , Bool val)

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

Parameters¶


U16 val

bit_reverse¶
[Source]
fun box bit_reverse()
: I16 val

Returns¶

I16 val

bswap¶
[Source]
fun box bswap()
: I16 val

Returns¶


fun box u8_unsafe()
: U8 val

Returns¶

U8 val

u16_unsafe¶
[Source]
fun box u16_unsafe()
: U16 val

Returns¶

U16 val

u32_unsafe¶
[Source]


fun box ip_multicast_ttl()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_nat_xxx¶
[Source]


.map[I64]({(x) => x * x })

1 4 9
fun ref map[B: B](
f: {(A!): B ?}[A, B] box)
: Iter[B] ref^

Parameters¶

f: {(A!): B ?}[A, B] box

Returns¶

Iter[B] ref^

nth¶
[Source]
Return the nth value of the iterator.
Example¶


Promise[A: Any #share]¶
[Source]
A promise to eventually produce a result of type A. This promise can either
be fulfilled or rejected.
Any number of promises can be chained after this one.
actor tag Promise[A: Any #share]

Constructors¶
create¶
[Source]
new tag create()
: Promise[A] tag^


Character position on line.
Character positions start at 1.
fun box pos()
: USize val

Returns¶

USize val


Bool val


fun box sctp_cause_unrecog_param()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cause_unsupported_hmacid¶
[Source]


bool¶
[Source]
fun box bool()
: Bool val ?

Returns¶

Bool val ?

i8¶
[Source]
fun box i8(
base: U8 val = 0)
: I8 val ?

Parameters¶

base: U8 val = 0


every¶
[Source]
Any predicate is true of every member of the empty list.
fun box every(
f: {(val->A): Bool}[A] box)
: Bool val

Parameters¶

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

Returns¶

Bool val

exists¶
[Source]
For any predicate, there is no element that satisfies it in the empty
list.


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


error
end

fun ref block(len: USize): Array[U8] iso^ ? =>
"""
Return a block as a contiguous chunk of memory.
Will throw an error if you request a block larger than what is currently
stored in the `Reader`.
"""
if _available < len then
error
end

_available = _available - len
var out = recover Array[U8] .> undefined(len) end
var i = USize(0)

while i < len do
let node = _chunks.head()?
(let data, let offset) = node()?


path.pony

1
2
3
4
5
6
7
8
9
10
11


ISize val ?

sub_partial¶
[Source]
fun box sub_partial(
y: ISize val)
: ISize val ?

Parameters¶

y: ISize val

Returns¶

ISize val ?

mul_partial¶


fun ref u128_le(data: U128) =>
"""
Write a U128 to the buffer in little-endian byte order.
"""
let num_bytes = U128(0).bytewidth()
ifdef littleendian then
_current.push_u128(data)
else
_current.push_u128(data.bswap())
end
_size = _size + num_bytes

fun ref u128_be(data: U128) =>
"""
Write a U128 to the buffer in big-endian byte order.
"""
let num_bytes = U128(0).bytewidth()
ifdef bigendian then
_current.push_u128(data)


_fd = -1
end

fun _final() =>
"""
Close the file descriptor.
"""
if _fd != -1 then
ifdef posix then
@close(_fd)
end
end


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


Monotonic unadjusted microseconds.
fun box micros()
: U64 val

Returns¶

U64 val

nanos¶
[Source]
Monotonic unadjusted nanoseconds.
fun box nanos()
: U64 val

Returns¶

U64 val


let r = (ifdef windows then
@_read(_fd, result.cpointer(), result.space().i32())
else
@read(_fd, result.cpointer(), result.space())
end).isize()

match r
| 0  => _errno = FileEOF
| -1 => _errno = _get_error()
end

result.truncate(r.usize())
result
else
recover String end
end

fun ref print(data: ByteSeq box): Bool =>
"""
Same as write, buts adds a newline.


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86interface Iterator[A]
"""

Iterators generate a series of values, one value at a time on each call to `next()`.

An Iterator is considered exhausted, once its `has_next()` method returns `false`.


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

Parameters¶

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

Returns¶

MT ref^


fun box udp_encap_espinudp_port()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

udp_nocksum¶
[Source]


# Test names

Tests are identified by names, which are used when printing test results and on the command line to select which tests to run. These names are independent of the names of the test classes in the Pony source code.

Arbitrary strings can be used for these names, but for large projects, it is strongly recommended to use a hierarchical naming scheme to make it easier to select groups of tests.


# Aliasing

__Aliasing__ means having more than one reference to the same object, within the same actor. This can be the case for a variable or a field.

In most programming languages, aliasing is pretty simple. You just assign some variable to another variable, and there you go, you have an alias. The variable you assign to has the same type (or some supertype) as what's being assigned to it, and everything is fine.

In Pony, that works for some reference capabilities, but not all.


IniIncompleteSection¶
[Source]
primitive val IniIncompleteSection

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

Returns¶

IniIncompleteSection val^


cols.push((2, o.help_string(), o.descr()))
end
_Columns.write(w, cols)

fun _write_commands(w: Writer) =>
let cols = Array[(USize,String,String)]()
_list_commands(_spec, cols, 1)
_Columns.write(w, cols)

fun _list_commands(
cs: CommandSpec box,
cols: Array[(USize,String,String)],
level: USize)
=>
for c in cs.commands().values() do
cols.push((level*2, c.help_string(), c.descr()))
_list_commands(c, cols, level + 1)
end

fun _write_args(w: Writer, args: Array[ArgSpec] 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]


concat¶
[Source]
The concatenation of any list l with the empty list is l.
fun box concat(
l: (Cons[A] val | Nil[A] val))
: (Cons[A] val | Nil[A] val)

Parameters¶

l: (Cons[A] val | Nil[A] val)

Returns¶

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

map[B: B]¶
[Source]
Mapping a function from A to B over the empty list yields the
empty list of Bs.


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


fun box usize()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64¶
[Source]


msg: String val
verbose: Bool val = false

Returns¶

None val


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


fun _swap(a: A, i: ISize, j: ISize) ? =>
a(j.usize())? = a(i.usize())? = a(j.usize())?


"""
Down arrow.
"""
(let ctrl, let alt, let shift) = _mod()
_notify.down(ctrl, alt, shift)
_esc_clear()

fun ref _left() =>
"""
Left arrow.
"""
(let ctrl, let alt, let shift) = _mod()
_notify.left(ctrl, alt, shift)
_esc_clear()

fun ref _right() =>
"""
Right arrow.
"""
(let ctrl, let alt, let shift) = _mod()


"""
Return type for
[`Generator.generate`](pony_check-Generator.md#generate).

Either a single value or a Tuple of a value and an Iterator
of shrunken values based upon this value.
"""

class CountdownIter[T: (Int & Integer[T] val) = USize] is Iterator[T]
var _cur: T
let _to: T

new create(from: T, to: T = T.min_value()) =>
"""
Create am `Iterator` that counts down according to the specified arguments.

`from` is exclusive, `to` is inclusive.
"""
_cur = from
_to = to


fun box tipc_cfg_srv()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_conn_shutdown¶
[Source]


If the operation overflows, the result is undefined.
"""
this +~ y

fun sub_unsafe(y: A): A =>
"""
Unsafe operation.
If the operation overflows, the result is undefined.
"""
this -~ y

fun mul_unsafe(y: A): A =>
"""
Unsafe operation.
If the operation overflows, the result is undefined.
"""
this *~ y

fun div_unsafe(y: A): A =>
"""


fun box usize_unsafe()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64_unsafe¶
[Source]


which aliases as a `String tag`).

Example:

```pony
Generators.repeatedly[Writer]({(): Writer^ =>
let writer = Writer.>write("consume me, please")
consume writer
})
```
"""
Generator[T](
object is GenObj[T]
fun generate(rnd: Randomness): GenerateResult[T] ? =>
f()?
end)

fun seq_of[T, S: Seq[T] ref](
gen: Generator[T],


fun box sctp_operation_error()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_packet_dropped¶
[Source]


# Out of order arguments

Partial application with named arguments allows binding arguments in any order, not just left to right. For example:

```pony
let f = foo~addmul(where mul = 4)
f(3)
```

Here, we bound the `mul` argument but left `add` unbound.


supposed to be used with getsockopt(2) and setsockopt(2).
Please consult your platform's documentation to verify the names
of the option level and option name macros.
The following code fragments are equivalent: set the socket
receive buffer size for the file descriptor fd to 4455.
/* In C */
int option_value = 4455;
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &option_value, 4);

/* In Pony */
var option: I32 = 4455;
@setsockopt[I32](fd, OSSockOpt.sol_socket(), OSSockOpt.so_rcvbuf(),
addressof option, I32(4))

primitive val OSSockOpt

Constructors¶
create¶
[Source]
new val create()


that: Pointer[A] tag)
: Bool val

Parameters¶

that: Pointer[A] tag

Returns¶

Bool val

le¶
[Source]
fun tag le(
that: Pointer[A] tag)
: Bool val

Parameters¶


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


# Caveats

There are several things to keep in mind when using Pony's serialisation system:

* Serialised objects will currently only work when passed between two running instances of the same Pony executable. You cannot pass objects between different Pony programs, nor can you pass them between different versions of the same program. Using the `Serialise.signature` function can help you determine if your two Pony programs are the same.
* Objects with `embed` fields will not be properly serialised.
* Objects with `Pointer` fields must use the custom serialisation mechanism or else the `Pointer` fields will be null when the object is deserialised. For information on how to handle these kinds of fields, please see the discussion of custom serialisation and deserialisation below.


"""
Return tab completion possibilities.
"""
Array[String]


Parameters¶

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

Returns¶

HashSet[A, H] val

eq¶
[Source]
Return true if this and that contain the same elements.
fun box eq(
that: HashSet[A, H] box)
: Bool val

Parameters¶

that: HashSet[A, H] box


"""
The wall-clock adjusted system time.
"""
@time(USize(0))

fun millis(): U64 =>
"""
Monotonic unadjusted milliseconds.
"""
ifdef osx then
@clock_gettime_nsec_np(_ClockUptimeRaw()) / 1000000
elseif linux or bsd then
var ts = _clock_gettime(_ClockMonotonic)
((ts._1 * 1000) + (ts._2 / 1000000)).u64()
elseif windows then
_subseconds_from_query_performance_counter(1000)
else
compile_error "unsupported platform"
end


[Source]
fun box div_partial(
y: A)
: A ?

Parameters¶

y: A

Returns¶

A ?

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


Property4[T1: T1, T2: T2, T3: T3, T4: T4]¶
[Source]
trait ref Property4[T1: T1, T2: T2, T3: T3, T4: T4] is
Property1[(T1 , T2 , T3 , T4)] ref

Implements¶

Property1[(T1 , T2 , T3 , T4)] ref

Public Functions¶
gen1¶
[Source]


let sb = Writer

sb.u32_le(7744)             // Our desired socket buffer size
let sbytes = Array[U8]
for bs in sb.done().values() do
sbytes.append(bs)
end
match conn.setsockopt(OSSockOpt.sol_socket(), OSSockOpt.so_rcvbuf(), sbytes)
| 0 =>
// System call was successful
| let errno: U32 =>
// System call failed
end
```
"""
_OSSocket.setsockopt(_fd, level, option_name, option)

fun ref setsockopt_u32(level: I32, option_name: I32, option: U32): U32 =>
"""
General wrapper for TCP sockets to the `setsockopt(2)` system call where


[Source]
fun box add_unsafe(
y: ISize val)
: ISize val

Parameters¶

y: ISize val

Returns¶

ISize val

sub_unsafe¶
[Source]
fun box sub_unsafe(
y: ISize val)
: ISize val


"""
Generate a printable string of the contents of the given readseq to use in
error messages.

The type parameter of this function is the type parameter of the
elements in the ReadSeq.
"""
"[len=" + array.size().string() + ": " + ", ".join(array.values()) + "]"

fun long_test(timeout: U64) =>
"""
Indicate that this is a long running test that may continue after the
test function exits.
Once this function is called, complete() must be called to finish the test,
unless a timeout occurs.
The timeout is specified in nanseconds.
"""
_runner.long_test(timeout)

fun complete(success: Bool) =>


Parameters¶

n: U32 val

Returns¶

U32 val ?

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

Parameters¶

that: Sig val


fun box ip_add_membership()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_bindany¶
[Source]


Public Functions¶
apply¶
[Source]
Receives input.
fun ref apply(
term: ANSITerm ref,
input: U8 val)
: None val

Parameters¶

term: ANSITerm ref
input: U8 val

Returns¶

None val


In case of system call success, this function returns the 2-tuple:
1. The integer 0.
2. The *option_value returned by the kernel converted to a Pony U32.
In case of system call failure, this function returns the 2-tuple:
1. The value of errno.
2. An undefined value that must be ignored.
fun ref getsockopt_u32(
level: I32 val,
option_name: I32 val)
: (U32 val , U32 val)

Parameters¶

level: I32 val
option_name: I32 val

Returns¶

(U32 val , U32 val)


new ref create(
string: String box)
: StringRunes ref^

Parameters¶

string: String box

Returns¶

StringRunes ref^

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

Returns¶


# A capability generic class

Now that we have `iso` working we know how to write a generic class that works for `iso` and it will work for other capabilities too:

```pony
class Foo[A]
var _c: A

new create(c: A) =>
_c = consume c

fun get(): this->A => _c

fun ref set(c: A) => _c = consume c

actor Main
new create(env:Env) =>
let a = Foo[String iso]("Hello".clone())
env.out.print(a.get().string())


datasync¶
[Source]
Sync the file contents to physical storage.
fun ref datasync()
: None val

Returns¶

None val

set_length¶
[Source]
Change the file size. If it is made larger, the new contents are undefined.
fun ref set_length(
len: USize val)
: Bool val

Parameters¶


```pony
let even_i32s =
Generators.i32()
.filter(
{(t) => (t, ((t % 2) == 0)) })
```
"""
Generator[T](
object is GenObj[T]
fun generate(rnd: Randomness): GenerateResult[T] ? =>
(let t: T, let shrunken: Iterator[T^]) = _gen.generate_and_shrink(rnd)?
(let t1, let matches) = predicate(consume t)
if not matches then
generate(rnd)? // recurse, this might recurse infinitely
else
// filter the shrunken examples
(consume t1, _filter_shrunken(shrunken))
end

fun shrink(t: T): ValueAndShrink[T] =>


None

fun tag tests(test: PonyTest) =>
bar.Main.make().tests(test)
foo.Main.make().tests(test)
```

Aggregate test classes may themselves be aggregated. Every test list class may
contain any combination of its own tests and aggregated lists.


return false
end
log(_format_loc(loc) + "Assert true passed. " + msg, true)
true

fun assert_false(actual: Bool, msg: String = "", loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the given expression is false.
"""
if actual then
fail(_format_loc(loc) + "Assert false failed. " + msg)
return false
end
log(_format_loc(loc) + "Assert false passed. " + msg, true)
true

fun assert_error(test: ITest box, msg: String = "", loc: SourceLoc = __loc)
: Bool


String val ?


fun box sctp_pcb_flags_connected()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_dont_wake¶
[Source]


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


CommandSpec¶
[Source]
CommandSpec describes the specification of a parent or leaf command. Each
command has the following attributes:

a name: a simple string token that identifies the command.
a description: used in the syntax message.
a map of options: the valid options for this command.
an optional help option+command name for help parsing
one of:
a Map of child commands.
an Array of arguments.


| 7 => int_property[I8](x.i8(), h)?
| 8 => int_property[I16](x.i16(), h)?
| 9 => int_property[I32](x.i32(), h)?
| 10 => int_property[I64](x.i64(), h)?
| 11 => int_property[ILong](x.ilong(), h)?
| 12 => int_property[ISize](x.isize(), h)?
| 13 => int_property[I128](x.i128(), h)?
else
h.log("rem is broken")
error
end

fun ref int_property[T: (Int & Integer[T] val)](x: T, h: PropertyHelper)?

class IntPairPropertySample is Stringable
let choice: U8
let int1: U128
let int2: U128

new create(choice': U8, int1': U128, int2': U128) =>


(A , Bool val)

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

Parameters¶

y: A

Returns¶

(A , Bool val)

divc¶


fun sol_local():I32 => @pony_os_sockopt_level(I32(4131))
fun sol_ndrvproto():I32 => @pony_os_sockopt_level(I32(4132))
fun sol_netrom():I32 => @pony_os_sockopt_level(I32(4133))
fun sol_rds():I32 => @pony_os_sockopt_level(I32(4134))
fun sol_rfcomm():I32 => @pony_os_sockopt_level(I32(4135))
fun sol_rose():I32 => @pony_os_sockopt_level(I32(4136))
fun sol_sco():I32 => @pony_os_sockopt_level(I32(4137))
fun sol_socket():I32 => @pony_os_sockopt_level(I32(4138))
fun sol_tipc():I32 => @pony_os_sockopt_level(I32(4139))
fun sol_udp():I32 => @pony_os_sockopt_level(I32(4140))

/*
*
* Options formatted in Pony by:
*   egrep -v '^(IP[A-Z0-6]*PROTO_|NSPROTO_|SOL_)' ~/sum-of-all-constants.txt | egrep -v '\(' | sort -u | egrep -v '^$' | sed 's/__/_/g' | awk 'BEGIN { count=0; } { printf("  fun %s():I32 => @pony_os_sockopt_option(I32(%d))\n", tolower($1), count++); }'
*/

// options
fun af_coip():I32 => @pony_os_sockopt_option(I32(0))
fun af_inet():I32 => @pony_os_sockopt_option(I32(1))


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


Parameters¶

y: ILong val

Returns¶

(ILong val , Bool val)

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

Parameters¶

y: ILong val

Returns¶


I64 val

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

Returns¶

I64 val

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

Parameters¶


F32 val

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

Returns¶

F32 val

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

Parameters¶


end

result.append("..")
result.append(sep())
result.append(target_clean.trim(target_0.usize()))
result
else
target_clean.trim(target_0.usize())
end

fun split(path: String, separator: String = Path.sep()): (String, String) =>
"""
Splits the path into a pair, (head, tail) where tail is the last pathname
component and head is everything leading up to that. The tail part will
never contain a slash; if path ends in a slash, tail will be empty. If
there is no slash in path, head will be empty. If path is empty, both head
and tail are empty. The path in head will be cleaned before it is returned.
In all cases, join(head, tail) returns a path to the same location as path
(but the strings may differ). Also see the functions dir() and base().
"""


GenerateResult[T2: T2]¶
[Source]
Return type for
Generator.generate.
Either a single value or a Tuple of a value and an Iterator
of shrunken values based upon this value.
type GenerateResult[T2: T2] is
(T2^ | (T2^ , Iterator[T2^] ref))

Type Alias For¶

(T2^ | (T2^ , Iterator[T2^] ref))


# Concurrent

Since behaviours are asynchronous, it's ok to run the body of a bunch of behaviours at the same time. This is exactly what Pony does. The Pony runtime has its own cooperative scheduler, which by default has a number of threads equal to the number of CPU cores on your machine. Each scheduler thread can be executing an actor behaviour at any given time, so Pony programs are naturally concurrent.


ULong val^

max_value¶
[Source]
new val max_value()
: ULong val^

Returns¶

ULong val^

Public Functions¶
next_pow2¶
[Source]
fun box next_pow2()
: ULong val

Returns¶


a.set(recover ref String end)
env.out.print(a.get().string())
```

This does not compile. The compiler complains that `get()` doesn't actually return a `String ref`, but `this->String ref`. We obviously need to simply change the type signature to fix this, but what is going on here?
`this->String ref` is [an arrow type](/reference-capabilities/arrow-types.md). An arrow type with "this->" states to use the capability of the actual receiver (`ref` in our case), not the capability of the method (which defaults to `box` here). According to [viewpoint adaption](/reference-capabilities/combining-capabilities.md) this will be `ref->ref` which is `ref`. Without this [arrow type](/reference-capabilities/arrow-types.md) we would only see the field `_c` as `box` because we are in a `box` method.

So let's apply what we just learned:

```pony
class Foo
var _c: String ref

new create(c: String ref) =>
_c = c

fun get(): this->String ref => _c

fun ref set(c: String ref) => _c = c


fun box i16()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64¶
[Source]


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

Parameters¶

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

Returns¶

Bool val

assert_ne[A: (Equatable[A] #read & Stringable #read)]¶
[Source]


[Source]
Cuts the given range out of the string.
Index range [from .. to) is half-open.
fun ref cut_in_place(
from: ISize val,
to: ISize val = call)
: None val

Parameters¶

from: ISize val
to: ISize val = call

Returns¶

None val

remove¶
[Source]


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


fun box ipx_stopfilterptype()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_add_membership¶
[Source]


end

// create a string representation before consuming ``sample`` with property
(sample, _sample_repr) = _Stringify.apply[T](consume sample)
let run_notify = recover val this~complete_run() end
let helper = PropertyHelper(_env, this, run_notify, this._current_round, _params.string())
_pass = true // will be set to false by fail calls

try
_prop1.property(consume sample, helper)?
else
fail(_sample_repr, 0 where err=true)
return
end
// dispatch to another behavior
// as complete_run might have set _pass already through a call to
// complete_run
_run_finished(this._current_round)


Time.nanos()
end
_bench.after_iteration()?
_run_iteration(n + 1, a + (e - s))
else
_fail()
end
end

be _complete(t: U64) =>
try
_bench.after()?
_aggregator.complete(_name, t)
else
_fail()
end

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


"""
(_item = consume value) as A^

fun ref pop(): A^ ? =>
"""
Remove the item from the node, if we have one, otherwise raise an error.
"""
(_item = None) as A^

fun ref prepend(that: ListNode[A]): Bool =>
"""
Prepend a node to this one. If `that` is already in a list, it is removed
before it is prepended. Returns true if `that` was removed from another
list.
If the ListNode is not contained within a List the prepend will fail.
"""
if (_prev is that) or (this is that) then
return false
end


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


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

Parameters¶

that: Promises[A] val

Returns¶

Bool val


String iso^

from_cpointer¶
[Source]
Return a string from binary pointer data without making a
copy. This must be done only with C-FFI functions that return
pony_alloc'd character arrays. If a null pointer is given then an
empty string is returned.
new ref from_cpointer(
str: Pointer[U8 val] ref,
len: USize val,
alloc: USize val = 0)
: String ref^

Parameters¶

str: Pointer[U8 val] ref
len: USize val


### Example

```pony
Iter[I64]([1; 2; 3].values())
.collect(Array[I64](3))
```
`[1, 2, 3]`
"""
for x in _iter do
coll.push(x)
end
coll

fun ref count(): USize =>
"""
Return the number of values in the iterator.


Fact(input != pad)?

match state
| 1 | 2 => out.push(output)
end
end

out

fun _enc_byte(i: U8, at62: U8, at63: U8): U8 ? =>
"""
Encode a single byte.
"""
match i
| 62 => at62
| 63 => at63
| if i < 26 => 'A' + i
| if i < 52 => ('a' - 26) + i
| if i < 62 => ('0' - 52) + i
else


use "buffered"
use "collections"

class Notify is InputNotify
let _env: Env
new create(env: Env) =>
_env = env
fun ref apply(data: Array[U8] iso) =>
let rb = Reader
rb.append(consume data)
try
while true do
let len = rb.i32_be()?
let items = rb.i32_be()?.usize()
for range in Range(0, items) do
let f = rb.f32_be()?
let str_len = rb.i32_be()?.usize()
let str = String.from_array(rb.block(str_len)?)
_env.out.print("[(" + f.string() + "), (" + str + ")]")
end


Returns¶

Array[U8 val] iso^ ?

read_until¶
[Source]
Find the first occurrence of the separator and return the block of bytes
before its position. The separator is not included in the returned array,
but it is removed from the buffer. To read a line of text, prefer line()
that handles \n and \r\n.
fun ref read_until(
separator: U8 val)
: Array[U8 val] iso^ ?

Parameters¶

separator: U8 val


var i: USize = 0

while i < _size do
let c = _ptr._apply(i)

if (c >= 0x61) and (c <= 0x7A) then
_set(i, c - 0x20)
end

i = i + 1
end

fun reverse(): String iso^ =>
"""
Returns a reversed version of the string.
"""
let s = clone()
s.reverse_in_place()
s


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.
fun box generate(
rnd: Randomness ref)
: (T^ | (T^ , Iterator[T^] ref)) ?

Parameters¶

rnd: Randomness ref

Returns¶

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

shrink¶
[Source]
Simplify the given value.


readline_notify.pony

1
2
3
4
5
6
7
8
9
10
11


I64 val

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

Returns¶

I128 val

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

Returns¶


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


USize val

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

Returns¶

U64 val

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

Returns¶


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


ILong val

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

Returns¶

ISize val

u8_unsafe¶
[Source]
fun box u8_unsafe()
: U8 val

Returns¶


: OSSockOpt val^

Returns¶

OSSockOpt val^

Public Functions¶
ipproto_3pc¶
[Source]
fun box ipproto_3pc()
: I32 val

Returns¶

I32 val

ipproto_adfs¶
[Source]


"""
Return the local IP address. If this TCPConnection is closed then the
address returned is invalid.
"""
let ip = recover NetAddress end
@pony_os_sockname(_fd, ip)
ip

fun remote_address(): NetAddress =>
"""
Return the remote IP address. If this TCPConnection is closed then the
address returned is invalid.
"""
let ip = recover NetAddress end
@pony_os_peername(_fd, ip)
ip

fun ref expect(qty: USize = 0) ? =>
"""
A `received` call on the notifier must contain exactly `qty` bytes. If


_set(_size, 0)
else
let cap = copy_len + offset
var i = offset

try
while i < cap do
push(seq(i)?)
i = i + 1
end
end
end

fun ref concat(iter: Iterator[U8], offset: USize = 0, len: USize = -1) =>
"""
Add len iterated bytes to the end of the string, starting from the given
offset.
"""
try
var n = USize(0)


for all of them. The developer only needs to specify the possible set of input
values using a Generator.
This testing technique is great for finding edge cases that would easily go
unnoticed with manually constructed test samples. In general it can lead to much
higher coverage than traditional unit testing, with much less code to write.
How PonyCheck implements Property Based Testing¶
A property based test in PonyCheck consists of the following:

A name (mostly for integration into PonyTest)
One or more generators, depending on how your property is laid out.
There are tons of them defined in the primitive
Generators.
A property method that asserts a certain property for each sample
generated by the Generator(s) with the help of
PropertyHelper, which tries to expose a
similar API   as TestHelper.
Optionally, the method params() can be used to configure how PonyCheck
executes the property by specifying a custom
PropertyParams object.


let nan: F64 = F64(0) / F64(0)

let infinite_range1 = Range[F64](0, p_inf, 1)
let infinite_range2 = Range[F64](0, n_inf, -1_000_000)
infinite_range1.is_infinite() == true
infinite_range2.is_infinite() == true

for i in Range[F64](0.5, 100, nan) do
// will not be executed as `inc` is nan
end
for i in Range[F64](0.5, 100, p_inf) do
// will not be executed as `inc` is +Inf
end
```
"""
let _min: A
let _max: A
let _inc: A
let _forward: Bool
let _infinite: Bool


data: I16 val)
: None val

Parameters¶

data: I16 val

Returns¶

None val

u32_le¶
[Source]
Write a U32 to the buffer in little-endian byte order.
fun ref u32_le(
data: U32 val)
: None val

Parameters¶


312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331


if this.has_next() then
if _use_original then
_use_original = not _use_original
_iter.next()?
else
_use_original = not _use_original
other.next()?
end
else
error
end
end)

fun ref intersperse(value: A, n: USize = 1): Iter[A!] =>
"""
Return an iterator that yields the value after every `n` elements of the
original iterator.


But take another look at the final lines: what Pony thinks is the actual receiver type, `Array[String val] box`, is significantly different from what it thinks is the actual target type, `Array[String val] ref`. And a type with a reference capability of `box`, which is immutable, is indeed not a subtype of a type with a reference capability of `ref`, which *is* mutable.

The issue must lie with the one difference between the receiver type and the target type, which is the prefix "this->". The type `this->Array[String val] ref` is a viewpoint adapted type, or arrow type, that describes the `Array[String val] ref` "as seen by the receiver". The receiver, in this case, has the receiver reference capability of the method `add_stripe`, which is the default `box`. *That* is why the final type is `Array[String val] box`.

The fundamental error in this example is the same as the last: the default receiver reference capability for a method is `box`, which is immutable. This method, however, is attempting to modify the receiver, by adding another color stripe. That is not legal at all.

As an aside, while trying to figure out what is happening, you may have been misled by the declaration of the `colors` field, `let colors...`. That declaration makes the `colors` binding constant. As a result, you cannot assign a new array to the field. On the other hand, the array itself can be mutable or immutable. In this example, it is mutable, allowing `push` to be called on the `colors` field in the `add_stripe` method.


fun box add(
y: A)
: A

Parameters¶

y: A

Returns¶

A

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

Parameters¶


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


Wrapper for the FFI call getsockopt(fd, SOL_SOCKET, SO_RCVBUF, ...)
fun ref get_so_rcvbuf()
: (U32 val , U32 val)

Returns¶

(U32 val , U32 val)

get_so_sndbuf¶
[Source]
Wrapper for the FFI call getsockopt(fd, SOL_SOCKET, SO_SNDBUF, ...)
fun ref get_so_sndbuf()
: (U32 val , U32 val)

Returns¶

(U32 val , U32 val)


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


Bool val


fun bitwidth(): USize => ifdef ilp32 then 32 else 64 end

fun bytewidth(): USize => bitwidth().usize() / 8

fun min(y: ISize): ISize => if this < y then this else y end
fun max(y: ISize): ISize => if this > y then this else y end

fun fld(y: ISize): ISize =>
_SignedArithmetic.fld[ISize, USize](this, y)

fun fld_unsafe(y: ISize): ISize =>
_SignedUnsafeArithmetic.fld_unsafe[ISize, USize](this, y)

fun mod(y: ISize): ISize =>
_SignedArithmetic.mod[ISize, USize](this, y)

fun mod_unsafe(y: ISize): ISize =>
_SignedUnsafeArithmetic.mod_unsafe[ISize, USize](this, y)

fun addc(y: ISize): (ISize, Bool) =>


fun box addc(
y: I64 val)
: (I64 val , Bool val)

Parameters¶

y: I64 val

Returns¶

(I64 val , Bool val)

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

Parameters¶


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


"""
_pending_writes() // try writes
_pending_reads(_stdout)
_pending_reads(_stderr)
_try_shutdown()

fun ref _close() =>
"""
Close all pipes and wait for the child process to exit.
"""
if not _closed then
_closed = true
_stdin.close()
_stdout.close()
_stderr.close()
_wait_for_child()
end

be _wait_for_child() =>
match _final_wait_result


Parameters¶

path: String val

Returns¶

String val

volume¶
[Source]
On Windows, this returns the drive letter or UNC base at the beginning of
the path, if there is one. Otherwise, this returns an empty string.
fun box volume(
path: String val)
: String val

Parameters¶


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


# C types

Many C functions require types that don't have an exact equivalent in Pony. A variety of features is provided for these.

For FFI functions that have no return value (i.e. they return `void` in C) the return value specified should be `None`.

In Pony, a String is an object with a header and fields, while in C a `char*` is simply a pointer to character data. The `.cstring()` function on String provides us with a valid pointer to hand to C. Our `mkdir` example above makes use of this for the first argument.

Pony classes and structs correspond directly to pointers to the class or struct in C.

For C pointers to simple types, such as U64, the Pony `Pointer[]` polymorphic type should be used, with a `tag` reference capability. To represent `void*` arguments, you should the `Pointer[None] tag` type, which will allow you to pass a pointer to any type, including other pointers. This is needed to write declarations for certain POSIX functions, such as `memcpy`:

```pony
// The C type is void* memcpy(void *restrict dst, const void *restrict src, size_t n);
use @memcpy[Pointer[U8]](dst: Pointer[None] tag, src: Pointer[None] tag, n: USize)

// Now we can use memcpy with any Pointer type
let out: Pointer[Pointer[U8] tag] tag = // ...
let outlen: Pointer[U8] tag = // ...
let ptr: Pointer[U8] tag = // ...


# Boolean Literals

There is `true`, there is `false`. That's it.


Returns¶

Bool val

nan¶
[Source]
Check whether this number is NaN.
fun box nan()
: Bool val

Returns¶

Bool val

ldexp¶
[Source]
fun box ldexp(
x: F32 val,


USize val) & Real[N] val)](
n: N)
: N

Parameters¶

n: N

Returns¶

N

int_unbiased[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶
[Source]
fun ref int_unbiased[optional N: ((U8 val | U16 val | U32 val |
U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N


fun box sctp_status()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_stream_reset_incoming¶
[Source]


fun box i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]


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


F64 val^

e¶
[Source]
new val e()
: F64 val^

Returns¶

F64 val^

from_bits¶
[Source]
new val from_bits(
i: U64 val)
: F64 val^

Parameters¶


Collections' by Michael J. Steindorfer and Jurgen J. Vinju


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


Both strings are isolated and mutable, as they do not share memory.
The operation does not allocate a new string pointer nor copy elements.
"""
let start_ptr = cpointer(split_point)
let size' = _size - _size.min(split_point)
let alloc = _alloc - _size.min(split_point)

trim_in_place(0, split_point)

let right = recover
if size' > 0 then
from_cpointer(start_ptr._unsafe(), size', alloc)
else
create()
end
end

(consume this, consume right)

fun iso unchop(b: String iso): ((String iso^, String iso^) | String iso^) =>