FilePath¶
[Source]
A FilePath represents a capability to access a path. The path will be
represented as an absolute path and a set of capabilities for operations on
that path.
class val FilePath

Constructors¶
create¶
[Source]
Create a new path to any location.
Unless absolute, path' will be relative to the program's working directory.
Capabilities are exactly as given.


error
end


Peek at a big-endian I64.
fun box peek_i64_be(
offset: USize val = 0)
: I64 val ?

Parameters¶

offset: USize val = 0

Returns¶

I64 val ?

peek_i64_le¶
[Source]
Peek at a little-endian I64.
fun box peek_i64_le(
offset: USize val = 0)
: I64 val ?


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


None val

concat¶
[Source]
Add len iterated elements to the tail of the list, starting from the given
offset.
When len is -1, all elements of iterator are pushed.
Does not remove elements from iterator.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = List[String].from(["d"; "e"; "f"])
my_list.concat(other_list.values())  // my_list is ["a"; "b"; "c"; "d"; "e"; "f"], other_list is unchanged

fun ref concat(
iter: Iterator[A^] ref,
offset: USize val = 0,
len: USize val = call)
: None val

Parameters¶


# Unions

A __union__ type is written like a __tuple__, but it uses a `|` (pronounced "or" when reading the type) instead of a `,` between its elements. Where a tuple represents a collection of values, a union represents a _single_ value that can be any of the specified types.

Unions can be used for tons of stuff that require multiple concepts in other languages. For example, optional values, enumerations, marker values, and more.

```pony
var x: (String | None)
```

Here we have an example of using a union to express an optional type, where `x` might be a `String`, but it also might be `None`.


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


# Implementing Iterators

Iterator implementations need to adhere to the following rules to be considered well-behaved:

* If the Iterator is exhausted, `has_next()` needs to return `false`.
* Once `has_next()` returned `false` it is not allowed to switch back to `true`
(Unless the Iterator supports rewinding)
* `has_next()` does not change its returned value if `next()` has not been called.
That means, that between two calls to `next()` any number of calls to `has_next()`
need to return the same value. (Unless the Iterator supports rewinding)
* A call to `next()` erroring does not necessarily denote exhaustiveness.


ISize val

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

Parameters¶

y: ISize val

Returns¶

ISize val

div¶


y: A

Returns¶

A

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

Parameters¶

y: A

Returns¶


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


u32¶
[Source]
fun ref u32()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val


1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611


(A , Bool val)

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

Parameters¶

y: A

Returns¶

(A , Bool val)

divc¶


y: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

add¶
[Source]


Bool val

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

Parameters¶

y: U128 val

Returns¶

Bool val

le¶
[Source]


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


fun box tcpopt_ccecho()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpopt_eol¶
[Source]


U32 val ?

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

Parameters¶

y: U32 val

Returns¶

U32 val ?

div_partial¶
[Source]


Assert package¶
Contains runtime assertions. If you are looking for assertion that only run
when your code was compiled with the debug flag, check out Assert. For
assertions that are always enabled, check out Fact.
Public Types¶

primitive Assert
primitive Fact


i: USize val)
: ListNode[A] ref ?

Parameters¶

i: USize val

Returns¶

ListNode[A] ref ?

clear¶
[Source]
Empties the list.
fun ref clear()
: None val

Returns¶


## Constructors

Pony constructors have names. Other than that, they are just like constructors in other languages. They can have parameters, and they always return a new instance of the type. Since they have names, you can have more than one constructor for a type.

Constructors are introduced with the __new__ keyword.

```pony
class Wombat
let name: String
var _hunger_level: U64

new create(name': String) =>
name = name'
_hunger_level = 0

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


Generator[Array[T] ref] box

shuffled_iter[T: T]¶
[Source]
fun box shuffled_iter[T: T](
array: Array[T] ref)
: Generator[Iterator[this->T!] ref] box

Parameters¶

array: Array[T] ref

Returns¶

Generator[Iterator[this->T!] ref] box

list_of[T: T]¶


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


class Example
var other: (Example | None) = None

let arr: Array[Example] iso = recover
let obj1 = Example
let obj2 = Example
obj1.other = obj2
obj2.other = obj1
[obj1; obj2]
end
```
"""
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


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


ansi_notify.pony

1
2
3
4
5
6
7
8
9
10
11


Returns¶

U64 val

ctz_unsafe¶
[Source]
Unsafe operation.
If this is 0, the result is undefined.
fun box ctz_unsafe()
: U64 val

Returns¶

U64 val

bitwidth¶
[Source]


12
13
14
15
16
17trait TestList
"""
Source of unit tests for a PonyTest object.
See package doc string for further information and example use.
"""

fun tag tests(test: PonyTest)
"""
Add all the tests in this suite to the given test object.
Typically the implementation of this function will be of the form:
```pony
fun tests(test: PonyTest) =>
test(_TestClass1)
test(_TestClass2)
test(_TestClass3)


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


let params = prop.params()
h.long_test(params.timeout)
let property_runner =
PropertyRunner[(T1, T2, T3)](
consume prop,
params,
h, // PropertyResultNotify
h, // PropertyLogger
h.env
)
h.dispose_when_done(property_runner)
property_runner.run()

class iso Property4UnitTest[T1, T2, T3, T4] is UnitTest

var _prop4: ( Property4[T1, T2, T3, T4] iso | None )
let _name: String

new iso create(p4: Property4[T1, T2, T3, T4] iso, name': (String | None) = None) =>
_name =


U64 val | U128 val | ULong 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)


Returns the Arg by name, defaulting to a fake Arg if unknown.
"""
try _args(name)? else Arg(ArgSpec.bool(name), false) end

class val Option
"""
Option contains a spec and an effective value for a given option.
"""
let _spec: OptionSpec
let _value: _Value

new val create(spec': OptionSpec, value': _Value) =>
_spec = spec'
_value = value'

fun _append(next: Option): Option =>
Option(_spec, _spec._typ_p().append(_value, next._value))

fun spec() : OptionSpec => _spec


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

dispose_when_done¶
[Source]
Let us not have older rounds interfere with newer ones,
thus dispose directly.
be dispose_when_done(
disposable: DisposableActor tag,
round: (_Shrink val | _Run val))

Parameters¶

disposable: DisposableActor tag
round: (_Shrink val | _Run val)


Parameters¶

offset: USize val = 0

Returns¶

F32 val ?

peek_f32_le¶
[Source]
Peek at a little-endian F32.
fun box peek_f32_le(
offset: USize val = 0)
: F32 val ?

Parameters¶

offset: USize val = 0


fun box apply(
wrap: TCPConnectionNotify iso)
: TCPConnectionNotify iso^

Parameters¶

wrap: TCPConnectionNotify iso

Returns¶

TCPConnectionNotify iso^


[Source]
fun ref ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

int_fp_mult[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶


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


"""

@ntohl(_scope)

fun ipv4_addr() : U32 =>
"""
Returns IPV4 address (`_addr` field in the class) if `ip4()` is `True`.
If `ip4()` is `False` then the contents are invalid.
"""
@ntohl(_addr)

fun ipv6_addr() : (U32, U32, U32, U32) =>
"""
Returns IPV6 address as the 4-tuple (say `a`).
`a._1 = _addr1` // Bits 0-32 of the IPv6 address in host byte order.
`a._2 = _addr2  // Bits 33-64 of the IPv6 address in host byte order.
`a._3 = _addr3  // Bits 65-96 of the IPv6 address in host byte order.
`a._4 = _addr4  // Bits 97-128 of the IPv6 address in host byte order.

The contents of the 4-tuple returned are valid only if `ip6()` is `True`.


Parameters¶

len: USize val = 0

Returns¶

Seq[A] ref^

Public Functions¶
reserve¶
[Source]
Reserve space for len elements.
fun ref reserve(
len: USize val)
: None val

Parameters¶

len: USize val


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


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


AlignCenter¶
[Source]
primitive val AlignCenter

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

Returns¶

AlignCenter val^


Bool val

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

Parameters¶

that: TCPListenAuth val

Returns¶

Bool val


end
end

error

fun ref _distance_of(byte: U8): USize ? =>
"""
Get the distance to the first occurrence of the given byte
"""
if _chunks.size() == 0 then
error
end

var node = _chunks.head()?
var search_len: USize = 0

while true do
(var data, var offset) = node()?

try


Parameters¶

y: F64 val

Returns¶

F64 val

neg¶
fun box neg()
: F64 val

Returns¶

F64 val

eq¶
fun box eq(


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


var chosen: (Generator[T] | None) = None
for weighted_gen in weighted_generators.values() do
let new_sum = running_sum + weighted_gen._1
if ((desired_sum == 0) or ((running_sum < desired_sum) and (desired_sum <= new_sum))) then
// we just crossed or reached the desired sum
chosen = weighted_gen._2
break
else
// update running sum
running_sum = new_sum
end
end
match chosen
| let x: Generator[T] box => x.generate(rnd)?
| None =>
Debug("chosen is None, desired_sum: " + desired_sum.string() +
"running_sum: " + running_sum.string())
error
end
end)


while _readable do
let size = _packet_size
let data = _read_buf = recover Array[U8] .> undefined(size) end
let from = recover NetAddress end
let len =
@pony_os_recvfrom(_event, data.cpointer(), data.space(),
from) ?

if len == 0 then
_readable = false
return
end

data.truncate(len)
_notify.received(this, consume data, consume from)

sum = sum + len

if sum > (1 << 12) then


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


Parameters¶

i: USize val
value: val->A

Returns¶

Vec[A] val ?

insert¶
[Source]
Return a vector with an element inserted. Elements after this are moved
up by one index, extending the vector. An out of bounds index raises an
error.
fun val insert(
i: USize val,
value: val->A)
: Vec[A] val ?


Base64¶
[Source]
primitive val Base64

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

Returns¶

Base64 val^


Note the call to `values()` on the array — this is because the loop needs an iterator, not an array.

Like python, pony also support iterating over both index and value like python `enumerate`, like this:

```pony
for (index, value) in ["Bob"; "Fred"; "Sarah"].pairs() do
env.out.print("(" + index.string() + ", " + value + ")")
end
```

The iterator does not have to be of any particular type, but needs to provide the following methods:

```pony
fun has_next(): Bool
fun next(): T?
```


Bool val

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

Returns¶

Bool val

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

Returns¶


Bool val


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


one_of_safe[T: T]¶
[Source]
Version of one_of that will error if xs is empty.
fun box one_of_safe[T: T](
xs: ReadSeq[T] box,
do_shrink: Bool val = false)
: Generator[box->T] box ?

Parameters¶

xs: ReadSeq[T] box
do_shrink: Bool val = false

Returns¶

Generator[box->T] box ?

frequency[T: T]¶
[Source]


(K^ , V^) ?

get_or_else¶
[Source]
Get the value associated with provided key if present. Otherwise,
return the provided alternate value.
fun box get_or_else(
key: box->K!,
alt: this->V)
: this->V

Parameters¶

key: box->K!
alt: this->V

Returns¶

this->V


# Basic concepts

There are a few simple concepts you need to understand before reference capabilities will make any sense. We've talked about some of these already, and some may already be obvious to you, but it's worth recapping here.


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


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

Parameters¶

y: USize val

Returns¶

USize val

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

Parameters¶


multicast_join¶
[Source]
Add a multicast group. This can be limited to packets arriving on a
specific interface.
be multicast_join(
group: String val,
to: String val = "")

Parameters¶

group: String val
to: String val = ""

multicast_leave¶
[Source]
Drop a multicast group. This can be limited to packets arriving on a
specific interface. No attempt is made to check that this socket has
previously added this group.
be multicast_leave(


Parameters¶

that: SignalRaise val

Returns¶

Bool val


Cap¶
[Source]
The Capsicum rights.
primitive val Cap

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

Returns¶


Time Package¶
The Time Package provides classes and methods for timing operations,
dealing with dates and times, and scheduling tasks.
Public Types¶

primitive Nanos
class PosixDate
primitive Time
class Timer
interface TimerNotify
actor Timers


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


fun box fldc(
y: A)
: (A , Bool val)

Parameters¶

y: A

Returns¶

(A , Bool val)

modc¶
[Source]
fun box modc(
y: A)
: (A , Bool val)

Parameters¶


fun box hash()
: USize val

Returns¶

USize val

addc¶
[Source]
fun box addc(
y: ULong val)
: (ULong val , Bool val)

Parameters¶

y: ULong val

Returns¶


U128 val

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

Returns¶

U128 val

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

Parameters¶


fun box ip_max_source_filter()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_min_memberships¶
[Source]


Parameters¶

flag: A

Returns¶

None val

flip¶
[Source]
Sets the flag if it is unset, unsets the flag if it is set.
fun ref flip(
flag: A)
: None val

Parameters¶

flag: A


fun box shl_unsafe(
y: U128 val)
: U128 val

Parameters¶

y: U128 val

Returns¶

U128 val

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

Parameters¶


break
end

result.push(cur = recover String end)
else
// Add bytes to the current string.
var j = U8(0)

while j < len do
cur.push(_ptr._apply(i + j.usize()))
j = j + 1
end
end

i = i + len.usize()
end
end

// Add all remaining bytes to the current string.
while i < _size do


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


actual: Bool val
msg: String val = ""
loc: SourceLoc val = __loc

Returns¶

Bool val

assert_false¶
[Source]
Assert that the given expression is false.
fun box assert_false(
actual: Bool val,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val

Parameters¶


Parameters¶

from: ISize val
to: ISize val = call

Returns¶

String iso^

lower¶
[Source]
Returns a lower case version of the string.
fun box lower()
: String iso^

Returns¶

String iso^


type BinaryHeapPriority[A: Comparable[A] #read] is
( _BinaryHeapPriority[A]
& (MinHeapPriority[A] | MaxHeapPriority[A]))

interface val _BinaryHeapPriority[A: Comparable[A] #read]
new val create()
fun apply(x: A, y: A): Bool

primitive MinHeapPriority[A: Comparable[A] #read] is _BinaryHeapPriority[A]
fun apply(x: A, y: A): Bool =>
x < y

primitive MaxHeapPriority [A: Comparable[A] #read] is _BinaryHeapPriority[A]
fun apply(x: A, y: A): Bool =>
x > y


Blue text.
fun box blue()
: String val

Returns¶

String val

magenta¶
[Source]
Magenta text.
fun box magenta()
: String val

Returns¶

String val


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


I8 val

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

Returns¶

I16 val

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

Returns¶


isize¶
[Source]
fun box isize(
base: U8 val = 0)
: ISize val ?

Parameters¶

base: U8 val = 0

Returns¶

ISize val ?

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


new val create(
from: Bool val)
: Bool val^

Parameters¶

from: Bool val

Returns¶

Bool val^

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


new val create()
: FormatGeneralLarge val^

Returns¶

FormatGeneralLarge val^

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

Parameters¶

that: FormatGeneralLarge val

Returns¶


compile_intrinsic

fun f32_unsafe(): F32 =>
"""
Unsafe operation.
If the value doesn't fit in the destination type, the result is undefined.
"""
compile_intrinsic

fun f64_unsafe(): F64 =>
"""
Unsafe operation.
If the value doesn't fit in the destination type, the result is undefined.
"""
compile_intrinsic

trait val Real[A: Real[A] val] is
(Stringable & _ArithmeticConvertible & Comparable[A])
new val create(value: A)


Bool val


fun box ip_min_memberships()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_mtu¶
[Source]


None val

set_keepalive¶
[Source]
Sets the TCP keepalive timeout to approximately secs seconds. Exact
timing is OS dependent. If secs is zero, TCP keepalive is disabled. TCP
keepalive is disabled by default. This can only be set on a connected
socket.
fun ref set_keepalive(
secs: U32 val)
: None val

Parameters¶

secs: U32 val

Returns¶


y: A)
: (A , Bool val)

Parameters¶

y: A

Returns¶

(A , Bool val)

fldc¶
[Source]
Divide this integer by y and return the result, rounded towards negative infinity and a flag indicating overflow or division by zero.
fun box fldc(
y: A)
: (A , Bool val)

Parameters¶


notifier: ProcessNotify iso
filepath: FilePath val
args: Array[String val] val
vars: Array[String val] val
wdir: (FilePath val | None val) = reference
process_poll_interval: U64 val = call

Returns¶

ProcessMonitor tag^

Public Behaviours¶
print¶
[Source]
Print some bytes and append a newline.
be print(
data: (String val | Array[U8 val] val))

Parameters¶


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


cap.pony

1
2
3
4
5
6
7
8
9
10
11


y: I16 val

Returns¶

Bool val

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

Parameters¶

y: I16 val

Returns¶


y: U32 val

Returns¶

Bool val

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

Returns¶

USize val

hash64¶
[Source]


fun box i64_unsafe()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong_unsafe¶
[Source]


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


"""
@pony_os_host_ip6(host.cstring())

fun _resolve(
auth: DNSAuth,
family: U32,
host: String,
service: String)
: Array[NetAddress] iso^
=>
"""
Turns an addrinfo pointer into an array of addresses.
"""
var list = recover Array[NetAddress] end
var result = @pony_os_addrinfo(family, host.cstring(), service.cstring())

if not result.is_null() then
var addr = result

while not addr.is_null() do


_SignedPartialArithmetic.sub_partial[I32](this, y)?

fun mul_partial(y: I32): I32 ? =>
_SignedPartialArithmetic.mul_partial[I32](this, y)?

fun div_partial(y: I32): I32 ? =>
_SignedPartialArithmetic.div_partial[I32, U32](this, y)?

fun rem_partial(y: I32): I32 ? =>
_SignedPartialArithmetic.rem_partial[I32, U32](this, y)?

fun divrem_partial(y: I32): (I32, I32) ? =>
_SignedPartialArithmetic.divrem_partial[I32, U32](this, y)?

fun fld_partial(y: I32): I32 ? =>
_SignedPartialArithmetic.fld_partial[I32, U32](this, y)?

fun mod_partial(y: I32): I32 ? =>
_SignedPartialArithmetic.mod_partial[I32, U32](this, y)?


"""
var _head: (ListNode[A] | None) = None
var _tail: (ListNode[A] | None) = None
var _size: USize = 0

new create(len: USize = 0) =>
"""
Always creates an empty list with 0 nodes, `len` is ignored.

Required method for `List` to satisfy the `Seq` interface.
```pony
let my_list = List[String]
```
"""
None

new unit(a: A) =>
"""
Creates a list with 1 node of element.


fun box hash64()
: U64 val

Returns¶

U64 val

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

Returns¶

I8 val

i16¶
[Source]


// prepend() returns a new List, leaving the
// old list unchanged
let l2 = empty.prepend(3) // List(3)
let l3 = l2.prepend(2) // List(2, 3)
let l4 = l3.prepend(1) // List(1, 2, 3)
let l4_head = l4.head() // 1
let l4_tail = l4.tail() // List(2, 3)

l4_head == 1
Lists[U32].eq(l4, Lists[U32]([1; 2; 3]))?
Lists[U32].eq(l4_tail, Lists[U32]([2; 3]))?

let doubled = l4.map[U32]({(x) => x * 2 })

Lists[U32].eq(doubled, Lists[U32]([2; 4; 6]))?
end

type List[A: A] is
(Cons[A] val | Nil[A] val)


end
end
end

fun ref truncate(len: USize) =>
"""
Pop tail elements until the list is len size.
If the list is already smaller than len, do nothing.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
my_list.truncate(1)  // my_list is ["a"]
```
"""
try
while _size > len do
pop()?
end
end


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.
Example code¶
use "encode/base64"

actor Main
new create(env: Env) =>
env.out.print(Base64.encode("foobar"))
try
env.out.print(Base64.decode[String iso]("Zm9vYmFy")?)


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


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

Parameters¶

y: USize val

Returns¶

USize val

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

Parameters¶


fun box rds_rdma_notify_me()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_rdma_readwrite¶
[Source]


// .skip(1)
.map_stateful[MapIs[K, V]^]({
(s: USize): MapIs[K, V]^ =>
MapIs[K, V].create(s).>concat(
Iter[(K^, V^)](gen.value_iter(rnd)).take(s)
)
})
(consume result, shrink_iter)
end)

fun one_of[T](xs: ReadSeq[T], do_shrink: Bool = false): Generator[box->T] =>
"""
Generate a random value from the given ReadSeq.
This generator will generate nothing if the given xs is empty.

Generators created with this method do not support shrinking.
If `do_shrink` is set to `true`, it will return the same value
for each shrink round. Otherwise it will return nothing.
"""


fun box ipv6_checksum()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_drop_membership¶
[Source]


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)


fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

I8 val

i16_unsafe¶
[Source]


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


gen2: Generator[T2] box
gen3: Generator[T3] box
fn: {(T1, T2, T3): T4^}[T1, T2, T3, T4] ref

Returns¶

Generator[T4] box

map4[T1: T1, T2: T2, T3: T3, T4: T4, T5: T5]¶
[Source]
Convenience combinator for mapping 4 generators into 1.
fun box map4[T1: T1, T2: T2, T3: T3, T4: T4, T5: T5](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
gen4: Generator[T4] box,
fn: {(T1, T2, T3, T4): T5^}[T1, T2, T3, T4, T5] ref)
: Generator[T5] box


Lists[A] val^

Public Functions¶
empty¶
[Source]
Returns an empty list.
fun box empty()
: (Cons[A] val | Nil[A] val)

Returns¶

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

cons¶
[Source]
Returns a list that has h as a head and t as a tail.
fun box cons(


32
33
34
35
36
37
38
39
40
41trait val FormatSpec

primitive FormatDefault is FormatSpec

primitive FormatUTF32 is FormatSpec
primitive FormatBinary is FormatSpec
primitive FormatBinaryBare is FormatSpec
primitive FormatOctal is FormatSpec
primitive FormatOctalBare is FormatSpec
primitive FormatHex is FormatSpec
primitive FormatHexBare is FormatSpec


compare¶
[Source]
fun box compare(
that: box->A)
: (Less val | Equal val | Greater val)

Parameters¶

that: box->A

Returns¶

(Less val | Equal val | Greater val)


y: F32 val

Returns¶

Bool val

ge_unsafe¶
fun box ge_unsafe(
y: F32 val)
: Bool val

Parameters¶

y: F32 val

Returns¶

Bool val


Returns¶

F32 val

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

Returns¶

F32 val

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


B

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

Returns¶

B

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

Returns¶


fun ref add_section(section: String): Bool =>
"""
This is called for every valid section in the INI file. Return false
to halt processing.
"""
true

fun ref errors(line: USize, err: IniError): Bool =>
"""
This is called for each error encountered. Return false to halt processing.
"""
true

primitive Ini
"""
A streaming parser for INI formatted lines of test.
"""
fun apply(lines: Iterator[String box], f: IniNotify): Bool =>
"""
This accepts a string iterator and calls the IniNotify for each new entry.


var a: Foo = a.create()
```

Here we specify that `var a` is type `Foo`, then proceed to use `a` to call the constructor, `create()`, for objects of type `Foo`.


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

Parameters¶

y: A

Returns¶

(A , Bool val)

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


Files package¶
The Files package provides classes for working with files and
directories.
Files are identified by FilePath objects, which represent both the
path to the file and the capabilites for accessing the file at that
path. FilePath objects can be used with the CreateFile and
OpenFile primitives and the File class to get a reference to a
file that can be used to write to and/or read from the file. It can
also be used with the Directory object to get a reference to a
directory object that can be used for directory operations.
The FileLines class allows a file to be accessed one line at a time.
The FileStream actor provides the ability to asynchronously write to
a file.


std_stream.pony

1
2
3
4
5
6
7
8
9
10
11


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:

```pony
fun apply(h: TestHelper) =>
let a: Array[U8] = [1; 2; 3]
let b: Array[U8] = [1; 3; 2]
h.assert_array_eq_unordered[U8](a, b)
```
"""
try
let missing = Array[box->A]
let consumed = Array[Bool].init(false, actual.size())
for e in expect.values() do
var found = false
var i: USize = -1
for a in actual.values() do
i = i + 1


fun box ipproto_mh()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_micp¶
[Source]


trait val _ValueType
fun string(): String
fun value_of(s: String): _Value ?
fun is_seq(): Bool => false
fun append(v1: _Value, v2: _Value): _Value => v1

primitive _BoolType is _ValueType
fun string(): String => "Bool"
fun value_of(s: String): _Value ? => s.bool()?

primitive _StringType is _ValueType
fun string(): String => "String"
fun value_of(s: String): _Value => s

primitive _I64Type is _ValueType
fun string(): String => "I64"
fun value_of(s: String): _Value ? => s.i64()?

primitive _U64Type is _ValueType
fun string(): String => "U64"


_notifier.failed(this, ProcessError(WriteError))
return
end
end


ini_map.pony

1
2
3
4
5
6
7
8
9
10
11


fun box pread()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

mmap¶
[Source]


732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751


peek_u8(offset)?.i8()

fun peek_u16_be(offset: USize = 0): U16 ? =>
"""
Peek at a big-endian U16.
"""
(peek_u8(offset)?.u16() << 8) or peek_u8(offset + 1)?.u16()

fun peek_u16_le(offset: USize = 0): U16 ? =>
"""
Peek at a little-endian U16.
"""
peek_u8(offset)?.u16() or (peek_u8(offset + 1)?.u16() << 8)

fun peek_i16_be(offset: USize = 0): I16 ? =>
"""
Peek at a big-endian I16.
"""
peek_u16_be(offset)?.i16()


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


[Source]
fun ref after()
: None val ?

Returns¶

None val ?

after_iteration¶
[Source]
fun ref after_iteration()
: None val ?

Returns¶

None val ?


if (c >= 0x41) and (c <= 0x5A) then
_set(i, c + 0x20)
end

i = i + 1
end

fun upper(): String iso^ =>
"""
Returns an upper case version of the string. Currently only knows ASCII
case.
"""
let s = clone()
s.upper_in_place()
s

fun ref upper_in_place() =>
"""
Transforms the string to upper case.
"""


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


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


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


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


else
compile_error "no clock_gettime monotonic clock"
end

primitive _ClockUptimeRaw
fun apply(): U32 =>
ifdef osx then
8
else
compile_error "no clock_gettime_nsec_np uptime raw clock"
end

primitive Time
"""
A collection of ways to fetch the current time.
"""
fun now(): (I64 /*sec*/, I64 /*nsec*/) =>
"""
The wall-clock adjusted system time with nanoseconds.
Return: (seconds, nanoseconds)


Returns¶

String val

apply¶
[Source]
fun ref apply(
h: TestHelper val)
: None val ?

Parameters¶

h: TestHelper val

Returns¶

None val ?


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


Parameters¶

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

Returns¶

OptionSpec val^

u64¶
[Source]
Creates an Option with an U64 typed value that can be used like
--count=47 -C=47
to yield an option value like
cmd.option("count").u64() == U64(47).
new val u64(
name': String val,


(_family and 0xff).u8()
end
else
ifdef bigendian then
(_family and 0xff).u8()
else
((_family >> 8) and 0xff).u8()
end
end

fun port() : U16 =>
"""
Returns port number in host byte order.
"""
@ntohs(_port)

fun scope() : U32 =>
"""
Returns IPv6 scope identifier: Unicast, Anycast, Multicast and
unassigned scopes.


: None val

Parameters¶

msg: String val

Returns¶

None val

complete¶
[Source]
Called when the Property execution is complete
signalling whether it was successful or not.
fun box complete(
success: Bool val)
: None val

Parameters¶


Parameters¶

base: U8 val = 0

Returns¶

I64 val ?

i128¶
[Source]
fun box i128(
base: U8 val = 0)
: I128 val ?

Parameters¶

base: U8 val = 0


var ponyversion: Bool = false
"""
Print the version of the compiler and exit.
"""

var ponyhelp: Bool = false
"""
Print the runtime usage options and exit.
"""


exclusion_group¶
fun box exclusion_group()
: String val

Returns¶

String val

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

Parameters¶

h: TestHelper val

Returns¶


fun box local_peeruuid()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

max_tcpoptlen¶
[Source]


(ILong val , ILong val)

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

Parameters¶

y: ILong val

Returns¶

ILong val

neg_unsafe¶


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

Parameters¶

y: ISize val

Returns¶

ISize val ?

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


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


Parameters¶

len: USize val

Returns¶

None val

clone¶
[Source]
Clone all elements into a new List.
Note: elements are not copied, an additional reference to each element is created in the new List.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.clone()  // my_list is ["a"; "b"; "c"], other_list is ["a"; "b"; "c"]

fun box clone()
: List[this->A!] ref^


Public Functions¶
value¶
[Source]
fun box value()
: U32 val

Returns¶

U32 val

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

Parameters¶


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


that: FileLink val

Returns¶

Bool val

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

Parameters¶

that: FileLink val

Returns¶


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


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


MapIs[K: K, V: V]¶
[Source]
This is a map that uses identity comparison on the key.
type MapIs[K: K, V: V] is
HashMap[K, V, HashIs[K] val] ref

Type Alias For¶

HashMap[K, V, HashIs[K] val] ref


fun descr(): String =>
"""
Returns the description for this arg.
"""
_descr

fun _typ_p(): _ValueType => _typ

fun _default_p(): _Value => _default

fun required(): Bool =>
"""
Returns true iff this arg is required to be present in the command line.
"""
_required

fun help_string(): String =>
"""
Returns a formated help string for this arg.


m: HashMap[K, V, H] val

Returns¶

MapKeys[K, V, H] ref^

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

Returns¶

Bool val

next¶
[Source]


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


IntPairUnitTest¶
[Source]
type IntPairUnitTest is
Property1UnitTest[IntPairPropertySample ref] iso

Type Alias For¶

Property1UnitTest[IntPairPropertySample ref] iso


y: I8 val

Returns¶

I8 val

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

Returns¶

I8 val

add¶
[Source]


fun box ipproto_igmp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_igrp¶
[Source]


# Literals

***What do we want?***

Values!

***Where do we want them?***

In our Pony programs!

***Say no more***

Every programming language has literals to encode values of certain types, and so does Pony.

In Pony you can express booleans, numeric types, characters, strings and arrays as literals.


fun box i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]


# Usage

Writing property based tests in PonyCheck is done by implementing the trait [`Property1`](https://stdlib.ponylang.io/pony_check-Property1). A [`Property1`](https://stdlib.ponylang.io/pony_check-Property1) needs to define a type parameter for the type of the input sample, a [`Generator`](https://stdlib.ponylang.io/pony_check-Generator) and a property function. Here is a minimal example:

```pony
use "pony_test"

class _MyFirstProperty is Property1[String]
fun name(): String =>
"my_first_property"

fun gen(): Generator[String] =>
Generators.ascii()

fun property(arg1: String, ph: PropertyHelper) =>
ph.assert_eq[String](arg1, arg1)
```

A `Property1` needs a name for identification in test output. We created a `Generator` by using one of the many convenience factory methods and combinators defined in the [`Generators`](https://stdlib.ponylang.io/pony_check-Generators) primitive and we used [`PropertyHelper`](https://stdlib.ponylang.io/pony_check-PropertyHelper) to assert on a condition that should hold for all samples


Parameters¶

y: USize val

Returns¶

ISize val

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

Returns¶

String iso^

add_unsafe¶


Returns¶

Bool val

lt¶
[Source]
Return true if every element in this is also in that, and this has fewer
elements than that.
fun box lt(
that: HashSet[A, H] box)
: Bool val

Parameters¶

that: HashSet[A, H] box

Returns¶


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


Public Functions¶
time¶
[Source]
Return a POSIX time. Treats the date as UTC.
fun box time()
: I64 val

Returns¶

I64 val

normal¶
[Source]
Normalise all the fields of the date. For example, if the hour is 24, it is
set to 0 and the day is advanced. This allows fields to be changed naively,
eg. adding 1000 to hours to advance the time by 1000 hours, and then
normalising the date.
fun ref normal()


### Example

```pony
Iter[U32].repeat_value(7)
```
`7 7 7 7 7 7 7 7 7 ...`
"""
_iter =
object
let _v: A = consume value

fun ref has_next(): Bool => true

fun ref next(): A => _v
end

fun ref next_or(default: A): A =>
"""
Return the next value, or the given default.


y: U128 val

Returns¶

U128 val

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

Parameters¶

y: U128 val

Returns¶


fun box shr(
y: U64 val)
: I64 val

Parameters¶

y: U64 val

Returns¶

I64 val

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

Parameters¶


ULong val

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

Returns¶

ILong val

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

Returns¶


Bool val


fun box so_conaccess()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_conditional_accept¶
[Source]


p3.join([p1; p2].values())
.next[None]({(a: Array[String val] val) =>
for s in a.values() do
env.out.print(s)
end
})

p2("second")
p3("third")
p1("first")

fun tag join(
ps: Iterator[Promise[A] tag] ref)
: Promise[Array[A] val] tag

Parameters¶

ps: Iterator[Promise[A] tag] ref

Returns¶


Returns¶

I128 val

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

Returns¶

U128 val

i128_unsafe¶
[Source]
Unsafe operation.
If the value doesn't fit in the destination type, the result is undefined.
fun box i128_unsafe()


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

Parameters¶

c: AsyncBenchContinue val

Returns¶

None val

config¶
[Source]
fun box config()
: BenchConfig val


end

try
ifdef posix then
_child = _ProcessPosix.create(
filepath.path, args, vars, wdir, _err, _stdin, _stdout, _stderr)?
elseif windows then
let windows_child = _ProcessWindows.create(
filepath.path, args, vars, wdir, _stdin, _stdout, _stderr)
_child = windows_child
// notify about errors
match windows_child.process_error
| let pe: ProcessError =>
_notifier.failed(this, pe)
return
end
else
compile_error "unsupported platform"
end
_err.begin(this)


If either i or j are out of bounds, an error is raised.
"""
if (i >= _size) or (j >= _size) then error end

let x = _ptr._apply(i)
_ptr._update(i, _ptr._apply(j))
_ptr._update(j, consume x)

fun keys(): ArrayKeys[A, this->Array[A]]^ =>
"""
Return an iterator over the indices in the array.
"""
ArrayKeys[A, this->Array[A]](this)

fun values(): ArrayValues[A, this->Array[A]]^ =>
"""
Return an iterator over the values in the array.
"""
ArrayValues[A, this->Array[A]](this)


var _stdout: _Pipe = _Pipe.none()
var _stderr: _Pipe = _Pipe.none()
var _err: _Pipe = _Pipe.none()
var _child: _Process = _ProcessNone

let _max_size: USize = 4096
var _read_buf: Array[U8] iso = recover Array[U8] .> undefined(_max_size) end
var _read_len: USize = 0
var _expect: USize = 0

embed _pending: List[(ByteSeq, USize)] = _pending.create()
var _done_writing: Bool = false

var _closed: Bool = false
var _timers: (Timers tag | None) = None
let _process_poll_interval: U64

var _polling_child: Bool = false
var _final_wait_result: (_WaitResult | None) = None


y: U64 val

Returns¶

Bool val

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

Parameters¶

y: U64 val

Returns¶


Package

PonyBench provides a microbenchmarking framework. It is designed to measure
the runtime of synchronous and asynchronous operations.
Example Program¶
The following is a complete program with multiple trivial benchmarks followed
by their output.
use "time"
use "pony_bench"

actor Main is BenchmarkList
new create(env: Env) =>
PonyBench(env, this)


let _params: String

let env: Env

new val create(
env': Env,
runner: _IPropertyRunner,
run_notify: _PropertyRunNotify,
run: _Round,
params: String
) =>
env = env'
_runner = runner
_run_notify = run_notify
_run = run
_params = params

/****** START DUPLICATION FROM TESTHELPER ********/

fun log(msg: String, verbose: Bool = false) =>


time.pony

1
2
3
4
5
6
7
8
9
10
11


udp_socket.pony

1
2
3
4
5
6
7
8
9
10
11


key: K

Returns¶

HashMap[K, V, H] val

keys¶
[Source]
fun val keys()
: MapKeys[K, V, H] ref

Returns¶

MapKeys[K, V, H] ref

values¶
[Source]


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


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


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() or (u8()?.u64() << 8) or
(u8()?.u64() << 16) or (u8()?.u64() << 24) or
(u8()?.u64() << 32) or (u8()?.u64() << 40) or
(u8()?.u64() << 48) or (u8()?.u64() << 56)
end
else


max: ILong = ILong.max_value())
: ILong
=>
"""
Generate a ILong in closed interval [min, max]
(default: [min_value, max_value]).

Behavior is undefined if `min` > `max`.
"""
min + ulong(0, (max - min).ulong()).ilong()

fun ref isize(
min: ISize = ISize.min_value(),
max: ISize = ISize.max_value())
: ISize
=>
"""
Generate a ISize in closed interval [min, max]
(default: [min_value, max_value]).


that: FileWrite val

Returns¶

Bool val

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

Parameters¶

that: FileWrite val

Returns¶


pony_test.pony

1
2
3
4
5
6
7
8
9
10
11


In order to connect via proxy, return the host & service for the proxy
server.

An implementation of this function might look like:
```pony
let _proxy_host = "some-proxy.example.com"
let _proxy_service = "80"
var _destination_host: ( None | String )
var _destination_service: ( None | String )

fun ref proxy_via(host: String, service: String): (String, String) =>
_destination_host = host
_destination_service = service
( _proxy_host, _proxy_service )
```
"""
(host, service)

fun ref connecting(conn: TCPConnection ref, count: U32) =>
"""


sample: IntPairPropertySample ref,
h: PropertyHelper val)
: None val ?

Parameters¶

sample: IntPairPropertySample ref
h: PropertyHelper val

Returns¶

None val ?

int_property[T: ((I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Integer[T] val)]¶
[Source]
fun ref int_property[T: ((I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |


fun box so_vm_sockets_buffer_min_size()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_vm_sockets_connect_timeout¶
[Source]


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

Parameters¶

n: N

Returns¶

N

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


632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651


ILong val

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

Parameters¶

y: ULong val

Returns¶

ILong val

string¶


new iso create(
p3: Property3[T1, T2, T3] iso,
name': (String val | None val) = reference)
: Property3UnitTest[T1, T2, T3] iso^

Parameters¶

p3: Property3[T1, T2, T3] iso
name': (String val | None val) = reference

Returns¶

Property3UnitTest[T1, T2, T3] iso^

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


fun ilong(
min: ILong = ILong.min_value(),
max: ILong = ILong.max_value())
: Generator[ILong]
=>
"""
Create a generator for ILong values.
"""
let that = this
Generator[ILong](
object is GenObj[ILong]
fun generate(rnd: Randomness): ILong^ =>
rnd.ilong(min, max)

fun shrink(i: ILong): ValueAndShrink[ILong] =>
that._int_shrink[ILong](consume i, min)
end)

fun isize(


max-heaps, the greatest item will be returned. For min-heaps, the smallest
item will be returned.

The time complexity of this operation is O(log(n)) with respect to the size
of the heap.
"""
let n = size() - 1
_data.swap_elements(0, n)?
_sift_down(0, n)
_data.pop()?

fun ref append(
seq: (ReadSeq[A] & ReadElement[A^]),
offset: USize = 0,
len: USize = -1)
=>
"""
Append len elements from a sequence, starting from the given offset.
"""
_data.append(seq, offset, len)


CapRights¶
[Source]
type CapRights is
CapRights0 ref

Type Alias For¶

CapRights0 ref


use @"llvm.smul.with.overflow.i32"[(I32, Bool)](a: I32, b: I32)
use @"llvm.smul.with.overflow.i64"[(I64, Bool)](a: I64, b: I64)

primitive I8 is SignedInteger[I8, U8]
new create(value: I8) => value
new from[A: (Number & Real[A] val)](a: A) => a.i8()

new min_value() => -0x80
new max_value() => 0x7F

fun abs(): U8 => if this < 0 then (-this).u8() else this.u8() end
fun bit_reverse(): I8 => @"llvm.bitreverse.i8"(this.u8()).i8()
fun bswap(): I8 => this
fun popcount(): U8 => @"llvm.ctpop.i8"(this.u8())
fun clz(): U8 => @"llvm.ctlz.i8"(this.u8(), false)
fun ctz(): U8 => @"llvm.cttz.i8"(this.u8(), false)

fun clz_unsafe(): U8 =>
"""
Unsafe operation.


I64 val

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

Returns¶

I128 val

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

Returns¶


filepath = path

let fstatat =
@pony_os_fstatat(fd, from.cstring(), this)
if not fstatat then error end


UnsignedInteger[A: UnsignedInteger[A] val]¶
[Source]
trait val UnsignedInteger[A: UnsignedInteger[A] val] is
Integer[A] val

Implements¶

Integer[A] val

Constructors¶
create¶
[Source]


y: I128 val

Returns¶

(I128 val , Bool val)

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

Parameters¶

y: I128 val

Returns¶


F32 val

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

Returns¶

F64 val

compare¶
[Source]
fun box compare(
that: box->A)
: (Less val | Equal val | Greater val)

Parameters¶


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


fun ipproto_ipcv():I32 => @pony_os_sockopt_level(I32(4051))
fun ipproto_ipeip():I32 => @pony_os_sockopt_level(I32(4052))
fun ipproto_ipip():I32 => @pony_os_sockopt_level(I32(4053))
fun ipproto_ippc():I32 => @pony_os_sockopt_level(I32(4054))
fun ipproto_ipv4():I32 => @pony_os_sockopt_level(I32(4055))
fun ipproto_ipv6():I32 => @pony_os_sockopt_level(I32(4056))
fun ipproto_irtp():I32 => @pony_os_sockopt_level(I32(4057))
fun ipproto_kryptolan():I32 => @pony_os_sockopt_level(I32(4058))
fun ipproto_larp():I32 => @pony_os_sockopt_level(I32(4059))
fun ipproto_leaf1():I32 => @pony_os_sockopt_level(I32(4060))
fun ipproto_leaf2():I32 => @pony_os_sockopt_level(I32(4061))
fun ipproto_max():I32 => @pony_os_sockopt_level(I32(4062))
fun ipproto_maxid():I32 => @pony_os_sockopt_level(I32(4063))
fun ipproto_meas():I32 => @pony_os_sockopt_level(I32(4064))
fun ipproto_mh():I32 => @pony_os_sockopt_level(I32(4065))
fun ipproto_mhrp():I32 => @pony_os_sockopt_level(I32(4066))
fun ipproto_micp():I32 => @pony_os_sockopt_level(I32(4067))
fun ipproto_mobile():I32 => @pony_os_sockopt_level(I32(4068))
fun ipproto_mpls():I32 => @pony_os_sockopt_level(I32(4069))
fun ipproto_mtp():I32 => @pony_os_sockopt_level(I32(4070))


fun ref insert_in_place(offset: ISize, that: String box) =>
"""
Inserts the given string at the given offset. Appends the string if the
offset is out of bounds.
"""
reserve(_size + that._size)
let index = offset_to_index(offset).min(_size)
@memmove(_ptr.usize() + index + that._size,
_ptr.usize() + index, _size - index)
that._ptr._copy_to(_ptr._offset(index), that._size)
_size = _size + that._size
_set(_size, 0)

fun ref insert_byte(offset: ISize, value: U8) =>
"""
Inserts a byte at the given offset. Appends if the offset is out of bounds.
"""
reserve(_size + 1)
let index = offset_to_index(offset).min(_size)
@memmove(_ptr.usize() + index + 1, _ptr.usize() + index,


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

Parameters¶

y: USize val

Returns¶

USize val

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

Parameters¶


// If it fires, we send the escape sequence as if it was normal data.
if _escape isnt _EscapeNone then
if _timer isnt None then
try _timers.cancel(_timer as Timer tag) end
end

let t = recover
object is TimerNotify
let term: ANSITerm = this

fun ref apply(timer: Timer, count: U64): Bool =>
term._timeout()
false
end
end

let timer = Timer(consume t, 25000000)
_timer = timer
_timers(consume timer)
end


Returns¶

F32 val

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

Returns¶

F32 val

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


fun box ip_recvflowid()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_recvopts¶
[Source]


prealloc: USize val = 6)
: HashMap[K, V, H] ref^

Parameters¶

prealloc: USize val = 6

Returns¶

HashMap[K, V, H] ref^

Public Functions¶
size¶
[Source]
The number of items in the map.
fun box size()
: USize val

Returns¶


else compile_error "no SIGPIPE"
end

fun alrm(): U32 => 14
fun term(): U32 => 15

fun urg(): U32 =>
ifdef bsd or osx then 16
elseif linux then 23
else compile_error "no SIGURG"
end

fun stkflt(): U32 =>
ifdef linux then 16
else compile_error "no SIGSTKFLT"
end

fun stop(): U32 =>
ifdef bsd or osx then 17
elseif linux then 19


contains¶
[Source]
Checks whether the map contains the key k
fun box contains(
k: box->K!)
: Bool val

Parameters¶

k: box->K!

Returns¶

Bool val

concat¶
[Source]


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


[Source]
fun box params()
: PropertyParams val

Returns¶

PropertyParams val


Returns¶

Poperator[T] ref^

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

Returns¶

Bool val

next¶
[Source]
fun ref next()


A

addc¶
[Source]
fun box addc(
y: A)
: (A , Bool val)

Parameters¶

y: A

Returns¶

(A , Bool val)

subc¶
[Source]


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


"""
Inform the notifier that we're connecting.
"""
if _connect_count > 0 then
_notify.connecting(this, _connect_count)
else
_notify.connect_failed(this)
hard_close()
end

fun ref close() =>
"""
Attempt to perform a graceful shutdown. Don't accept new writes. If the
connection isn't muted then we won't finish closing until we get a zero
length read. If the connection is muted, perform a hard close and shut
down immediately.
"""
ifdef windows then
_close()
else


fld_unsafe¶
[Source]
Floored division, rounded towards negative infinity,
as opposed to div which rounds towards zero.
Unsafe Operation
If y is 0, the result is undefined.
If the operation overflows, the result is undefined.
fun box fld_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶

A


### Example

```pony
let x: (U64 | None) = 42
Iter[U64].maybe(x).next_or(0)
```
`42`
"""
if has_next() then
try next()? else default end
else
default
end

fun ref map_stateful[B](f: {ref(A!): B ?}): Iter[B]^ =>
"""
Allows stateful transformation of each element from the iterator, similar
to `map`.
"""
Iter[B](


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

Parameters¶

y: I16 val

Returns¶

(I16 val , I16 val)

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

Parameters¶


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751


let c = Foo("hi")

if a == b then
// won't print
e.out.print("1")
end

if a == c then
// will print
e.out.print("2")
end

if a is c then
// won't print
e.out.print("3")
end
```

If you don't define your own `eq`, you will inherit the default implementation that defines equal by value as being the same as by identity.


# Short circuiting

The `and` and `or` operators use __short circuiting__ when used with boolean variables. This means that the first operand is always evaluated, but the second is only evaluated if it can affect the result.

For `and`, if the first operand is __false__ then the second operand is not evaluated since it cannot affect the result.

For `or`, if the first operand is __true__ then the second operand is not evaluated since it cannot affect the result.

This is a special feature built into the compiler, it cannot be used with operator aliasing for any other type.


Returns the host and service name.
If reversedns is DNSAuth,
a DNS lookup will be executed and the hostname
for this address is returned as first element of the result tuple.
If no hostname could be found, an error is raised.
If reversedns is None the plain IP address is given
and no DNS lookup is executed.
If servicename is false the numeric port is returned
as second element of the result tuple.
If it is true the port is translated into its
corresponding servicename (e.g. port 80 is returned as "http").
Internally this method uses the POSIX C function getnameinfo.
fun box name(
reversedns: (DNSAuth val | None val) = reference,
servicename: Bool val = false)
: (String val , String val) ?

Parameters¶

reversedns: (DNSAuth val | None val) = reference


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


size: USize)
use @pony_os_std_write[None](file: Pointer[None] tag, buffer: Pointer[U8] tag,
size: USize)
type ByteSeq is (String | Array[U8] val)

interface val ByteSeqIter
"""
Accept an iterable collection of String or Array[U8] val.
"""
fun values(): Iterator[this->ByteSeq box]

interface tag OutStream
"""
Asnychronous access to some output stream.
"""
be print(data: ByteSeq)
"""
Print some bytes and insert a newline afterwards.
"""


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


"""
Tab completion.

TODO: Improve this.
"""
let r = _notify.tab(_edit.clone())

match r.size()
| 0 => None
| 1 =>
try
_edit = r(0)?.clone()
end_key()
end
else
_out.write("\n")

for completion in r.values() do
_out.print(completion)
end


let my_list = List[String].from(["a"; "b"; "c"])
try my_list.tail()? end // Returns a ListNode[String] containing "c"

fun box tail()
: this->ListNode[A] ref ?

Returns¶

this->ListNode[A] ref ?

prepend_node¶
[Source]
Adds a node to the head of the list.
let my_list = List[String].from(["a"; "b"; "c"])
let new_head = ListNode[String]("0")
my_list.prepend_node(new_head) // ["0", "a"; "b"; "c"]

fun ref prepend_node(
node: ListNode[A] ref)


fun box netlink_dnrtmsg()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_ecryptfs¶
[Source]


value: A)
: A^ ?

Parameters¶

i: USize val
value: A

Returns¶

A^ ?

index¶
[Source]
Gets the i-th node, raising an error if the index is out of bounds.
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.index(0)? end // Returns a ListNode[String] containing "a"

fun box index(


U128 val

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

Returns¶

ULong val

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

Returns¶


state: Bool val

Returns¶

U32 val

set_so_rcvbuf¶
[Source]
Wrapper for the FFI call setsockopt(fd, SOL_SOCKET, SO_RCVBUF, ...)
fun ref set_so_rcvbuf(
bufsize: U32 val)
: U32 val

Parameters¶

bufsize: U32 val

Returns¶


OptionSpec¶
[Source]
OptionSpec describes the specification of a named Option. They have a name,
descr(iption), a short-name, a typ(e), and a default value when they are not
required.
Options can be placed anywhere before or after commands, and can be thought
of as named arguments.
class val OptionSpec

Constructors¶
bool¶
[Source]
Creates an Option with a Bool typed value that can be used like


fun box sctp_str_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_timeouts¶
[Source]


fun box futimesat()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

mkdirat¶
[Source]


# Memory Allocation at Runtime

Pony is a null-free, type-safe language, with no dangling pointers, no buffer overruns, but with a **very fast garbage collector**, so you don't have to worry about explicit memory allocation, if on the heap or stack, if in a threaded actor, or not.


let exe = try env.args(0)? else "fmt_example" end
env.err.print("Usage: " + exe + " NUMBER1 NUMBER2")
end
```
"""

use "collections"

primitive Format
"""
Provides functions for generating formatted strings.

* fmt. Format to use.
* prefix. Prefix to use.
* prec. Precision to use. The exact meaning of this depends on the type,
but is generally the number of characters used for all, or part, of the
string. A value of -1 indicates that the default for the type should be
used.
* width. The minimum number of characters that will be in the produced
string. If necessary the string will be padded with the fill character to


fun box mrt_add_mfc()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mrt_api_config¶
[Source]


fun box f64_unsafe()
: F64 val

Returns¶

F64 val

compare¶
[Source]
fun box compare(
that: I16 val)
: (Less val | Equal val | Greater val)

Parameters¶

that: I16 val

Returns¶


"""
Returns the arg value as a Bool, defaulting to false.
"""
try _value as Bool else false end

fun string(): String =>
"""
Returns the arg value as a String, defaulting to empty.
"""
try _value as String else "" end

fun i64(): I64 =>
"""
Returns the arg value as an I64, defaulting to 0.
"""
try _value as I64 else I64(0) end

fun u64(): U64 =>
"""
Returns the arg value as an U64, defaulting to 0.


F64 val) & Real[A] val)](
a: A)
: I16 val^

Parameters¶

a: A

Returns¶

I16 val^

min_value¶
[Source]
new val min_value()
: I16 val^

Returns¶


fun ref get_so_error(): (U32, U32) =>
"""
Wrapper for the FFI call `getsockopt(fd, SOL_SOCKET, SO_ERROR, ...)`
"""
_OSSocket.get_so_error(_fd)

fun ref get_so_rcvbuf(): (U32, U32) =>
"""
Wrapper for the FFI call `getsockopt(fd, SOL_SOCKET, SO_RCVBUF, ...)`
"""
_OSSocket.get_so_rcvbuf(_fd)

fun ref get_so_sndbuf(): (U32, U32) =>
"""
Wrapper for the FFI call `getsockopt(fd, SOL_SOCKET, SO_SNDBUF, ...)`
"""
_OSSocket.get_so_sndbuf(_fd)


`TCPConnection` is a single example. This Backpressure package exists to allow
a programmer to indicate to the runtime that a given actor is experiencing
pressure and sending messages to it should be adjusted accordingly.

Any actor that needs to be able to tell the runtime to "send me messages
slower" due to external conditions can do so via this package. Additionally,
actors that maintain their own internal queues of any sort, say for buffering,
are also prime candidates for using this package. If an actor's internal
queue grows too large, it can call `Backpressure.apply` to let the runtime know
it is under pressure.


fun box mac_get()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

sem_getvalue¶
[Source]


fun so_detach_filter():I32 => @pony_os_sockopt_option(I32(822))
fun so_domain():I32 => @pony_os_sockopt_option(I32(823))
fun so_dontlinger():I32 => @pony_os_sockopt_option(I32(824))
fun so_dontroute():I32 => @pony_os_sockopt_option(I32(825))
fun so_donttrunc():I32 => @pony_os_sockopt_option(I32(826))
fun so_error():I32 => @pony_os_sockopt_option(I32(827))
fun so_exclusiveaddruse():I32 => @pony_os_sockopt_option(I32(828))
fun so_get_filter():I32 => @pony_os_sockopt_option(I32(829))
fun so_group_id():I32 => @pony_os_sockopt_option(I32(830))
fun so_group_priority():I32 => @pony_os_sockopt_option(I32(831))
fun so_hci_raw_direction():I32 => @pony_os_sockopt_option(I32(832))
fun so_hci_raw_filter():I32 => @pony_os_sockopt_option(I32(833))
fun so_incoming_cpu():I32 => @pony_os_sockopt_option(I32(834))
fun so_keepalive():I32 => @pony_os_sockopt_option(I32(835))
fun so_l2cap_encrypted():I32 => @pony_os_sockopt_option(I32(836))
fun so_l2cap_flush():I32 => @pony_os_sockopt_option(I32(837))
fun so_l2cap_iflow():I32 => @pony_os_sockopt_option(I32(838))
fun so_l2cap_imtu():I32 => @pony_os_sockopt_option(I32(839))
fun so_l2cap_oflow():I32 => @pony_os_sockopt_option(I32(840))
fun so_l2cap_omtu():I32 => @pony_os_sockopt_option(I32(841))


fun box ip_fw_get()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_fw_nat_del¶
[Source]


fun box shr(
y: U16 val)
: U16 val

Parameters¶

y: U16 val

Returns¶

U16 val

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

Parameters¶


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

Parameters¶

y: I8 val

Returns¶

I8 val

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

Parameters¶


732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751


Returns an iterator over the elements of the list.
"""
object is Iterator[val->A]
var _list: List[A] box = this
fun has_next(): Bool => _list isnt Nil[A]
fun ref next(): val->A! ? => (_list = _list.tail()?).head()?
end

fun is_empty(): Bool =>
"""
Returns a Bool indicating if the list is empty.
"""
false

fun is_non_empty(): Bool =>
"""
Returns a Bool indicating if the list is non-empty.
"""
true


fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

I8 val

i16_unsafe¶
[Source]


be dispose() =>
"""
Terminate child and close down everything.
"""
match _child
| let never_started: _ProcessNone =>
// We never started a child process so do not do any disposal
// If we do, some weirdness can happen with dispose getting called
// on the notifier which is not supposed to happen if we never started
// a child (or haven't started one yet).
return
else
Backpressure.release(_backpressure_auth)
_child.kill()
_close()
end

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


## Example proxy implementation

```pony
actor Main
new create(env: Env) =>
MyClient.create(
"example.com", // we actually want to connect to this host
"80",
ExampleProxy.create("proxy.example.com", "80")) // we connect via this proxy

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

class ExampleProxy is Proxy
let _proxy_host: String


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


y: USize val

Returns¶

USize val

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

Parameters¶

y: USize val

Returns¶


fun box ipproto_idpr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_igmp¶
[Source]


Parameters¶

value: (A | None val)

Returns¶

Iter[A] ref^

chain¶
[Source]
Take an iterator of iterators and return an Iter containing the
items of the first one, then the second one, and so on.
Example¶
let xs = [as I64: 1; 2].values()
let ys = [as I64: 3; 4].values()

Iter[I64].chain([xs; ys].values())

1 2 3 4


ctrl: Bool val = false
alt: Bool val = false
shift: Bool val = false

Returns¶

None val

home¶
[Source]
Beginning of the line.
fun ref home(
ctrl: Bool val = false,
alt: Bool val = false,
shift: Bool val = false)
: None val

Parameters¶


Bool val

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

Parameters¶

that: Flags[A, B] box

Returns¶

(Less val | Equal val | Greater val)

ne¶
[Source]


(I128 val , Bool val)

modc¶
[Source]
fun box modc(
y: I128 val)
: (I128 val , Bool val)

Parameters¶

y: I128 val

Returns¶

(I128 val , Bool val)

add_partial¶
[Source]


precision (ie a normalised number).
fun tag min_exp2()
: I16 val

Returns¶

I16 val

min_exp10¶
[Source]
Minimum exponent value such that (10^exponent) - 1 is representable at full
precision (ie a normalised number).
fun tag min_exp10()
: I16 val

Returns¶

I16 val


new val create()
: FormatBinaryBare val^

Returns¶

FormatBinaryBare val^

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

Parameters¶

that: FormatBinaryBare val

Returns¶


data: ByteSeqIter val)

Parameters¶

data: ByteSeqIter val

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

Parameters¶

data: ByteSeqIter val

flush¶
[Source]


: I128 val

Returns¶

I128 val

u128_unsafe¶
[Source]
Unsafe operation.
If the value doesn't fit in the destination type, the result is undefined.
fun box u128_unsafe()
: U128 val

Returns¶

U128 val

add_unsafe¶


fun box ip_recvrssbucketid()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_recvttl¶
[Source]


FileRemove¶
[Source]
primitive val FileRemove

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

Returns¶

FileRemove val^


fun box op_or(
y: I32 val)
: I32 val

Parameters¶

y: I32 val

Returns¶

I32 val

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

Parameters¶


## Continue

Sometimes you want to stop part-way through one loop iteration and move onto the next. Like other languages, Pony uses the `continue` keyword for this.

`continue` stops executing the current iteration of the innermost loop it's in and evaluates the condition ready for the next iteration.

If `continue` is executed during the last iteration of the loop then we have no value to return from the loop. In this case, we use the loop's `else` expression to get a value. As with the `if` expression, if no `else` expression is provided, `None` is returned.

__Can I continue an outer, nested loop like the Java labeled continue?__ No, Pony does not support that. If you need to continue an outer loop you should probably refactor your code.


_connect_count = 0
_fd = fd
ifdef not windows then
_event = @pony_asio_event_create(this, fd,
AsioEvent.read_write_oneshot(), 0, true)
else
_event = @pony_asio_event_create(this, fd,
AsioEvent.read_write(), 0, true)
end
_connected = true
ifdef not windows then
@pony_asio_event_set_writeable(_event, true)
end
_writeable = true
_read_buf = recover Array[U8] .> undefined(read_buffer_size) end
_read_buffer_size = read_buffer_size
_yield_after_reading = yield_after_reading
_yield_after_writing = yield_after_writing

_notify.accepted(this)


"""
Create a generator for `SetIs` filled with values
of the given generator `gen`.
The returned `SetIs` will have a size up to `max`,
but tend to have fewer entries
depending on the source generator `gen`.

E.g. if the given generator is for `U8` values and `max` is set to 1024
the set will only ever be of size 256 max.

Also for efficiency purposes and to not loop forever,
this generator will only try to add at most `max` values to the set.
If there are duplicates, the set won't grow.
"""
// TODO: how to remove code duplications
Generator[SetIs[T]](
object is GenObj[SetIs[T]]
fun generate(rnd: Randomness): GenerateResult[SetIs[T]] =>
let size = rnd.usize(0, max)


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


I64 val

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

Parameters¶

y: I64 val

Returns¶

I64 val

div_unsafe¶
[Source]


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


The caller is responsible for the correct size and byte contents of
the `option` array for the requested `level` and `option_name`,
including using the appropriate CPU endian byte order.

This function returns `0` on success, else the value of `errno` on
failure.

Usage example:

```pony
// listening() is a callback function for class UDPNotify
fun ref listening(sock: UDPSocket ref) =>
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 sock.setsockopt(OSSockOpt.sol_socket(), OSSockOpt.so_rcvbuf(), sbytes)


If the ListNode is not contained within a List the append will fail.
fun ref append(
that: ListNode[A] ref)
: Bool val

Parameters¶

that: ListNode[A] ref

Returns¶

Bool val

remove¶
[Source]
Remove a node from a list.
The ListNode must be contained within a List for this to succeed.
fun ref remove()
: None val


that: FileRename val

Returns¶

Bool val

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

Parameters¶

that: FileRename val

Returns¶


fun box shr(
y: U8 val)
: U8 val

Parameters¶

y: U8 val

Returns¶

U8 val

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

Parameters¶


stdin: _Pipe,
stdout: _Pipe,
stderr: _Pipe)
=>
ifdef windows then
let wdir_ptr =
match wdir
| let wdir_fp: FilePath => wdir_fp.path.cstring()
| None => Pointer[U8] // NULL -> use parent directory
end
var error_code: U32 = 0
var error_message = Pointer[U8]
h_process = @ponyint_win_process_create(
path.cstring(),
_make_cmdline(args).cstring(),
_make_environ(vars).cpointer(),
wdir_ptr,
stdin.far_fd, stdout.far_fd, stderr.far_fd,
addressof error_code, addressof error_message)
process_error =


## Constructors

Struct constructors, like class constructors, have names. Everything you previously learned about Pony class constructors applies to struct constructors.

```pony
struct Pointer[A]
"""
A Pointer[A] is a raw memory pointer. It has no descriptor and thus can't be
included in a union or intersection, or be a subtype of any interface. Most
functions on a Pointer[A] are private to maintain memory safety.
"""
new create() =>
"""
A null pointer.
"""
compile_intrinsic

new _alloc(len: USize) =>
"""
Space for len instances of A.


fun box local_peercred()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

local_peereuuid¶
[Source]


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


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


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


y: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

eq¶
[Source]


Format¶
[Source]
Provides functions for generating formatted strings.

fmt. Format to use.
prefix. Prefix to use.
prec. Precision to use. The exact meaning of this depends on the type,
but is generally the number of characters used for all, or part, of the
string. A value of -1 indicates that the default for the type should be
used.
width. The minimum number of characters that will be in the produced
string. If necessary the string will be padded with the fill character to
make it long enough.


Iterator[(this->String box | this->Array[U8 val] box)] ref


y: U16 val

Returns¶

U16 val ?

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

Parameters¶

y: U16 val

Returns¶


F64 val) & Real[A] val)](
a: A)
: ISize val^

Parameters¶

a: A

Returns¶

ISize val^

min_value¶
[Source]
new val min_value()
: ISize val^

Returns¶


"""
Iterate through the values of the iterator without a for loop. The
function `on_error` will be called if the iterator's `has_next` method
returns true but its `next` method throws an error.


fun ipv6_priority_11():I32 => @pony_os_sockopt_option(I32(162))
fun ipv6_priority_12():I32 => @pony_os_sockopt_option(I32(163))
fun ipv6_priority_13():I32 => @pony_os_sockopt_option(I32(164))
fun ipv6_priority_14():I32 => @pony_os_sockopt_option(I32(165))
fun ipv6_priority_15():I32 => @pony_os_sockopt_option(I32(166))
fun ipv6_priority_8():I32 => @pony_os_sockopt_option(I32(167))
fun ipv6_priority_9():I32 => @pony_os_sockopt_option(I32(168))
fun ipv6_priority_bulk():I32 => @pony_os_sockopt_option(I32(169))
fun ipv6_priority_control():I32 => @pony_os_sockopt_option(I32(170))
fun ipv6_priority_filler():I32 => @pony_os_sockopt_option(I32(171))
fun ipv6_priority_interactive():I32 => @pony_os_sockopt_option(I32(172))
fun ipv6_priority_reserved1():I32 => @pony_os_sockopt_option(I32(173))
fun ipv6_priority_reserved2():I32 => @pony_os_sockopt_option(I32(174))
fun ipv6_priority_unattended():I32 => @pony_os_sockopt_option(I32(175))
fun ipv6_priority_uncharacterized():I32 => @pony_os_sockopt_option(I32(176))
fun ipv6_recvdstopts():I32 => @pony_os_sockopt_option(I32(177))
fun ipv6_recverr():I32 => @pony_os_sockopt_option(I32(178))
fun ipv6_recvhoplimit():I32 => @pony_os_sockopt_option(I32(179))
fun ipv6_recvhopopts():I32 => @pony_os_sockopt_option(I32(180))
fun ipv6_recvorigdstaddr():I32 => @pony_os_sockopt_option(I32(181))


## Finalisers

Finalisers are special functions. They are named `_final`, take no parameters and have a receiver reference capability of `box`. In other words, the definition of a finaliser must be `fun _final()`.

The finaliser of an object is called before the object is collected by the GC. Functions may still be called on an object after its finalisation, but only from within another finaliser. Messages cannot be sent from within a finaliser.

Finalisers are usually used to clean up resources allocated in C code, like file handles, network sockets, etc.


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


fun box rose_network_congestion()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rose_number_busy¶
[Source]


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

Parameters¶

f: {(B, val->A): B^}[A, B] box
acc: B

Returns¶

B


PosixDate¶
[Source]
Represents a proleptic Gregorian date and time, without specifying a
time zone. The day of month, month, day of week, and day of year are all
indexed from 1, i.e. January is 1, Monday is 1.
class ref PosixDate

Constructors¶
create¶
[Source]
Create a date from a POSIX time. Negative arguments will be changed to zero.
new ref create(
seconds: I64 val = 0,


Bool val

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

Parameters¶

that: FormatBinaryBare val

Returns¶

Bool val


fun box usize_unsafe()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64_unsafe¶
[Source]


To avoid this problem the use command allows you to specify an alias. If you do this then only that alias is put into your namespace. The types from the used package can then be accessed using this alias as a qualifier. Our example now becomes:

```pony
// In package A
class Foo

// In package B
class Foo

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

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

If you prefer you can give an alias to only one of the packages. `Foo` will then still be added to your namespace referring to the unaliased package:


[Source]
Creates an iterator for the given map.
new ref create(
map: M)
: MapValues[K, V, H, M] ref^

Parameters¶

map: M

Returns¶

MapValues[K, V, H, M] ref^

Public Functions¶
has_next¶
[Source]
True if it believes there are remaining entries. May not be right if values
were added or removed from the map.


fun box ipv6_priority_interactive()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_priority_reserved2¶
[Source]


fun box tipc_withdrawn()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ttcp_client_snd_wnd¶
[Source]


None val

valid¶
[Source]
Returns true if the file is currently open.
fun box valid()
: Bool val

Returns¶

Bool val

read¶
[Source]
Returns up to len bytes.
fun ref read(
len: USize val)


_esc_num = 0
_esc_mod = 0


Public Functions¶
next¶
[Source]
A random integer in [0, 2^64)
fun ref next()
: U64 val

Returns¶

U64 val

has_next¶
fun tag has_next()
: Bool val

Returns¶

Bool val


U16 val

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

Parameters¶

y: U16 val

Returns¶

(U16 val , U16 val)

rem_unsafe¶
[Source]


Returns¶

Bool val

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

Parameters¶

atime: (I64 val , I64 val)
mtime: (I64 val , I64 val)

Returns¶


Here's a few examples of the space allocated when initialising an Array with
various number of elements:

size
space

0
0

1
8

8


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


None val

remove¶
[Source]
Remove n elements from the array, beginning at index i.
fun ref remove(
i: USize val,
n: USize val)
: None val

Parameters¶

i: USize val
n: USize val

Returns¶

None val


112
113
114
115
116
117
118
119
120
121
122use @cap_enter[I32]() if freebsd or "capsicum"

primitive Cap
"""
The Capsicum rights.
"""
fun enter(): Bool =>
"""
This places the current process into capability mode, a mode of execution
in which processes may only issue system calls operating on file


next_index¶
[Source]
Given an index, return the next index that has a populated value. Raise an
error if there is no next populated index.
fun box next_index(
prev: USize val = call)
: USize val ?

Parameters¶

prev: USize val = call

Returns¶

USize val ?

index¶


"(" + _spec.deb_string() + "=)" + _value.string()

class val SyntaxError
"""
SyntaxError summarizes a syntax error in a given parsed command line.
"""
let _token: String
let _msg: String

new val create(token': String, msg': String) =>
_token = token'
_msg = msg'

fun token(): String => _token

fun string(): String => "Error: " + _msg + " at: '" + _token + "'"


fun box ipv6_fl_s_none()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_fl_s_user¶
[Source]


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


[Source]
fun ref i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶


[Source]
Creates a command help for a specific command that can print a detailed
help message.
fun box for_command(
cs: CommandSpec box,
argv: Array[String val] box)
: (CommandHelp box | SyntaxError val)

Parameters¶

cs: CommandSpec box
argv: Array[String val] box

Returns¶

(CommandHelp box | SyntaxError val)

eq¶
[Source]


| Operator | Method | Description                                   |
| -------- | ------ | --------------------------------------------- |
| `+`      | `add()`  | wrap around on over-/underflow                |
| `-`      | `sub()`  | wrap around on over-/underflow                |
| `*`      | `mul()`  | wrap around on over-/underflow                |
| `/`      | `div()`  | `x / 0 = 0`                                   |
| `%`      | `rem()`  | `x % 0 = 0`                                   |
| `%%`     | `mod()`  | `x %% 0 = 0`                                  |
| `-`      | `neg()`  | wrap around on over-/underflow                |
| `>>`     | `shr()`  | filled with zeros, so `x >> 1 == x/2` is true |
| `<<`     | `shl()`  | filled with zeros, so `x << 1 == x*2` is true |

---


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


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

Parameters¶

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

Returns¶

None val

skip¶
[Source]
Skip n bytes.
fun ref skip(
n: USize val)
: None val ?

Parameters¶


Bool val

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

Parameters¶

that: HashEq[A] val

Returns¶

Bool val


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


Returns¶

B

every¶
[Source]
Returns true if every element satisfies the provided predicate, false
otherwise.
fun val every(
f: {(val->A): Bool}[A] box)
: Bool val

Parameters¶

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

Returns¶


Returns¶

U8 val ?

update_offset¶
[Source]
Changes a byte in the string, returning the previous byte at that offset.
Raise an error if the offset is out of bounds.
fun ref update_offset(
offset: ISize val,
value: U8 val)
: U8 val ?

Parameters¶

offset: ISize val
value: U8 val

Returns¶


 Time Package

The Time Package provides classes and methods for timing operations,
dealing with dates and times, and scheduling tasks.
"""

use "lib:rt" if linux
use @"internal.x86.cpuid"[(I32, I32, I32, I32)](eax: I32)
use @"internal.x86.rdtscp"[U64](aux: Pointer[I32])
use @"llvm.x86.rdtsc"[U64]()
use @"llvm.readcyclecounter"[U64]()
use @time[I64](tloc: Pointer[None])
use @clock_gettime[I32](clock: U32, ts: Pointer[(I64, I64)])
if lp64 and (linux or bsd)
use @clock_gettime[I32](clock: U32, ts: Pointer[(I32, I32)])
if ilp32 and (linux or bsd)
use @clock_gettime_nsec_np[U64](clock: U32) if osx
use @gettimeofday[I32](tp: Pointer[(I64, I64)], tzp: Pointer[None])
if osx
use @GetSystemTimeAsFileTime[None](times_as_file_time: Pointer[(U32, U32)])


AlignLeft¶
[Source]
primitive val AlignLeft

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

Returns¶

AlignLeft val^


Parameters¶

y: ISize val

Returns¶

(ISize val , Bool val)

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

Parameters¶

y: ISize val

Returns¶


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


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


"""
@"llvm.cttz.i64"(this, true)

fun bitwidth(): U64 => 64

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

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

fun hash(): USize =>
ifdef ilp32 then
((this >> 32).u32() xor this.u32()).hash()
else
usize().hash()
end

fun addc(y: U64): (U64, Bool) =>
@"llvm.uadd.with.overflow.i64"(this, y)


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


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


fun box tcp_ccalgoopt()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_congestion¶
[Source]


Returns¶

I32 val ?

peek_u64_be¶
[Source]
Peek at a big-endian U64.
fun box peek_u64_be(
offset: USize val = 0)
: U64 val ?

Parameters¶

offset: USize val = 0

Returns¶

U64 val ?


fun box ipproto_adfs()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_ahip¶
[Source]


fun tag select(p: Promise[A]): Promise[(A, Promise[A])] =>
"""
Return a promise that is fulfilled when either promise is fulfilled,
resulting in a tuple of its value and the other promise.
"""
let p' = Promise[(A, Promise[A])]

let s =
object tag
var _complete: Bool = false
let _p: Promise[(A, Promise[A])] = p'

be apply(a: A, p: Promise[A]) =>
if not _complete then
_p((a, p))
_complete = true
end
end

next[None]({(a) => s(a, p) })


1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051


Parameters¶

y: F64 val

Returns¶

F64 val

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

Returns¶

F64 val


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


float[A: ((F32 val | F64 val) & FloatingPoint[A])]¶
[Source]
fun box float[A: ((F32 val | F64 val) & FloatingPoint[A])](
x: A,
fmt: (FormatDefault val | FormatExp val | FormatExpLarge val |
FormatFix val | FormatFixLarge val | FormatGeneral val |
FormatGeneralLarge val) = reference,
prefix: (PrefixDefault val | PrefixSpace val | PrefixSign val) = reference,
prec: USize val = 6,
width: USize val = 0,
align: (AlignLeft val | AlignRight val | AlignCenter val) = reference,
fill: U32 val = 32)
: String iso^

Parameters¶

x: A
fmt: (FormatDefault val | FormatExp val | FormatExpLarge val |


"""
Create a generator for USize values.
"""
let that = this
Generator[USize](
object is GenObj[USize]
fun generate(rnd: Randomness): GenerateResult[USize] =>
rnd.usize(min, max)

fun shrink(u: USize): ValueAndShrink[USize] =>
that._int_shrink[USize](consume u, min)
end)

fun ulong(
min: ULong = ULong.min_value(),
max: ULong = ULong.max_value())
: Generator[ULong]
=>
"""
Create a generator for ULong values.


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


: InputSerialisedAuth val^

Parameters¶

auth: AmbientAuth val

Returns¶

InputSerialisedAuth val^

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

Parameters¶


Returns¶

String val

descr¶
[Source]
Returns the description for this arg.
fun box descr()
: String val

Returns¶

String val

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


Public Functions¶
value¶
[Source]
fun box value()
: U32 val

Returns¶

U32 val

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

Parameters¶


qty is zero, the call can contain any amount of data.
fun ref expect(
qty: USize val = 0)
: None val

Parameters¶

qty: USize val = 0

Returns¶

None val


if n == nth then
return i
end

n = n + 1
end
until (i = i - 1) == 0
end
end

error

fun clone(): Array[this->A!]^ =>
"""
Clone the array.
The new array contains references to the same elements that the old array
contains, the elements themselves are not cloned.
"""
let out = Array[this->A!](_size)
_ptr._copy_to(out._ptr, _size)


ILong val

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

Parameters¶

y: ILong val

Returns¶

Bool val

ne¶


that: FileSync val

Returns¶

Bool val

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

Parameters¶

that: FileSync val

Returns¶


"""
(let dir, let pre) = Path.split(prefix)
let parent: FilePath = match base
| let base': FileAuth => FilePath(base', dir)
| let base': FilePath => FilePath.from(base', dir)?
end

if not parent.mkdir() then
error
end

var temp = FilePath.from(parent, pre + Path.random())?

while not temp.mkdir(true) do
temp = FilePath.from(parent, pre + Path.random())?
end

caps.union(caps')
caps.intersect(temp.caps)
path = temp.path


alt: Bool val
shift: Bool val

Returns¶

None val

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

Parameters¶

ctrl: Bool val
alt: Bool val


fun ref apply(c: AsyncBenchContinue) =>
c.complete()


wrap: TCPConnectionNotify iso

Returns¶

TCPConnectionNotify iso^


# Identity equality

Identity equality checks in Pony are done via the `is` keyword. `is` verifies that the two items are the same.

```pony
if None is None then
// TRUE!
// There is only 1 None so the identity is the same
end

let a = Foo("hi")
let b = Foo("hi")

if a is b then
// NOPE. THIS IS FALSE
end

let c = a
if a is c then
// YUP! TRUE!


fun box usize()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64¶
[Source]


that: Fact val)
: Bool val

Parameters¶

that: Fact val

Returns¶

Bool val


fun box tcp_defer_accept()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_fastopen¶
[Source]


ifdef ilp32 then
@"llvm.cttz.i32"(this.u32(), false).usize()
else
@"llvm.cttz.i64"(this.u64(), false).usize()
end

fun clz_unsafe(): USize =>
ifdef ilp32 then
@"llvm.ctlz.i32"(this.u32(), true).usize()
else
@"llvm.ctlz.i64"(this.u64(), true).usize()
end

fun ctz_unsafe(): USize =>
ifdef ilp32 then
@"llvm.cttz.i32"(this.u32(), true).usize()
else
@"llvm.cttz.i64"(this.u64(), true).usize()
end


Parameters¶

f: {(val->A): List[B]}[A, B] box

Returns¶

Nil[B] val

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

Parameters¶

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


y: U32 val

Returns¶

U32 val

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

Parameters¶

y: U32 val

Returns¶


412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429use "time"

actor Promise[A: Any #share]


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


fun box scm_wifi_status()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_adaptation_layer¶
[Source]


fun box i16()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64¶
[Source]


F64 val

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

Returns¶

I8 val

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

Returns¶


U128 val

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

Returns¶

ULong val

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

Returns¶


fun box ndrv_demuxtype_ethertype()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ndrv_demuxtype_snap¶
[Source]


StartProcessAuth¶
[Source]
primitive val StartProcessAuth

Constructors¶
create¶
[Source]
new val create(
from: AmbientAuth val)
: StartProcessAuth val^

Parameters¶


FileLookup¶
[Source]
primitive val FileLookup

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

Returns¶

FileLookup val^


32
33
34
35use @getpid[I32]()
use @kill[I32](pid_t: I32, sig: U32)
use @raise[I32](sig: U32)

interface SignalNotify
"""
Notifications for a signal.
"""
fun ref apply(count: U32): Bool =>
"""
Called with the the number of times the signal has fired since this was
last called. Return false to stop listening for the signal.
"""
true

fun ref dispose() =>
"""


fun box rds_trans_iwarp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_trans_tcp¶
[Source]


ILong val

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

Returns¶

ISize val

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

Returns¶


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


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


fun box ipproto_prm()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_pvp¶
[Source]


--opt or -O or --opt=true or -O=true
to yield an option value like
cmd.option("opt").bool() == true.
new val bool(
name': String val,
descr': String val = "",
short': (U8 val | None val) = reference,
default': (Bool val | None val) = reference)
: OptionSpec val^

Parameters¶

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

Returns¶

OptionSpec val^


# An `iso` specific class

```pony
// Note - this won't compile
class Foo
var _c: String iso

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

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

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

actor Main
new create(env:Env) =>
let a = Foo(recover iso String end)
env.out.print(a.get().string())
a.set(recover iso String end)
env.out.print(a.get().string())


A random integer in [0, 2^8)
fun ref u8()
: U8 val

Returns¶

U8 val

u16¶
[Source]
A random integer in [0, 2^16)
fun ref u16()
: U16 val

Returns¶

U16 val


[Source]
UNIX-style user ID of the owning group of filepath.

let size: USize val¶
[Source]
Total size of filepath in bytes.
In case of a symlink this is the size of the target, not the symlink itself.

let access_time: (I64 val , I64 val)¶
[Source]
Time of last access as a tuple of seconds and nanoseconds since the epoch:
(let a_secs: I64, let a_nanos: I64) = file_info.access_time

let modified_time: (I64 val , I64 val)¶
[Source]
Time of last modification as tuple of seconds and nanoseconds since the epoch:
(let m_secs: I64, let m_nanos: I64) = file_info.modified_time


"""
_set = set

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

fun ref next(): S->A ? =>
"""
Returns the next value, or raises an error if there isn't one. If values
are added during iteration, this may not return all values.
"""
_i = _set.next_index(_i)?
_count = _count + 1
_set.index(_i)?


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


# Arithmetic

Arithmetic is about the stuff you learn to do with numbers in primary school: Addition, Subtraction, Multiplication, Division and so on. Piece of cake. We all know that stuff. We nonetheless want to spend a whole section on this topic, because when it comes to computers the devil is in the details.

As introduced in [Primitives](/types/primitives.md#built-in-primitive-types) numeric types in Pony are represented as a special kind of primitive that maps to machine words. Both integer types and floating point types support a rich set of arithmetic and bit-level operations. These are expressed as [Infix Operators](/expressions/ops.md#infix-operators) that are implemented as plain functions on the numeric primitive types.

Pony focuses on two goals, performance and safety. From time to time, these two goals collide. This is true especially for arithmetic on integers and floating point numbers. Safe code should check for overflow, division by zero and other error conditions on each operation where it can happen. Pony tries to enforce as many safety invariants at compile time as it possibly can, but checks on arithmetic operations can only happen at runtime. Code focused on performance should execute integer arithmetic as fast and with as few CPU cycles as possible. Checking for overflow is expensive, doing plain dangerous arithmetic that is possibly subject to overflow is cheap.

Pony provides different ways of doing arithmetic to give programmers the freedom to chose which operation suits best for them, the safe but slower operation or the fast one, because performance is crucial for the use case.


fun box so_vm_sockets_connect_timeout()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_vm_sockets_peer_host_vm_id¶
[Source]


fun required(): Bool =>
"""
Returns true iff this option is required to be present in the command line.
"""
_required

// Other than bools, all options require args.
fun _requires_arg(): Bool =>
match _typ
| let _: _BoolType => false
else
true
end

// Used for bool options to get the true arg when option is present w/o arg
fun _default_arg(): _Value =>
match _typ
| let _: _BoolType => true
else
false


632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651


"""
_distance_of('\n')?


fun box tipc_err_no_name()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_err_no_port¶
[Source]


let bit = bits()
let high = (bit >> 32).u32()
let ex = ((high and 0x7FF00000) >> 20) - 1023

if ex < 0 then
return 0
end

let s = ((high and 0x80000000) >> 31).i128()
var r = ((bit and 0x000FFFFFFFFFFFFF) or 0x0010000000000000).i128()
let ex' = ex.u128()

if ex' > 52 then
r = r << (ex' - 52)
else
r = r >> (52 - ex')
end

(r xor s) - s


fun box div_unsafe(
y: ULong val)
: ULong val

Parameters¶

y: ULong val

Returns¶

ULong val

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

Parameters¶


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


## Open world typing

We've covered a couple ways that traits can be better than interfaces, let's close with the reason for why we say, unless you have a reason to, you should use `interface` instead of `trait`. Interfaces are incredibly flexible. Because traits only provide nominal typing, a concrete type can only be in a category if it was declared as such by the programmer who wrote the concrete type. Interfaces allow you to create your own categorizations on the fly, as you need them, to group existing concrete types together however you need to.

Here's a contrived example:

```pony
interface Compactable
fun ref compact()
fun size(): USize

class Compactor
"""
Compacts data structures when their size crosses a threshold
"""
let _threshold: USize

new create(threshold: USize) =>
_threshold = threshold


Parameters¶

n: N

Returns¶

N

int[optional N: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Real[N] val)]¶
[Source]
A random integer in [0, n)
Uses fixed-point inversion if platform supports native 128 bit operations
otherwise uses floating-point multiplication.
fun ref int[optional N: ((U8 val | U16 val | U32 val |
U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N


will be omitted from the result.
fun box base(
path: String val,
with_ext: Bool val = true)
: String val

Parameters¶

path: String val
with_ext: Bool val = true

Returns¶

String val

dir¶
[Source]
Return a cleaned path before the last separator, or the whole path if there
is no separator.


if consumed(i)? then continue end
if e == a then
consumed.update(i, true)?
found = true
break
end
end
if not found then
missing.push(e)
end
end

let extra = Array[box->A]
for (i, c) in consumed.pairs() do
if not c then extra.push(actual(i)?) end
end

if (extra.size() != 0) or (missing.size() != 0) then
fail(
_format_loc(loc) + "Assert EQ_UNORDERED failed. " + msg


y: USize val

Returns¶

USize val ?

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

Parameters¶

y: USize val

Returns¶


FormatFixLarge¶
[Source]
primitive val FormatFixLarge is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


fun box sctp_packet_dropped()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_packet_truncated¶
[Source]


(I32 val , Bool val)

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

Parameters¶

y: I32 val

Returns¶

(I32 val , Bool val)

mulc¶
[Source]


fn: {(T1, T2): T3^}[T1, T2, T3] ref

Returns¶

Generator[T3] box

map3[T1: T1, T2: T2, T3: T3, T4: T4]¶
[Source]
Convenience combinator for mapping 3 generators into 1.
fun box map3[T1: T1, T2: T2, T3: T3, T4: T4](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
fn: {(T1, T2, T3): T4^}[T1, T2, T3, T4] ref)
: Generator[T4] box

Parameters¶

gen1: Generator[T1] box


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


new val i64(name': String,
descr': String = "",
short': (U8 | None) = None,
default': (I64 | None) = None)
=>
"""
Creates an Option with an I64 typed value that can be used like
`--count=42 -C=42`
to yield an option value like
`cmd.option("count").i64() == I64(42)`.
"""
_name = name'
_descr = descr'
_short = short'
(_typ, _default, _required) = _init(_I64Type, default')

new val u64(name': String,
descr': String = "",
short': (U8 | None) = None,
default': (U64 | None) = None)


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


fun box dso_cork()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dso_info¶
[Source]