12
13
14
15
16
17
18
19
20
21
22
23
24
25primitive Nanos
"""
Collection of utility functions for converting various durations of time
to nanoseconds, for passing to other functions in the time package.
"""
fun from_seconds(t: U64): U64 =>
t * 1_000_000_000


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


fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

I8 val

i16_unsafe¶
[Source]


32
33
34
35
36
37interface TCPListenNotify
"""
Notifications for TCP listeners.

For an example of using this class, please see the documentation for the
`TCPListener` actor.
"""
fun ref listening(listen: TCPListener ref) =>
"""
Called when the listener has been bound to an address.
"""
None

fun ref not_listening(listen: TCPListener ref)
"""


U128 val

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

Returns¶

ULong val

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

Returns¶


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


# Capability Subtyping


else
err
end

primitive OpenFile
"""
Open a File for read only.
"""
fun apply(from: FilePath): (File | FileErrNo) =>
let file = File.open(from)
let err = file.errno()

match err
| FileOK => file
else
err
end

class File
"""


from_micros_f¶
[Source]
fun box from_micros_f(
t: F64 val)
: U64 val

Parameters¶

t: F64 val

Returns¶

U64 val

from_wall_clock¶
[Source]
fun box from_wall_clock(
wall: (I64 val , I64 val))
: U64 val


if h_process == 0 then
match error_code
| _ERRORBADEXEFORMAT() => ProcessError(ExecveError)
| _ERRORDIRECTORY() =>
let wdirpath =
match wdir
| let wdir_fp: FilePath => wdir_fp.path
| None => "?"
end
ProcessError(ChdirError, "Failed to change directory to "
+ wdirpath)
else
let message = String.from_cstring(error_message)
ProcessError(ForkError, recover message.clone() end)
end
end
else
compile_error "unsupported platform"
end


fun box seek_tell()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

pread¶
[Source]


fun box sctp_frag_level_1()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_from_middle_box¶
[Source]


Implements¶

Seq[A] ref

Constructors¶
create¶
[Source]
Create an array with zero elements, but space for len elements.
new ref create(
len: USize val = 0)
: Array[A] ref^

Parameters¶

len: USize val = 0

Returns¶


registrar.pony

1
2
3
4
5
6
7
8
9
10
11


fun sctp_ecn_cwr():I32 => @pony_os_sockopt_option(I32(602))
fun sctp_ecn_echo():I32 => @pony_os_sockopt_option(I32(603))
fun sctp_ecn_supported():I32 => @pony_os_sockopt_option(I32(604))
fun sctp_enable_change_assoc_req():I32 => @pony_os_sockopt_option(I32(605))
fun sctp_enable_reset_assoc_req():I32 => @pony_os_sockopt_option(I32(606))
fun sctp_enable_reset_stream_req():I32 => @pony_os_sockopt_option(I32(607))
fun sctp_enable_stream_reset():I32 => @pony_os_sockopt_option(I32(608))
fun sctp_enable_value_mask():I32 => @pony_os_sockopt_option(I32(609))
fun sctp_established():I32 => @pony_os_sockopt_option(I32(610))
fun sctp_event():I32 => @pony_os_sockopt_option(I32(611))
fun sctp_events():I32 => @pony_os_sockopt_option(I32(612))
fun sctp_explicit_eor():I32 => @pony_os_sockopt_option(I32(613))
fun sctp_flight_logging_enable():I32 => @pony_os_sockopt_option(I32(614))
fun sctp_forward_cum_tsn():I32 => @pony_os_sockopt_option(I32(615))
fun sctp_fragment_interleave():I32 => @pony_os_sockopt_option(I32(616))
fun sctp_frag_level_0():I32 => @pony_os_sockopt_option(I32(617))
fun sctp_frag_level_1():I32 => @pony_os_sockopt_option(I32(618))
fun sctp_frag_level_2():I32 => @pony_os_sockopt_option(I32(619))
fun sctp_from_middle_box():I32 => @pony_os_sockopt_option(I32(620))
fun sctp_fr_logging_enable():I32 => @pony_os_sockopt_option(I32(621))


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


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

Returns¶

A

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

Parameters¶


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


string.pony

1
2
3
4
5
6
7
8
9
10
11


In addition, there is a string_seq type that accepts string values from the
command line and collects them into a sequence which can then be retrieved as
a ReadSeq[String] using the string_seq() accessor function.
Some specific details:

bool Options: have a default value of 'true' if no value is given. That is,
-f is equivalent to -f=true.

string_seq Options: the option prefix has to be used each time, like:
--file=f1 --file=f2 --file=f3 with the results being collected into
a single sequence.

string_seq Args: there is no way to indicate termination, so a string_seq
Arg should be the last arg for a command, and will consume all remaining
command line arguments.


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


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

Parameters¶

y: I8 val

Returns¶

I8 val

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

Returns¶


tcp_listen_notify.pony

1
2
3
4
5
6
7
8
9
10
11


 Backpressure Package

The Backpressure package allows Pony programmers to participate in Pony's
runtime backpressure system. The goal of the backpressure system is to prevent
an actor's mailbox from growing at an unbounded rate.

At a high level, the runtime backpressure system works by adjusting the
scheduling of actors. When an actor becomes overloaded, the Pony runtime will
deprioritize scheduling the actors that are sending to it. This change in
scheduling allows the overloaded actor to catch up.

The Pony runtime can detect overloading based on message queue size. However,
the overloading of some types of actors is harder to detect. Let's take the
case of actors like `TCPConnection`.

`TCPConnection` manages a socket for sending data to and receiving data from
another process. TCP connections can experience backpressure from outside
our Pony program that prevents them from sending. There's no way for the Pony
runtime to detect this, so intervention by the programmer is needed.


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


# We'll see structs again

Structs play an important role in Pony's interactions with code written using C. We'll see them again in [C-FFI section](/c-ffi/index.md) of the tutorial. We probably won't see too much about structs until then.


Returns¶

A^ ?

truncate¶
[Source]
Truncate an array to the given length, discarding excess elements. If the
array is already smaller than len, do nothing.
fun ref truncate(
len: USize val)
: None val

Parameters¶

len: USize val

Returns¶


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


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


1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691


"""
while (@dup2(oldfd, newfd) < 0) do
if @pony_os_errno() == _EINTR() then
continue
else
@_exit(I32(-1))
end
end

fun kill() =>
"""
Terminate the process, first trying SIGTERM and if that fails, try SIGKILL.
"""
if pid > 0 then
// Try a graceful termination
if @kill(pid, Sig.term()) < 0 then
match @pony_os_errno()
| _EINVAL() => None // Invalid argument, shouldn't happen but
// tryinng SIGKILL isn't likely to help.
| _ESRCH() => None  // No such process, child has terminated


+ my_list.size().string() + ".") // 1

// Get the first element of our List
try env.out.print("The first (index 0) node has the value: "
+ my_list.index(0)?()?.string()) end // A single String

// Create a second List from a single String literal
let my_second_list = List[String].unit("Another String")

// Append the second List to the first
my_list.append_list(my_second_list)
env.out.print("A list created by appending our second single-node list onto our first has size: "
+ my_list.size().string()) // 2
env.out.print("The List nodes of our first list are now:")
for n in my_list.values() do
env.out.print("\t" + n.string())
end
// NOTE: this _moves_ the elements so second_list consequently ends up empty
env.out.print("Append *moves* the nodes from the second list so that now has "
+ my_second_list.size().string() + " nodes.") // 0


AsioEventNotify tag

Implements¶

AsioEventNotify tag

Constructors¶
create¶
[Source]
Listens for both IPv4 and IPv6 connections.
new tag create(
auth: TCPListenAuth val,
notify: TCPListenNotify iso,
host: String val = "",
service: String val = "0",
limit: USize val = 0,
read_buffer_size: USize val = 16384,
yield_after_reading: USize val = 16384,
yield_after_writing: USize val = 16384)


ifdef native128 then
this % y
else
(let q, let r) = divrem(y)
r
end

fun mul_unsafe(y: U128): U128 =>
"""
Unsafe operation.
If the operation overflows, the result is undefined.
"""
ifdef native128 then
this *~ y
else
this * y
end

fun divrem_unsafe(y: U128): (U128, U128) =>
"""


# Sugar

Pony allows you to omit certain small details from your code and will put them back in for you. This is done to help make your code less cluttered and more readable. Using sugar is entirely optional, you can always write out the full version if you prefer.


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

Returns¶

Generator[S] box

array_of[T: T]¶
[Source]
fun box array_of[T: T](
gen: Generator[T] box,
min: USize val = 0,
max: USize val = 100)
: Generator[Array[T] ref] box

Parameters¶


Copy len elements from src(src_idx) to this(dst_idx).
Only works for Array[U8].
"""
reserve(dst_idx + len)
src._ptr._offset(src_idx)._copy_to(_ptr._convert[U8]()._offset(dst_idx), len)

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

fun copy_to(
dst: Array[this->A!],
src_idx: USize,
dst_idx: USize,
len: USize)
=>
"""
Copy len elements from this(src_idx) to dst(dst_idx).
"""
dst.reserve(dst_idx + len)


let _gen: Generator[T] val
let _helper: TestHelper

new create(gen': Generator[T] val, testHelper: TestHelper) =>
_gen = gen'
_helper = testHelper

fun ref apply(prop: {(T, PropertyHelper) ?} val) ? =>
"""execute"""
Property1UnitTest[T](
object iso is Property1[T]
fun name(): String => ""

fun gen(): Generator[T] => _gen

fun ref property(arg1: T, h: PropertyHelper) ? =>
prop(consume arg1, h)?
end
).apply(_helper)?


# Named arguments

So far, when calling methods we have always given all the arguments in order. This is known as using __positional__ arguments. However, we can also specify the arguments in any order by specifying their names. This is known as using __named__ arguments.

To call a method using named arguments the `where` keyword is used, followed by the named arguments and their values.

```pony
class Coord
var _x: U32
var _y: U32

new create(x: U32 = 0, y: U32 = 0) =>
_x = x
_y = y

class Bar
fun f() =>
var a: Coord = Coord.create(3, 4) // Contains (3, 4)
var b: Coord = Coord.create(where y = 4, x = 3) // Contains (3, 4)
```


[Source]
fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

F32 val


be flush()


F64 val

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

Parameters¶

array: Array[A] ref

Returns¶

None val


Returns¶

Bool val

is_non_empty¶
[Source]
Returns a Bool indicating if the list is non-empty.
fun box is_non_empty()
: Bool val

Returns¶

Bool val

head¶
[Source]
Returns the head of the list.


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


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


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

Parameters¶

that: DebugErr val

Returns¶

Bool val


fun box icmp_dest_unreach()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_echoreply¶
[Source]


fun box sctp_pktdrop_supported()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pluggable_ss¶
[Source]


writer.u32_be(42)
writer.f32_be(3.14)

let b = recover iso Array[U8] end

for chunk in writer.done().values() do
b.append(chunk)
end

reader.append(consume b)

try
env.out.print(reader.u32_be()?.string()) // prints 42
env.out.print(reader.f32_be()?.string()) // prints 3.14
end

Public Types¶

class Reader
class Writer


fun val get_or_else(k: K, alt: val->V): val->V =>
"""
Get the value associated with provided key if present. Otherwise,
return the provided alternate value.
"""
try
match _root(0, H.hash(k).u32(), k)?
| let v: V => v
else alt
end
else
alt // should not occur
end

fun val contains(k: K): Bool =>
"""
Check whether the node contains the provided key.
"""
try _root(0, H.hash(k).u32(), k)? isnt None
else false // should not occur


ULong val

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

Returns¶

ULong val

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

Returns¶


XorOshiro128StarStar¶
[Source]
This is an implementation of xoroshiro128**, as detailed at:
http://xoshiro.di.unimi.it/
This Rand implementation is slightly slower than XorOshiro128Plus
but does not exhibit "mild dependencies in Hamming weights" (the lower four bits might fail linearity tests).
class ref XorOshiro128StarStar is
Random ref

Implements¶

Random ref


fun tcp_keepidle():I32 => @pony_os_sockopt_option(I32(1002))
fun tcp_keepinit():I32 => @pony_os_sockopt_option(I32(1003))
fun tcp_keepintvl():I32 => @pony_os_sockopt_option(I32(1004))
fun tcp_linger2():I32 => @pony_os_sockopt_option(I32(1005))
fun tcp_maxburst():I32 => @pony_os_sockopt_option(I32(1006))
fun tcp_maxhlen():I32 => @pony_os_sockopt_option(I32(1007))
fun tcp_maxolen():I32 => @pony_os_sockopt_option(I32(1008))
fun tcp_maxseg():I32 => @pony_os_sockopt_option(I32(1009))
fun tcp_maxwin():I32 => @pony_os_sockopt_option(I32(1010))
fun tcp_max_sack():I32 => @pony_os_sockopt_option(I32(1011))
fun tcp_max_winshift():I32 => @pony_os_sockopt_option(I32(1012))
fun tcp_md5sig():I32 => @pony_os_sockopt_option(I32(1013))
fun tcp_md5sig_maxkeylen():I32 => @pony_os_sockopt_option(I32(1014))
fun tcp_minmss():I32 => @pony_os_sockopt_option(I32(1015))
fun tcp_mss():I32 => @pony_os_sockopt_option(I32(1016))
fun tcp_mss_default():I32 => @pony_os_sockopt_option(I32(1017))
fun tcp_mss_desired():I32 => @pony_os_sockopt_option(I32(1018))
fun tcp_nodelay():I32 => @pony_os_sockopt_option(I32(1019))
fun tcp_noopt():I32 => @pony_os_sockopt_option(I32(1020))
fun tcp_nopush():I32 => @pony_os_sockopt_option(I32(1021))


USize val

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

Returns¶

USize val

ctz_unsafe¶
[Source]
Unsafe operation.
If this is 0, the result is undefined.


actor Main
new create(env: Env) =>
// create a notifier
let client = ProcessClient(env)
let notifier: ProcessNotify iso = consume client
// define the binary to run
let path = FilePath(FileAuth(env.root), "/bin/cat")
// define the arguments; first arg is always the binary name
let args: Array[String] val = ["cat"]
// define the environment variable for the execution
let vars: Array[String] val = ["HOME=/"; "PATH=/bin"]
// create a ProcessMonitor and spawn the child process
let sp_auth = StartProcessAuth(env.root)
let bp_auth = ApplyReleaseBackpressureAuth(env.root)
let pm: ProcessMonitor = ProcessMonitor(sp_auth, bp_auth, consume notifier,
path, args, vars)
// write to STDIN of the child process
pm.write("one, two, three")
pm.done_writing() // closing stdin allows cat to terminate


32
33
34
35
36
37
38
39
40
41
42use "collections"

type IniMap is Map[String, Map[String, String]]

primitive IniParse
"""
This is used to parse INI formatted text as a nested map of strings.
"""
fun apply(lines: Iterator[String]): IniMap ref^ ? =>
"""


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

Parameters¶

map: M

Returns¶

MapKeys[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.


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


else
0 == @symlink(path.cstring(), link_name.path.cstring())
end

fun chmod(mode: FileMode box): Bool =>
"""
Set the FileMode for a path.
"""
if not caps(FileChmod) then
return false
end

let m = mode.u32()

ifdef windows then
0 == @_chmod(path.cstring(), m)
else
0 == @chmod(path.cstring(), m)
end


# Combined create-apply

If a type has a create constructor that takes no arguments then the create and apply sugar can be used together. Just call on the type and calls to create and apply will be added. The call to create will take no arguments and the call to apply will take whatever arguments are supplied.

```pony
var foo = Foo()
var bar = Bar(x, 37 where crash = false)
```

becomes:

```pony
var foo = Foo.create().apply()
var bar = Bar.create().apply(x, 37 where crash = false)
```

__What if the create has default arguments? Do I get the combined create-apply sugar if I want to use the defaults?__ The combined create-apply sugar can only be used when the `create` constructor has no arguments. If there are default arguments then this sugar cannot be used.


fun ref property(arg1: (T1, T2, T3), h: PropertyHelper) ? =>
(let x, let y, let z) = consume arg1
property3(consume x, consume y, consume z, h)?

fun ref property3(arg1: T1, arg2: T2, arg3: T3, h: PropertyHelper) ?
"""
A method verifying that a certain property holds for all given
`arg1`,`arg2`, and `arg3`
with the help of [PropertyHelper](pony_check-PropertyHelper.md) `h`.
"""

trait Property4[T1, T2, T3, T4] is Property1[(T1, T2, T3, T4)]

fun gen1(): Generator[T1]
"""
The Generator for the first argument to your `property4` method.
"""

fun gen2(): Generator[T2]
"""


fun box tcp_s_data_in()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_thin_dupack¶
[Source]


ProcessMonitor calls this when new data is received on STDERR of the
forked process
"""

fun ref failed(process: ProcessMonitor ref, err: ProcessError) =>
"""
ProcessMonitor calls this if we run into errors communicating with the
forked process.
"""

fun ref expect(process: ProcessMonitor ref, qty: USize): USize =>
"""
Called when the process monitor has been told to expect a certain quantity
of bytes. This allows nested notifiers to change the expected quantity,
which allows a lower level protocol to handle any framing.
"""
qty

fun ref dispose(process: ProcessMonitor ref, child_exit_status: ProcessExitStatus) =>
"""


randomness.pony

1
2
3
4
5
6
7
8
9
10
11


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

Parameters¶

a: A

Returns¶

I32 val^

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

Returns¶


ne¶
[Source]
fun box ne(
that: Sort[A, B] val)
: Bool val

Parameters¶

that: Sort[A, B] val

Returns¶

Bool val


_ts(Timer(
object iso is TimerNotify
fun apply(timer: Timer, count: U64 = 0): Bool =>
// signal completion of async benchmark iteration when timer fires
c.complete()
false
end,
_ns))

```
By default, the results are printed to stdout like so:
```
Benchmark results will have their mean and median adjusted for overhead.
You may disable this with --noadjust.

Benchmark                                   mean            median   deviation  iterations
Nothing                                     1 ns              1 ns      ±0.87%     3000000
_Fib(5)                                    12 ns             12 ns      ±1.02%     2000000
_Fib(10)                                  185 ns            184 ns      ±1.03%     1000000
_Fib(20)                                23943 ns          23898 ns      ±1.11%       10000


primitive PrefixDefault is PrefixSpec

primitive PrefixSpace is PrefixSpec
primitive PrefixSign is PrefixSpec

type PrefixNumber is
( PrefixDefault
| PrefixSpace
| PrefixSign )


Public Functions¶
join¶
[Source]
Create a promise that is fulfilled when all promises in the given sequence
are fulfilled. If any promise in the sequence is rejected then the new
promise is also rejected. The order that values appear in the final array
is based on when each promise is fulfilled and not the order that they are
given.
Join three existing promises to make a fourth.
use "promises"

actor Main
new create(env: Env) =>

let p1 = Promise[String val]
let p2 = Promise[String val]
let p3 = Promise[String val]


fun box modc(
y: I16 val)
: (I16 val , Bool val)

Parameters¶

y: I16 val

Returns¶

(I16 val , Bool val)

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

Parameters¶


# Example program

Imagine you have a program with 3 actors that you need to shutdown when it
receives a TERM signal. We can set up a Custodian that knows about each
of our actors and when a TERM signal is received, is disposed of.

```pony
use "bureaucracy"
use "signals"

actor Actor1
be dispose() => None // dispose of resources here.

actor Actor2
be dispose() => None // dispose of resources here.

actor Actor3
be dispose() => None // dispose of resources here.

actor Main


fun box u32()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128¶
[Source]


1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191


Bool val

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

Parameters¶

that: FormatOctal val

Returns¶

Bool val


fun mcast_undefined():I32 => @pony_os_sockopt_option(I32(362))
fun mrt_add_bw_upcall():I32 => @pony_os_sockopt_option(I32(363))
fun mrt_add_mfc():I32 => @pony_os_sockopt_option(I32(364))
fun mrt_add_vif():I32 => @pony_os_sockopt_option(I32(365))
fun mrt_api_config():I32 => @pony_os_sockopt_option(I32(366))
fun mrt_api_flags_all():I32 => @pony_os_sockopt_option(I32(367))
fun mrt_api_support():I32 => @pony_os_sockopt_option(I32(368))
fun mrt_assert():I32 => @pony_os_sockopt_option(I32(369))
fun mrt_del_bw_upcall():I32 => @pony_os_sockopt_option(I32(370))
fun mrt_del_mfc():I32 => @pony_os_sockopt_option(I32(371))
fun mrt_del_vif():I32 => @pony_os_sockopt_option(I32(372))
fun mrt_done():I32 => @pony_os_sockopt_option(I32(373))
fun mrt_init():I32 => @pony_os_sockopt_option(I32(374))
fun mrt_mfc_bw_upcall():I32 => @pony_os_sockopt_option(I32(375))
fun mrt_mfc_flags_all():I32 => @pony_os_sockopt_option(I32(376))
fun mrt_mfc_flags_border_vif():I32 => @pony_os_sockopt_option(I32(377))
fun mrt_mfc_flags_disable_wrongvif():I32 => @pony_os_sockopt_option(I32(378))
fun mrt_mfc_rp():I32 => @pony_os_sockopt_option(I32(379))
fun mrt_pim():I32 => @pony_os_sockopt_option(I32(380))
fun mrt_version():I32 => @pony_os_sockopt_option(I32(381))


Platform¶
[Source]
primitive val Platform

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

Returns¶

Platform val^


fun options(): Map[String, OptionSpec] box =>
"""
Returns a map by name of the named options of this command.
"""
_options

fun commands(): Map[String, CommandSpec box] box =>
"""
Returns a map by name of the child commands of this command.
"""
_commands

fun args(): Array[ArgSpec] box =>
"""
Returns an array of the positional arguments of this command.
"""
_args

fun is_leaf(): Bool => _type is _CommandSpecLeaf


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


new val create()
: FormatBinary val^

Returns¶

FormatBinary val^

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

Parameters¶

that: FormatBinary val

Returns¶


USize val

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

Returns¶

U64 val

string¶
fun box string()
: String iso^

Returns¶


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

Returns¶

None val

right¶
[Source]
Move right.
fun ref right(
ctrl: Bool val = false,
alt: Bool val = false,
shift: Bool val = false)
: None val

Parameters¶


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

p'

fun tag timeout(expiration: U64) =>
"""
Reject the promise after the given expiration in nanoseconds.
"""
Timers.apply(Timer(
object iso is TimerNotify
let _p: Promise[A] = this
fun ref apply(timer: Timer, count: U64): Bool =>
_p.reject()
false
end,
expiration))

be _attach(attach: _IThen[A] iso) =>
"""
Attaches a step asynchronously. If this promise has already been fulfilled


Called when no more data will arrive on the stream.
"""
None

interface tag InputStream
"""
Asynchronous access to some input stream.
"""
be apply(notify: (InputNotify iso | None), chunk_size: USize = 32)
"""
Set the notifier. Optionally, also sets the chunk size, dictating the
maximum number of bytes of each chunk that will be passed to the notifier.
"""

be dispose() =>
"""
Clear the notifier in order to shut down input.
"""
None


| 80 => 419 | 81 => 421 | 82 => 431 | 83 => 433 | 84 => 439
| 85 => 443 | 86 => 449 | 87 => 457 | 88 => 461 | 89 => 463
| 90 => 467 | 91 => 479 | 92 => 487 | 93 => 491 | 94 => 499
| 95 => 503 | 96 => 509 | 97 => 521 | 98 => 523 | 99 => 541
| 100 => 547 | 101 => 557 | 102 => 563 | 103 => 569 | 104 => 571
| 105 => 577 | 106 => 587 | 107 => 593 | 108 => 599 | 109 => 601
| 110 => 607 | 111 => 613 | 112 => 617 | 113 => 619 | 114 => 631
| 115 => 641 | 116 => 643 | 117 => 647 | 118 => 653 | 119 => 659
| 120 => 661 | 121 => 673 | 122 => 677 | 123 => 683 | 124 => 691
| 125 => 701 | 126 => 709 | 127 => 719 | 128 => 727 | 129 => 733
| 130 => 739 | 131 => 743 | 132 => 751 | 133 => 757 | 134 => 761
| 135 => 769 | 136 => 773 | 137 => 787 | 138 => 797 | 139 => 809
| 140 => 811 | 141 => 821 | 142 => 823 | 143 => 827 | 144 => 829
| 145 => 839 | 146 => 853 | 147 => 857 | 148 => 859 | 149 => 863
| 150 => 877 | 151 => 881 | 152 => 883 | 153 => 887 | 154 => 907
| 155 => 911 | 156 => 919 | 157 => 929 | 158 => 937 | 159 => 941
| 160 => 947 | 161 => 953 | 162 => 967 | 163 => 971 | 164 => 977
| 165 => 983 | 166 => 991 | 167 => 997 | 168 => 1009 | 169 => 1013
| 170 => 1019 | 171 => 1021 | 172 => 1031 | 173 => 1033 | 174 => 1039
| 175 => 1049 | 176 => 1051 | 177 => 1061 | 178 => 1063 | 179 => 1069


Returns¶

NullablePointer[A] ref^

Public Functions¶
apply¶
[Source]
This re-encodes the type of this from NullablePointer[A] to A, allowing
this to be assigned to a field of variable of type A. If this is a null
pointer, an error is raised.
fun box apply()
: this->A ?

Returns¶

this->A ?

is_none¶


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

Parameters¶

y: U16 val

Returns¶

U16 val

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

Parameters¶


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


fun ref delete(ctrl: Bool = false, alt: Bool = false, shift: Bool = false) =>
"""
Forward delete.
"""
try
if _cur_pos < _edit.size().isize() then
_edit.delete(_cur_pos, 1)
end

while
(_cur_pos < _edit.size().isize()) and
((_edit.at_offset(_cur_pos)? and 0xC0) == 0x80)
do
_edit.delete(_cur_pos, 1)
end

_refresh_line()
end

fun ref _clear() =>


setsockopt¶
[Source]
General wrapper for UDP sockets to the setsockopt(2) system call.
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:
// 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)


fun white_bg(): String =>
"""
White background.
"""
"\x1B[107m"

fun bright_red_bg(): String =>
"""
Bright red background.
"""
"\x1B[101m"

fun bright_green_bg(): String =>
"""
Bright green background.
"""
"\x1B[102m"

fun bright_yellow_bg(): String =>


### Examples

```pony
Iter[I64]([2; 4; 6].values())
.any({(I64) => (x % 2) == 1 })
```
`false`

```pony
Iter[I64]([2; 3; 4].values())
.any({(I64) => (x % 2) == 1 })
```
`true`
"""
for x in _iter do
if try f(x)? else false end then
return true
end
end
false


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


[Source]
fun ref usize()
: USize val

Returns¶

USize val

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

Returns¶

I8 val

i16¶


end
end

actor Main
new create(env: Env) =>
env.input(recover Notify(env) end, 1024)
```
"""
embed _chunks: List[(Array[U8] val, USize)] = _chunks.create()
var _available: USize = 0

fun size(): USize =>
"""
Return the number of available bytes.
"""
_available

fun ref clear() =>
"""
Discard all pending data.


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

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

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

fun subc(y: U16): (U16, Bool) =>
@"llvm.usub.with.overflow.i16"(this, y)

fun mulc(y: U16): (U16, Bool) =>
@"llvm.umul.with.overflow.i16"(this, y)

fun divc(y: U16): (U16, Bool) =>
_UnsignedCheckedArithmetic.div_checked[U16](this, y)

fun remc(y: U16): (U16, Bool) =>
_UnsignedCheckedArithmetic.rem_checked[U16](this, y)


abs¶
[Source]
Creates a new timer with an absolute expiration time rather than a relative
time. The expiration time is wall-clock adjusted system time.
new ref abs(
notify: TimerNotify ref,
expiration: (I64 val , I64 val),
interval: U64 val = 0)
: Timer ref^

Parameters¶

notify: TimerNotify ref
expiration: (I64 val , I64 val)
interval: U64 val = 0

Returns¶

Timer ref^


List[this->A!] ref^

reverse¶
[Source]
Builds a new List by reversing the elements in the List.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.reverse() // ["c"; "b"; "a"]

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

Returns¶

List[this->A!] ref^

contains[optional B: (A & HasEq[A!] #read)]¶
[Source]
Returns true if the List contains the provided element, otherwise returns false.


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


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

Returns¶

A

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

Parameters¶

y: A


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

Parameters¶

y: I8 val

Returns¶

I8 val

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

Parameters¶


"""
Get a big-endian F64.
"""
F64.from_bits(u64_be()?)

fun ref f64_le(): F64 ? =>
"""
Get a little-endian F64.
"""
F64.from_bits(u64_le()?)

fun ref _byte(): U8 ? =>
"""
Get a single byte.
"""
let node = _chunks.head()?
(var data, var offset) = node()?
let r = data(offset)?

offset = offset + 1


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


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


Parameters¶

y: A

Returns¶

(A , Bool val)

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

Parameters¶

y: A

Returns¶


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


property.pony

1
2
3
4
5
6
7
8
9
10
11


Returns¶

None val

clear¶
[Source]
Unsets all flags.
fun ref clear()
: None val

Returns¶

None val

set¶
[Source]
Sets the flag.


692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711


F64 val

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

Returns¶

I8 val

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

Returns¶


ILong¶
[Source]
primitive val ILong is
SignedInteger[ILong val, ULong val] val

Implements¶

SignedInteger[ILong val, ULong val] val

Constructors¶
create¶
[Source]


MapKeys[K: Any #share, V: Any #share, H: HashFunction[K] val]¶
[Source]
class ref MapKeys[K: Any #share, V: Any #share, H: HashFunction[K] val]

Constructors¶
create¶
[Source]
new ref create(
m: HashMap[K, V, H] val)
: MapKeys[K, V, H] ref^

Parameters¶


source_loc.pony

1
2
3
4
5
6
7
8
9
10
11


[Source]
Resets all colours and text styles to the default.
fun box reset()
: String val

Returns¶

String val

bold¶
[Source]
Bold text. Does nothing on Windows.
fun box bold(
state: Bool val = true)
: String val

Parameters¶

state: Bool val = true


Returns¶

U32 val

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

Returns¶

U32 val

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


@"llvm.cttz.i64"(this.u64(), true).ulong()
end

fun bitwidth(): ULong => ifdef ilp32 or llp64 then 32 else 64 end

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

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

fun fld(y: ILong): ILong =>
_SignedArithmetic.fld[ILong, ULong](this, y)

fun fld_unsafe(y: ILong): ILong =>
_SignedUnsafeArithmetic.fld_unsafe[ILong, ULong](this, y)

fun mod(y: ILong): ILong =>
_SignedArithmetic.mod[ILong, ULong](this, y)

fun mod_unsafe(y: ILong): ILong =>


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


for i in iter do
l = Cons[A](i, l)
end
l.reverse()

fun eq[T: Equatable[T] val = A](l1: List[T], l2: List[T]): Bool ? =>
"""
Checks whether two lists are equal.
"""
if (l1.is_empty() and l2.is_empty()) then
true
elseif (l1.is_empty() and l2.is_non_empty()) then
false
elseif (l1.is_non_empty() and l2.is_empty()) then
false
elseif (l1.head()? != l2.head()?) then
false
else
eq[T](l1.tail()?, l2.tail()?)?


Bureaucracy package¶
It happens to almost every program. It starts small, tiny if you will, like a
village where every actor knows every other actor and shutdown is easy. One day
you realize your program is no longer a cute seaside hamlet, its a bustling
metropolis and you are doing way too much work to keep track of everything.
What do you do? Call for a little bureaucracy.
The bureaucracy contains objects designed to ease your bookkeeping burdens.
Need to shutdown a number of actors together? Check out Custodian. Need
to keep track of a lot of stuff and be able to look it up by name? Check out
Registrar.
Put bureaucracy to use today and before long, your sprawling metropolis of a
code base will be manageable again in no time.
Public Types¶


i16_le¶
[Source]
Write an I16 to the buffer in little-endian byte order.
fun ref i16_le(
data: I16 val)
: None val

Parameters¶

data: I16 val

Returns¶

None val

i16_be¶
[Source]
Write an I16 to the buffer in big-endian byte order.
fun ref i16_be(


Returns¶

None val

dispose_when_done¶
[Source]
Pass a disposable actor to be disposed of when the test is complete.
The actor will be disposed no matter whether the test succeeds or fails.
If the test is already tearing down, the actor will be disposed immediately.
fun box dispose_when_done(
disposable: DisposableActor tag)
: None val

Parameters¶

disposable: DisposableActor tag

Returns¶


fun box sctp_authentication()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_auth_chunk¶
[Source]


Copy n elements from this to that.
"""
compile_intrinsic

fun tag usize(): USize =>
"""
Convert the pointer into an integer.
"""
compile_intrinsic

fun tag is_null(): Bool =>
"""
Return true for a null pointer, false for anything else.
"""
compile_intrinsic

fun tag eq(that: Pointer[A] tag): Bool =>
"""
Return true if this address is that address.
"""


let max_shrink_rounds: USize val¶
[Source]

let max_generator_retries: USize val¶
[Source]

let timeout: U64 val¶
[Source]

let async: Bool val¶
[Source]

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

Returns¶


env.out.print("overflow detected")
end
```

Partial as well as checked arithmetic comes with the burden of handling exceptions on every case and incurs some performance overhead, be warned.

| Partial Operator | Method        | Description                                       |
| ---------------- | ------------- | ------------------------------------------------- |
| `+?`             | `add_partial()` | errors on overflow/underflow                      |
| `-?`             | `sub_partial()` | errors on overflow/underflow                      |
| `*?`             | `mul_partial()` | errors on overflow/underflow                      |
| `/?`             | `div_partial()` | errors on overflow/underflow and division by zero |
| `%?`             | `rem_partial()` | errors on overflow/underflow and division by zero |
| `%%?`            | `mod_partial()` | errors on overflow/underflow and division by zero |

---

Checked arithmetic functions all return the result of the operation and a `Boolean` flag indicating overflow/underflow or division by zero in a tuple.

| Checked Method | Description                                                                               |


ArgSpec¶
[Source]
ArgSpec describes the specification of a positional Arg(ument). They have a
name, descr(iption), a typ(e), and a default value when they are not
required.
Args always come after a leaf command, and are assigned in their positional
order.
class val ArgSpec

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


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

Parameters¶

that: AlignCenter val

Returns¶

Bool val

ne¶
[Source]


2. An undefined value that must be ignored.
Usage example:
// connected() is a callback function for class TCPConnectionNotify
fun ref connected(conn: TCPConnection ref) =>
match conn.getsockopt(OSSockOpt.sol_socket(), OSSockOpt.so_rcvbuf(), 4)
| (0, let gbytes: Array[U8] iso) =>
try
let br = Reader.create().>append(consume gbytes)
ifdef littleendian then
let buffer_size = br.u32_le()?
else
let buffer_size = br.u32_be()?
end
end
| (let errno: U32, _) =>
// System call failed
end

fun ref getsockopt(
level: I32 val,


value: A

Returns¶

None val

shift¶
[Source]
Removes an element from the beginning of the sequence.
fun ref shift()
: A^ ?

Returns¶

A^ ?

append¶
[Source]


I32 val

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

Parameters¶

y: I32 val

Returns¶

(I32 val , I32 val)

rem_unsafe¶
[Source]


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


fun box tcpolen_fast_open_min()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpolen_nop¶
[Source]


# Specify the type of items in an array literal

The `as` operator can also be used to tell the compiler what type to use for the items in an array literal. In many cases, the compiler can infer the type, but sometimes it is ambiguous.

For example, in the case of the following program, the method `foo` can take either an `Array[U32] ref` or an `Array[U64] ref` as an argument. If a literal array is passed as an argument to the method and no type is specified then the compiler cannot deduce the correct one because there are two equally valid ones.

```pony
actor Main
fun foo(xs: (Array[U32] ref | Array[U64] ref)): Bool =>
// do something boring here
true

new create(env: Env) =>
foo([as U32: 1; 2; 3])
// the compiler would complain about this:
//   foo([1; 2; 3])
```

The requested type must be a valid type for the items in the array. Since these types are checked at compile time they are guaranteed to work, so there is no need for the programmer to handle an error condition.


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


(U32 val , Bool val)

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

Parameters¶

y: U32 val

Returns¶

U32 val ?

mod_unsafe¶
[Source]


fun box sctp_nagle_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_nrsack_supported¶
[Source]


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


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


A

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

Returns¶

A

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

Returns¶


fun ref push_u128[optional B: (A & Real[B] val & U8 val)](
value: U128 val)
: None val

Parameters¶

value: U128 val

Returns¶

None val

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


[Source]
Build the iterator over values.
reverse of false iterates forward, while
reverse of true iterates in reverse.
new ref create(
head: (N | None val),
reverse: Bool val = false)
: ListValues[A, N] ref^

Parameters¶

head: (N | None val)
reverse: Bool val = false

Returns¶

ListValues[A, N] ref^

Public Functions¶


String val


use @pony_os_connect_tcp6[U32](owner: AsioEventNotify, host: Pointer[U8] tag,
service: Pointer[U8] tag, from: Pointer[U8] tag, flags: U32)
use @pony_os_peername[Bool](fd: U32, ip: NetAddress tag)

actor TCPConnection is AsioEventNotify
"""
A TCP connection. When connecting, the Happy Eyeballs algorithm is used.

The following code creates a client that connects to port 8989 of
the local host, writes "hello world", and listens for a response,
which it then prints.

```pony
use "net"

class MyTCPConnectionNotify is TCPConnectionNotify
let _out: OutStream

new create(out: OutStream) =>
_out = out


fun box eq(
other: (Exited val | Signaled val))
: Bool val

Parameters¶

other: (Exited val | Signaled val)

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: (Exited val | Signaled val))
: Bool val

Parameters¶


# Sequential

Actors themselves, however, are sequential. That is, each actor will only execute one behaviour at a time. This means all the code in an actor can be written without caring about concurrency: no need for locks or semaphores or anything like that.

When you're writing Pony code, it's nice to think of actors not as a unit of parallelism, but as a unit of sequentiality. That is, an actor should do only what _has_ to be done sequentially. Anything else can be broken out into another actor, making it automatically parallel.

In the example below, the `Main` actor calls a behaviour `call_me_later` which, as we know, is _asynchronous_, so we won't wait for it to run before continuing. Then, we run the method `env.out.print`, which is _also asynchronous_, and will print the provided text to the terminal. Now that we've finished executing code inside the `Main` actor, the behaviour we've called earlier will eventually run, and it will print the last text.

```pony
actor Main
new create(env: Env) =>
call_me_later(env)
env.out.print("This is printed first")

be call_me_later(env: Env) =>
env.out.print("This is printed last")
```

Since all this code runs inside the same actor, and the calls to the other behaviour `env.out.print` are sequential as well, we are guaranteed that `"This is printed first"` is always printed __before__ `"This is printed last"`.


test(_TestSub)

class iso _TestAdd is UnitTest
fun name():String => "addition"

fun apply(h: TestHelper) =>
h.assert_eq[U32](4, 2 + 2)

class iso _TestSub is UnitTest
fun name():String => "subtraction"

fun apply(h: TestHelper) =>
h.assert_eq[U32](2, 4 - 2)
```

The make() constructor is not needed for this example. However, it allows for
easy aggregation of tests (see below) so it is recommended that all test Mains
provide it.

Main.create() is called only for program invocations on the current package.


Rand¶
[Source]
type Rand is
XorOshiro128Plus ref

Type Alias For¶

XorOshiro128Plus ref


fun box sctp_peer_addr_thlds()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pktdrop_supported¶
[Source]


Parameters¶

test: {(): None ?} box
msg: String val = ""
loc: SourceLoc val = __loc

Returns¶

Bool val

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


## Example

Assume we have a Pony class with a field that is a pointer to a C string. We would like to be able to serialise and deserialise this object. In order to do that, the Pony class implements the methods `_serialise_space(...)`, `_serialise(...)`, and `_deserialise(...)`. These methods, in turn, call C functions that calculate the number of bytes needed to serialise the string and serialise and deserialise it. In this example the serialised string is represented by a four-byte big-endian number that represents the length of the string, followed by the string itself without the terminating null. So if the C string is `hello world\0` then the serialised string is `\0x00\0x00\0x00\0x0Bhello world` (where the first four bytes of the serialised string are a big-endian representation of the number `0x0000000B`, which is `11`).

```pony
use "serialise"

use "lib:custser"

use @get_string[Pointer[U8]]()
use @serialise_space[USize](s: Pointer[U8] tag)
use @serialise[None](bytes: Pointer[U8] tag, str: Pointer[U8] tag)
use @deserialise[Pointer[U8] tag](bytes: Pointer[U8] tag)
use @printf[I32](fmt: Pointer[U8] tag, ...)

class CStringWrapper
var _cstr: Pointer[U8] tag

new create(cstr: Pointer[U8] tag) =>
_cstr = cstr


ILong val

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

Returns¶

ISize val

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

Returns¶


"""
append_node(ListNode[A](consume a))

fun ref pop(): A^ ? =>
"""
Removes the tail value, raising an error if the tail is empty.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.pop() end  // Returns "c" and my_list is ["a"; "b"]
```
"""
tail()? .> remove().pop()?

fun ref unshift(a: A) =>
"""
Adds a new head value.

```pony
let my_list = List[String].from(["a"; "b"; "c"])


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


I16 val

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

Parameters¶

y: I16 val

Returns¶

I16 val

divrem¶
[Source]


_notify = consume notify

be set_broadcast(state: Bool) =>
"""
Enable or disable broadcasting from this socket.
"""
if not _closed then
if _ip.ip4() then
set_so_broadcast(state)
elseif _ip.ip6() then
@pony_os_multicast_join(_fd, "FF02::1".cstring(), "".cstring())
end
end

be set_multicast_interface(from: String = "") =>
"""
By default, the OS will choose which address is used to send packets bound
for multicast addresses. This can be used to force a specific interface. To
revert to allowing the OS to choose, call with an empty string.
"""


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


I32 val

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

Returns¶

I64 val

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

Returns¶


else
var i: USize = 0

while str._apply(i) != 0 do
i = i + 1
end

_size = i
_alloc = i + 1
_ptr = str
end

new copy_cpointer(str: Pointer[U8] box, len: USize) =>
"""
Create a string by copying a fixed number of bytes from a pointer.
"""
if str.is_null() then
_size = 0
_alloc = 1
_ptr = Pointer[U8]._alloc(_alloc)


Returns¶

U16 val

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

Returns¶

U16 val

bitwidth¶
[Source]


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

Parameters¶

y: U64 val

Returns¶

(U64 val , Bool val)

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

Parameters¶


Per unit test class that provides control, logging and assertion functions.

Each unit test is given a TestHelper when it is run. This is val and so can
be passed between methods and actors within the test without restriction.

The assertion functions check the relevant condition and mark the test as a
failure if appropriate. The success or failure of the condition is reported
back as a Bool which can be checked if a different code path is needed when
that condition fails.

All assert functions take an optional message argument. This is simply a
string that is printed as part of the error message when the condition fails.
It is intended to aid identifying what failed.
"""

let _runner: _TestRunner
let env: Env
"""
The process environment.


Returns¶

None val

size¶
[Source]
Returns the number of elements in the sequence.
fun box size()
: USize val

Returns¶

USize val

apply¶
[Source]
Returns the i-th element of the sequence. Raises an error if the index


.any({(I64) => (x % 2) == 1 })

false
Iter[I64]([2; 3; 4].values())
.any({(I64) => (x % 2) == 1 })

true
fun ref any(
f: {(A!): Bool ?}[A] box)
: Bool val

Parameters¶

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

Returns¶

Bool val


ProcessNotify¶
[Source]
Notifications for Process connections.
interface ref ProcessNotify

Public Functions¶
created¶
[Source]
ProcessMonitor calls this when it is created.
fun ref created(
process: ProcessMonitor ref)
: None val


212
213
214
215
216
217
218
219
220
221
222
223class ListNode[A]
"""
A node in a doubly linked list.

See Pony [collections.List](https://stdlib.ponylang.io/collections-List/)
class for usage examples.

Each node contains four fields: two link fields (references to the previous and
to the next node in the sequence of nodes), one data field, and the reference to


y: U16 val

Returns¶

U16 val

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

Parameters¶

y: U16 val

Returns¶


 Ini package

The Ini package provides support for parsing
[INI file](https://en.wikipedia.org/wiki/INI_file) formatted text.

* Currently _does not_ support multi-line entries.
* Any keys not in a section will be placed in the section ""


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


match align
| AlignLeft =>
s.append(str)
for i in Range(s.size(), s.space()) do
s.push_utf32(fill)
end
| AlignRight =>
for i in Range(0, len - copy_len) do
s.push_utf32(fill)
end
s.append(str)
| AlignCenter =>
let half = (len - copy_len) / 2
for i in Range(0, half) do
s.push_utf32(fill)
end
s.append(str)
for i in Range(s.size(), s.space()) do
s.push_utf32(fill)
end


false otherwise.
"""
_exists(this, f)

fun _exists(l: List[A], f: {(val->A): Bool} box): Bool =>
"""
Private helper for exists, recursively testing predicate on elements,
returning true immediately on an element satisfying the predicate.
"""
match l
| let cons: Cons[A] =>
if (f(cons.head())) then
true
else
_exists(cons.tail(), f)
end
else
false
end


Returns¶

Generator[S] box

iso_seq_of[T: Any #send, S: Seq[T] iso]¶
[Source]
Generate a Seq[T] where T must be sendable (i.e. it must have a
reference capability of either tag, val, or iso).
The constraint of the elements being sendable stems from the fact that
there is no other way to populate the iso seq if the elements might be
non-sendable (i.e. ref), as then the seq would leak references via
its elements.
fun box iso_seq_of[T: Any #send, S: Seq[T] iso](
gen: Generator[T] box,
min: USize val = 0,
max: USize val = 100)
: Generator[S] box

Parameters¶


new iso create(p1: Property1[T] iso, name': (String | None) = None) =>
"""
Wrap a [Property1](pony_check-Property1.md) to make it mimic the PonyTest
[UnitTest](pony_test-UnitTest.md).

If `name'` is given, use this as the test name.
If not, use the property's `name()`.
"""
_name =
match name'
| None => p1.name()
| let s: String => s
end
_prop1 = consume p1

fun name(): String => _name

fun ref apply(h: TestHelper) ? =>
let prop = ((_prop1 = None) as Property1[T] iso^)


auth.pony

1
2
3
4
5
6
7
8
9
10
11


div_unsafe¶
fun box div_unsafe(
y: F32 val)
: F32 val

Parameters¶

y: F32 val

Returns¶

F32 val

divrem_unsafe¶
fun box divrem_unsafe(
y: F32 val)
: (F32 val , F32 val)


 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`.
"""

use @pony_os_stderr[Pointer[U8]]()
use @fprintf[I32](stream: Pointer[U8] tag, fmt: Pointer[U8] tag, ...)

primitive Assert
"""
This is a debug only assertion. If the test is false, it will print any
supplied error message to stderr and raise an error.
"""
fun apply(test: Bool, msg: String = "") ? =>
ifdef debug then
Fact(test, msg)?
end


I64 val

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

Returns¶

I128 val

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

Returns¶


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


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

Returns¶

I8 val

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

Returns¶

I16 val


512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531


fun ctz(): U32 => @"llvm.cttz.i32"(this.u32(), false)

fun clz_unsafe(): U32 =>
"""
Unsafe operation.
If this is 0, the result is undefined.
"""
@"llvm.ctlz.i32"(this.u32(), true)

fun ctz_unsafe(): U32 =>
"""
Unsafe operation.
If this is 0, the result is undefined.
"""
@"llvm.cttz.i32"(this.u32(), true)

fun bitwidth(): U32 => 32

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


then
err
else
(((c.u32() << 12) + (c2.u32() << 6) + c3.u32()) - 0xE2080, 3)
end
end
elseif c < 0xF5 then
// 4-byte.
if (i + 3) >= _size then
// Not enough bytes.
err
else
let c2 = _ptr._apply(i + 1)
let c3 = _ptr._apply(i + 2)
let c4 = _ptr._apply(i + 3)
if
// Not continuation bytes.
((c2 and 0xC0) != 0x80) or
((c3 and 0xC0) != 0x80) or
((c4 and 0xC0) != 0x80) or


out of bounds.
fun box utf32(
offset: ISize val)
: (U32 val , U8 val) ?

Parameters¶

offset: ISize val

Returns¶

(U32 val , U8 val) ?

apply¶
[Source]
Returns the i-th byte. Raise an error if the index is out of bounds.
fun box apply(
i: USize val)
: U8 val ?


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

Parameters¶

that: FileError val

Returns¶

Bool val


1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091


unit_test.pony

1
2
3
4
5
6
7
8
9
10
11


fun box fchflags()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

fchmod¶
[Source]


String val

bright_cyan_bg¶
[Source]
Bright cyan background.
fun box bright_cyan_bg()
: String val

Returns¶

String val

bright_grey_bg¶
[Source]
Bright grey background.
fun box bright_grey_bg()
: String val


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


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

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

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


U64 val

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

Returns¶

U64 val

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

Parameters¶


# Platform-dependent Code

The Pony libraries, of course, want to abstract platform differences. Sometimes you may want a `use` command that only works under certain circumstances, most commonly only on a particular OS or only for debug builds. You can do this by specifying a condition for a `use` command:

```pony
use "foo" if linux
use "bar" if (windows and debug)
```

Use conditions can use any of the methods defined in `builtin/Platform` as conditions.
There are currently the following booleans defined: `freebsd`, `linux`, `osx`, `posix` => `(freebsd or linux or osx)`, `windows`, `x86`, `arm`, `lp64`, `llp64`, `ilp32`, `native128`, `debug`

They can also use the operators `and`, `or`, `xor` and `not`. As with other expressions in Pony, parentheses __must__ be used to indicate precedence if more than one of `and`, `or` and `xor` is used.

Any use command whose condition evaluates to false is ignored.


Parameters¶

offset: ISize val

Returns¶

None val

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

Returns¶

None val


fun gt(y: box->A): Bool => this > y

fun min(y: A): A
fun max(y: A): A

fun hash(): USize =>
var x = usize()

ifdef ilp32 then
x = (not x) + (x << 15)
x = x xor (x >> 12)
x = x + (x << 2)
x = x xor (x >> 4)
x = (x + (x << 3)) + (x << 11)
x = x xor (x >> 16)

x
else
hash64().usize()
end


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


host,
service)

class ExampleProxy is Proxy
let _proxy_host: String
let _proxy_service: String

new create(proxy_host: String, proxy_service: String) =>
_proxy_host = proxy_host
_proxy_service = proxy_service

fun apply(wrap: TCPConnectionNotify iso): TCPConnectionNotify iso^ =>
ExampleProxyNotify.create(consume wrap, _proxy_service, _proxy_service)

class iso ExampleProxyNotify is TCPConnectionNotify
// Fictional proxy implementation that has no error
// conditions, and always forwards the connection.
let _proxy_host: String
let _proxy_service: String
var _destination_host: (None | String) = None


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


fun box ip_fw_nat_del()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_fw_nat_get_log¶
[Source]


1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451


[Source]
fun box divrem(
y: A)
: (A , A)

Parameters¶

y: A

Returns¶

(A , A)

rem¶
[Source]
Calculate the remainder after integer division, rounded towards zero (div).
The result has the sign of the dividend.
fun box rem(
y: A)


ULong val

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

Returns¶

String iso^

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

Parameters¶


command_spec.pony

1
2
3
4
5
6
7
8
9
10
11


var k = key
var b = I64(0)
var j = I64(0)

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

b.i32()
```

We can now use ponyc to compile a native executable integrating Pony and our C library. And that's all we need to do.


# String Literals

String literals are enclosed with double quotes `"` or triple-quoted `"""`. They can contain any kind of bytes and various escape sequences:

* `\u00FE` Unicode escape sequence with 4 hex digits encoding one code point
* `\u10FFFE` Unicode escape sequence with 6 hex digits encoding one code point
* `\x4F` hex escape sequence for Unicode letters with 2 hex digits (up to `0xFF`)
* `\a`, `\b`, `\e`, `\f`, `\n`, `\r`, `\t`, `\v`, `\\`, `\0`, `\"`

Each escape sequence encodes a full character, not byte.

```pony
use "format"

actor Main
new create(env: Env) =>

let pony = "🐎"
let pony_hex_escaped = "p\xF6n\xFF"
let pony_unicode_escape = "\U01F40E"


fun box sctp_set_peer_primary_addr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_shutdown_ack¶
[Source]


{(sample, ph) =>
ph.array_eq[Usize](arg1, arg1.reverse().reverse())
})
// ... possibly more properties, using `PonyCheck.for_all`

Independently of how you integrate with PonyTest,
the PonyCheck machinery will instantiate the provided Generator, and will
execute it for a configurable number of samples.
If the property fails using an assertion method of
PropertyHelper,
the failed example will be shrunken by the generator
to obtain a smaller and more informative, still failing, sample
for reporting.
Public Types¶

primitive ASCIIAll
primitive ASCIIAllWithNUL
primitive ASCIIDigits
primitive ASCIILetters
primitive ASCIILettersLower


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

Returns¶

U128 val

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

Returns¶

ULong val


fun box ipx_mtu()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipx_primary¶
[Source]


end
else
false
end

fun create_file(target: String): File iso^ ? =>
"""
Open for read/write, creating if it doesn't exist, preserving the contents
if it does exist.
"""
if
not path.caps(FileCreate)
or not path.caps(FileRead)
or not path.caps(FileWrite)
or (_fd == -1)
then
error
end

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


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


that: Flags[A, B] box)
: Bool val

Parameters¶

that: Flags[A, B] box

Returns¶

Bool val

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


new val create()
: MaxHeapPriority[A] val^

Returns¶

MaxHeapPriority[A] val^

Public Functions¶
apply¶
[Source]
fun box apply(
x: A,
y: A)
: Bool val

Parameters¶

x: A
y: A


fun box ipx_getnetinfo()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipx_immediatespxack¶
[Source]


# That's it!

Really, that's it. The program begins by creating a `Main` actor, and in the constructor, we print "Hello, world!" to `stdout`. Next, we'll start diving into the Pony type system.


_alloc = len.next_pow2().max(len).max(8)
_ptr = Pointer[A]._alloc(_alloc)
else
_alloc = 0
_ptr = Pointer[A]
end

new init(from: A^, len: USize) =>
"""
Create an array of len elements, all initialised to the given value.
"""
_size = len

if len > 0 then
_alloc = len.next_pow2().max(len).max(8)
_ptr = Pointer[A]._alloc(_alloc)

var i: USize = 0

while i < len do


fun rds_rdma_use_once():I32 => @pony_os_sockopt_option(I32(482))
fun rds_recverr():I32 => @pony_os_sockopt_option(I32(483))
fun rds_trans_count():I32 => @pony_os_sockopt_option(I32(484))
fun rds_trans_ib():I32 => @pony_os_sockopt_option(I32(485))
fun rds_trans_iwarp():I32 => @pony_os_sockopt_option(I32(486))
fun rds_trans_none():I32 => @pony_os_sockopt_option(I32(487))
fun rds_trans_tcp():I32 => @pony_os_sockopt_option(I32(488))
fun rose_access_barred():I32 => @pony_os_sockopt_option(I32(489))
fun rose_defer():I32 => @pony_os_sockopt_option(I32(490))
fun rose_dte_originated():I32 => @pony_os_sockopt_option(I32(491))
fun rose_holdback():I32 => @pony_os_sockopt_option(I32(492))
fun rose_idle():I32 => @pony_os_sockopt_option(I32(493))
fun rose_invalid_facility():I32 => @pony_os_sockopt_option(I32(494))
fun rose_local_procedure():I32 => @pony_os_sockopt_option(I32(495))
fun rose_max_digis():I32 => @pony_os_sockopt_option(I32(496))
fun rose_mtu():I32 => @pony_os_sockopt_option(I32(497))
fun rose_network_congestion():I32 => @pony_os_sockopt_option(I32(498))
fun rose_not_obtainable():I32 => @pony_os_sockopt_option(I32(499))
fun rose_number_busy():I32 => @pony_os_sockopt_option(I32(500))
fun rose_out_of_order():I32 => @pony_os_sockopt_option(I32(501))


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


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


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


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


@{(ctx: Pointer[None], size: USize): Pointer[U8] =>
@pony_alloc(ctx, size)
}
let throw_fn = @{() ? => error }
@pony_serialise(@pony_ctx(), data, Pointer[None], r, alloc_fn, throw_fn) ?
_data = consume r

new input(auth: InputSerialisedAuth, data: Array[U8] val) =>
"""
A caller with InputSerialisedAuth can create serialised data from any
arbitrary set of bytes. It is the caller's responsibility to ensure that
the data is in fact well-formed serialised data. This is currently the most
dangerous method, as there is currently no way to check validity at
runtime.
"""
_data = data

fun apply(auth: DeserialiseAuth): Any iso^ ? =>
"""
A caller with DeserialiseAuth can create an object graph from serialised


fun tag hash()
: USize val

Returns¶

USize val

hash64¶
[Source]
Returns a 64-bit hash of the address.
fun tag hash64()
: U64 val

Returns¶

U64 val


fun box udp_encap()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

udp_encap_espinudp_maxfraglen¶
[Source]


Returns¶

U32 val

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

Returns¶

U32 val

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


U16 val

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

Returns¶

U16 val

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

Returns¶


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

fun fld(y: F64): F64 =>
(this / y).floor()

fun fld_unsafe(y: F64): F64 =>
(this /~ y).floor()

fun mod(y: F64): F64 =>
let r = this.rem(y)
if r == F64(0.0) then
r.copysign(y)
elseif (r > 0) xor (y > 0) then
r + y
else
r
end


[Source]
The Generator used to produce samples to verify.
fun box gen()
: Generator[T] box

Returns¶

Generator[T] box

property¶
[Source]
A method verifying that a certain property holds for all given arg1
with the help of PropertyHelper h.
fun ref property(
arg1: T,
h: PropertyHelper val)
: None val ?

Parameters¶


892
893
894
895
896
897
898
899
900
901
902
903
904
905
906use @"llvm.bitreverse.i8"[U8](src: U8)
use @"llvm.bitreverse.i16"[U16](src: U16)
use @"llvm.bitreverse.i32"[U32](src: U32)
use @"llvm.bitreverse.i64"[U64](src: U64)
use @"llvm.bitreverse.i128"[U128](src: U128)
use @"llvm.bswap.i8"[U16](src: U8)


"""
Apply `fn` to each value of this iterator
and yield the results.

Example:

```pony
let single_code_point_string_gen =
Generators.u32()
.map[String]({(u) => String.from_utf32(u) })
```
"""
Generator[U](
object is GenObj[U]
fun generate(rnd: Randomness): GenerateResult[U] ? =>
(let generated: T, let shrunken: Iterator[T^]) =
_gen.generate_and_shrink(rnd)?

(fn(consume generated), _map_shrunken(shrunken))


fun u8(base: U8 = 0): U8 ? => _to_int[U8](base)?
fun u16(base: U8 = 0): U16 ? => _to_int[U16](base)?
fun u32(base: U8 = 0): U32 ? => _to_int[U32](base)?
fun u64(base: U8 = 0): U64 ? => _to_int[U64](base)?
fun u128(base: U8 = 0): U128 ? => _to_int[U128](base)?
fun ulong(base: U8 = 0): ULong ? => _to_int[ULong](base)?
fun usize(base: U8 = 0): USize ? => _to_int[USize](base)?

fun _to_int[A: ((Signed | Unsigned) & Integer[A] val)](base: U8): A ? =>
"""
Convert the *whole* string to the specified type.
If there are any other characters in the string, or the integer found is
out of range for the target type then an error is thrown.
"""
(let v, let d) = read_int[A](0, base)?
// Check the whole string is used
if (d == 0) or (d.usize() != _size) then error end
v

fun read_int[A: ((Signed | Unsigned) & Integer[A] val)](


fun box sctp_set_dynamic_primary()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_set_peer_primary_addr¶
[Source]


# Reference Capability Matrix

At this point, it's quite possible that you read the previous sections in this chapter and are still pretty confused about the relation between reference capabilities. It's okay! We have all struggled when learning this part of Pony, too. Once you start working on Pony code, you'll get a better intuition with them.

In the meantime, if you still feel like all these tidbits in the chapter are still scrambled in your head, there is one resource often presented with Pony that can give you a more visual representation: the __reference capability matrix__.

It is also the origin of the concept behind each capability in Pony, in the sense of how each capability denies certain properties to its reference -- in other words, which guarantees a capability makes. We will explain what that actually means before presenting the matrix.


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

Returns¶

U32 val

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

Parameters¶


y: U64 val

Returns¶

U64 val

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

Parameters¶

y: U64 val

Returns¶


fun box i64_unsafe()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong_unsafe¶
[Source]


poperator.pony

1
2
3
4
5
6
7
8
9
10
11


F64 val

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

Returns¶

F64 val

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

Parameters¶


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

Parameters¶

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

Returns¶


fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

I8 val

i16_unsafe¶
[Source]


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


Bool val

next¶
[Source]
fun ref next()
: A ?

Returns¶

A ?

next_or¶
[Source]
Return the next value, or the given default.
Example¶
let x: (U64 | None) = 42
Iter[U64].maybe(x).next_or(0)


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


listen: TCPListener ref

Returns¶

None val

connected¶
[Source]
Create a new TCPConnectionNotify to attach to a new TCPConnection for a
newly established connection to the server.
fun ref connected(
listen: TCPListener ref)
: TCPConnectionNotify iso^ ?

Parameters¶

listen: TCPListener ref


fun val values()
: MapValues[K, V, H] ref

Returns¶

MapValues[K, V, H] ref

pairs¶
[Source]
fun val pairs()
: MapPairs[K, V, H] ref

Returns¶

MapPairs[K, V, H] ref


bytes as serialised data. This is the most dangerous capability, as currently
it is possible for a malformed chunk of data to crash your program if it is
deserialised.
"""
new create(auth: AmbientAuth) =>
None

class val Serialised
"""
This represents serialised data. How it can be used depends on the other
capabilities a caller holds.
"""
let _data: Array[U8] val

new create(auth: SerialiseAuth, data: Any box) ? =>
"""
A caller with SerialiseAuth can create serialised data from any object.
"""
let r = recover Array[U8] end
let alloc_fn =


fun box sctp_get_addr_len()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_get_assoc_id_list¶
[Source]


Path¶
[Source]
Operations on paths that do not require a capability. The operations can be
used to manipulate path names, but give no access to the resulting paths.
primitive val Path

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

Returns¶


y: I32 val

Returns¶

I32 val

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

Parameters¶

y: I32 val

Returns¶


end
end

fun ref _notify_listening() =>
"""
Inform the notifier that we're listening.
"""
if _fd != -1 then
_notify.listening(this)
else
_notify.not_listening(this)
end

fun ref _close() =>
"""
Inform the notifier that we've closed.
"""
ifdef windows then
// On windows, wait until IOCP read operation has completed or been
// cancelled.


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

Returns¶

U64 val

string¶
fun box string()
: String iso^

Returns¶

String iso^


"""
let old = _array
let old_len = old.size()

_array = _array.init(_MapEmpty, len)
_size = 0

try
for i in Range(0, old_len) do
match old(i)? = _MapDeleted
| (let k: K, let v: V) =>
this(consume k) = consume v
end
end
end

fun keys(): MapKeys[K, V, H, this->HashMap[K, V, H]]^ =>
"""
Return an iterator over the keys.
"""


fun substring(from: ISize, to: ISize = ISize.max_value()): String iso^ =>
"""
Returns a substring. Index range [`from` .. `to`) is half-open.
Returns an empty string if nothing is in the range.

Note that this operation allocates a new string to be returned. For
similar operations that don't allocate a new string, see `trim` and
`trim_in_place`.
"""
let start = offset_to_index(from)
let finish = offset_to_index(to).min(_size)

if (start < _size) and (start < finish) then
let len = finish - start
let str = recover String(len) end
_ptr._offset(start)._copy_to(str._ptr._unsafe(), len)
str._size = len
str._set(len, 0)
str
else


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


fun decode[A: Seq[U8] iso = Array[U8] iso](
data: ReadSeq[U8],
at62: U8 = '+',
at63: U8 = '/',
pad: U8 = '=')
: A^ ?
=>
"""
Configurable decoding. The defaults are for RFC 4648. Missing padding is
not an error. Non-base64 data, other than whitespace (which can appear at
any time), is an error.
"""
let len = (data.size() * 4) / 3
let out = recover A(len) end

var state = U8(0)
var input = U8(0)
var output = U8(0)


U64 val

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

Returns¶

I8 val

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

Returns¶


Clear all of the any-user flags.
"""
any_read = false
any_write = false
any_exec = false

fun ref private() =>
"""
Clear all of the group and any-user flags.
"""
group_read = false
group_write = false
group_exec = false
any_read = false
any_write = false
any_exec = false

fun u32(): U32 =>
"""
Get the OS specific integer for a file mode. On Windows, if any read flag


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


# The Pony compiler

Before you get started, please check out the [installation instructions](https://github.com/ponylang/ponyc/blob/main/INSTALL.md) for the Pony compiler.


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 )

fun ref proxy_via(
host: String val,
service: String val)
: (String val , String val)

Parameters¶

host: String val
service: String val

Returns¶

(String val , String val)


Bool val


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

Parameters¶

y: ULong val

Returns¶

(ULong val , Bool val)

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

Parameters¶


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


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


fun zip3[T1, T2, T3](
gen1: Generator[T1],
gen2: Generator[T2],
gen3: Generator[T3])
: Generator[(T1, T2, T3)]
=>
"""
Zip three generators into a generator of a 3-tuple
containing the values generated by those three generators.
"""
Generator[(T1, T2, T3)](
object is GenObj[(T1, T2, T3)]
fun generate(rnd: Randomness): GenerateResult[(T1, T2, T3)] ? =>
(let v1: T1, let shrinks1: Iterator[T1^]) =
gen1.generate_and_shrink(rnd)?
(let v2: T2, let shrinks2: Iterator[T2^]) =
gen2.generate_and_shrink(rnd)?
(let v3: T3, let shrinks3: Iterator[T3^]) =
gen3.generate_and_shrink(rnd)?
((consume v1, consume v2, consume v3),


fun box ndrvproto_ndrv()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ndrv_deldmxspec¶
[Source]


USize val ?

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

Parameters¶

y: USize val

Returns¶

USize val ?

div_partial¶
[Source]


152
153
154
155
156
157
158
159
160
161
162
163
164"""
PonyBench provides a microbenchmarking framework. It is designed to measure
the runtime of synchronous and asynchronous operations.


SignalRaise val^

Public Functions¶
apply¶
[Source]
fun box apply(
sig: U32 val)
: None val

Parameters¶

sig: U32 val

Returns¶

None val

eq¶


primitive F64
type Float
trait FloatingPoint
primitive Greater
interface HasEq
primitive I128
primitive I16
primitive I32
primitive I64
primitive I8
primitive ILong
primitive ISize
interface InputNotify
interface InputStream
type Int
trait Integer
interface Iterator
primitive Less
primitive None
struct NullablePointer


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


fail(_format_loc(loc) + "Assert EQ failed. " + msg + " Expected ("
+ _print_array[A](expect) + ") == (" + _print_array[A](actual) + ")")
return false
end

log(
_format_loc(loc) + "Assert EQ passed. " + msg + " Got ("
+ _print_array[A](expect) + ") == (" + _print_array[A](actual) + ")",
true)
true

fun assert_array_eq_unordered[A: (Equatable[A] #read & Stringable #read)](
expect: ReadSeq[A],
actual: ReadSeq[A],
msg: String = "",
loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the contents of the 2 given ReadSeqs are equal ignoring order.


512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531


stdin.pony

1
2
3
4
5
6
7
8
9
10
11


min: I8 val = call
max: I8 val = call

Returns¶

Generator[I8 val] box

i16¶
[Source]
Create a generator for I16 values.
fun box i16(
min: I16 val = call,
max: I16 val = call)
: Generator[I16 val] box

Parameters¶

min: I16 val = call
max: I16 val = call


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

Returns¶

None val ?


y: U8 val

Returns¶

U8 val

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

Parameters¶

y: U8 val

Returns¶


fun box div_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶

A

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

Parameters¶


fun box sctp_pcb_flags_recvpeererr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_recvsendfailevnt¶
[Source]


ASCIILetters¶
[Source]
primitive val ASCIILetters

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

Returns¶

ASCIILetters val^


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

Returns¶

Iter[B] ref^

flat_map[B: B]¶
[Source]
Return an iterator over the values of the iterators produced from the
application of the given function.
Example¶
Iter[String](["alpha"; "beta"; "gamma"])
.flat_map[U8]({(s: String): Iterator[U8] => s.values() })

a l p h a b e t a g a m m a
fun ref flat_map[B: B](
f: {(A!): Iterator[B] ?}[A, B] box)
: Iter[B] ref^


Can't be used with --ponyminthreads.

var ponysuspendthreshold: U32 val¶
[Source]
Amount of idle time before a scheduler thread suspends itself to minimize
resource consumption (max 1000 ms, min 1 ms).
Defaults to 1 ms.

var ponycdinterval: U32 val¶
[Source]
Run cycle detection every N ms (max 1000 ms, min 10 ms).
Defaults to 100 ms.

var ponygcinitial: USize val¶
[Source]
Defer garbage collection until an actor is using at least 2^N bytes.
Defaults to 2^14.

var ponygcfactor: F64 val¶
[Source]


fun box u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶
[Source]


let result: SetIs[T] =
SetIs[T].create(size).>union(
Iter[T^](gen.value_iter(rnd))
.take(size)
)
let shrink_iter: Iterator[SetIs[T]^] =
Iter[USize](CountdownIter(size, 0)) //Range(size, 0, -1))
//.skip(1)
.map_stateful[SetIs[T]^]({
(s: USize): SetIs[T]^ =>
SetIs[T].create(s).>union(
Iter[T^](gen.value_iter(rnd)).take(s)
)
})
(consume result, shrink_iter)
end)

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


y: I8 val

Returns¶

I8 val

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

Parameters¶

y: I8 val

Returns¶


fun box ip_striphdr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_traffic_mgt_background¶
[Source]


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


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


FileTruncate¶
[Source]
primitive val FileTruncate

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

Returns¶

FileTruncate val^


FileLines¶
[Source]
Iterate over the lines in a file.
Returns lines without trailing line breaks.
Advances the file cursor to the end of each line returned from next.
This class buffers the file contents to accumulate full lines. If the file
does not contain linebreaks, the whole file content is read and buffered, which
might exceed memory resources. Take care.
class ref FileLines is
Iterator[String iso^] ref

Implements¶


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


fun _negative_to_zero(value: I64): I64 =>
if value > 0 then
value
else
0
end


Parameters¶

base: U8 val = 0

Returns¶

U8 val ?

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

Parameters¶

base: U8 val = 0


end

new max_value() =>
ifdef ilp32 then
0x7FFF_FFFF
else
0x7FFF_FFFF_FFFF_FFFF
end

fun abs(): USize => if this < 0 then (-this).usize() else this.usize() end

fun bit_reverse(): ISize =>
ifdef ilp32 then
@"llvm.bitreverse.i32"(this.u32()).isize()
else
@"llvm.bitreverse.i64"(this.u64()).isize()
end

fun bswap(): ISize =>
ifdef ilp32 then


try
_records(id)?._result(pass, log)

if not _no_prog then
_env.out.print(
_started.string() + " test" + _plural(_started)
+ " started, " + _finished.string() + " complete: "
+ _records(id)?.name + " complete")
end
end

if _all_started and (_finished == _records.size()) then
// All tests have completed
_print_report()
end

be _all_tests_applied() =>
"""
All our tests have been handed to apply(), setup for finishing
"""


`qty` is zero, the call can contain any amount of data. This has no effect
if called in the `sent` notifier callback.

Errors if `qty` exceeds the max buffer size as indicated by the
`read_buffer_size` supplied when the connection was created.
"""

if qty <= _read_buffer_size then
if not _in_sent then
_expect = _notify.expect(this, qty)
_read_buf_size()
end
else
error
end

fun ref set_nodelay(state: Bool) =>
"""
Turn Nagle on/off. Defaults to on. This can only be set on a connected
socket.


* What does the function return?

It returns the _old_ value of `_hunger_level`.

__Wait, seriously? The _old_ value?__ Yes. In Pony, assignment is an expression rather than a statement. That means it has a result. This is true of a lot of languages, but they tend to return the _new_ value. In other words, given `a = b`, in most languages, the value of that is the value of `b`. But in Pony, the value of that is the _old_ value of `a`.

__...why?__ It's called a "destructive read", and it lets you do awesome things with a capabilities-secure type system. We'll talk about that later. For now, we'll just mention that you can also use it to implement a _swap_ operation. In most languages, to swap the values of `a` and `b` you need to do something like:

```pony
var temp = a
a = b
b = temp
```

In Pony, you can just do:

```pony
a = b = a
```


undefined.
The operation isn't required to fully comply to IEEE 754 semantics.
"""
this <=~ y

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

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


n: N

Returns¶

N

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

Returns¶

F64 val

shuffle[A: A]¶
[Source]


// https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
var privileges: _TokenPrivileges ref = _TokenPrivileges
privileges.privilege_count = 1
privileges.privileges_0.luid = luid
privileges.privileges_0.attributes = 0x00000002 // SE_PRIVILEGE_ENABLED
ret = @AdjustTokenPrivileges(token, U8(0), privileges,
U32(0), USize(0), USize(0))
@CloseHandle(token)
if ret == 0 then
return false
end

// now actually try to create the link
let flags: U32 = if FileInfo(this)?.directory then 3 else 0 end
ret = @CreateSymbolicLinkA(link_name.path.cstring(),
path.cstring(), flags)
ret != 0
else
false
end


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

Parameters¶

that: IniNoDelimiter val

Returns¶

Bool val

ne¶
[Source]


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

Parameters¶

a: A

Returns¶

U128 val^

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

Returns¶


ISize val

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

Returns¶

USize val

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

Returns¶


new iso create(env: Env) =>
_env = env

fun ref apply(timer: Timer, count: U64): Bool =>
_env.out.print(_counter.string())
_counter = _counter + 1
true
```
"""
var _expiration: U64
var _interval: U64
let _notify: TimerNotify
embed _node: ListNode[Timer]

new iso create(
notify: TimerNotify iso,
expiration: U64,
interval: U64 = 0)
=>
"""


fun box sctp_pcb_flags_no_fragment()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_portreuse¶
[Source]


starting with this one. The handler can control which subdirectories are
expanded by removing them from the dir_entries list.
fun val walk(
handler: WalkHandler ref,
follow_links: Bool val = false)
: None val

Parameters¶

handler: WalkHandler ref
follow_links: Bool val = false

Returns¶

None val

canonical¶
[Source]
Return the equivalent canonical absolute path. Raise an error if there


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


push¶
[Source]
Add an element to the ring. If the ring is full, this will drop the oldest
element in the ring. Returns true if an element was dropped.
fun ref push(
value: A)
: Bool val

Parameters¶

value: A

Returns¶

Bool val

clear¶


new create(env: Env) =>
try
(let x, let y) = (env.args(1)?.i32()?, env.args(2)?.i32()?)
env.out.print(disp("x", x))
env.out.print(disp("y", y))
env.out.print(disp("hex(x)", x, FormatHex))
env.out.print(disp("hex(y)", y, FormatHex))
env.out.print(disp("x * y", x * y))
else
let exe = try env.args(0)? else "fmt_example" end
env.err.print("Usage: " + exe + " NUMBER1 NUMBER2")
end

Public Types¶

type Align
primitive AlignCenter
primitive AlignLeft
primitive AlignRight


fun box compare(
that: box->A)
: (Less val | Equal val | Greater val)

Parameters¶

that: box->A

Returns¶

(Less val | Equal val | Greater val)

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

Parameters¶


## Pony's default Integer Arithmetic

Doing arithmetic on integer types in Pony with the well known operators like `+`, `-`, `*`, `/` etc. tries to balance the needs for performance and correctness. All default arithmetic operations do not expose any undefined behaviour or error conditions. That means it handles both the cases for overflow/underflow and division by zero. Overflow/Underflow are handled with proper wrap around semantics, using one's complement on signed integers. In that respect we get behaviour like:

```pony
// unsigned wrap-around on overflow
U32.max_value() + 1 == 0

// signed wrap-around on overflow/underflow
I32.min_value() - 1 == I32.max_value()
```

In pony, the `+=`, `-=`, `*=` and `/=` is deprecated and users must explicitly write `i = i + 1` instead of `i += 1`.

Division by zero is a special case, which affects the division `/` and remainder `%` operators. In Mathematics, division by zero is undefined. In order to avoid either defining division as partial, throwing an error on division by zero or introducing undefined behaviour for that case, the _normal_ division is defined to be `0` when the divisor is `0`. This might lead to silent errors, when used without care. Choose [Partial and checked Arithmetic](#partial-and-checked-arithmetic) to detect division by zero.

In contrast to [Unsafe Arithmetic](#unsafe-integer-arithmetic) default arithmetic comes with a small runtime overhead because unlike the unsafe variants, it does detect and handle overflow and division by zero.

---


: String val

Returns¶

String val

yellow¶
[Source]
Yellow text.
fun box yellow()
: String val

Returns¶

String val

blue¶
[Source]


: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]
fun ref ilong()


fun box ipctl_sendredirects()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipctl_stats¶
[Source]


[Source]
fun box clz()
: B

Returns¶

B

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

Returns¶

B

clz_unsafe¶


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


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


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


conn.write((_destination_host + "\n").array())
conn.write((_destination_service + "\n").array())
wrapped.connected(conn)

fun ref received(conn, data, times) => _wrapped.received(conn, data, times)
fun ref connect_failed(conn: TCPConnection ref) => None

actor tag TCPConnection is
AsioEventNotify tag

Implements¶

AsioEventNotify tag

Constructors¶
create¶
[Source]
Connect via IPv4 or IPv6. If from is a non-empty string, the connection
will be made from the specified interface.


end

fun xfsz(): U32 =>
ifdef linux or bsd or osx then 25
else compile_error "no SIGXFSZ"
end

fun vtalrm(): U32 =>
ifdef linux or bsd or osx then 26
else compile_error "no SIGVTALRM"
end

fun prof(): U32 =>
ifdef linux or bsd or osx then 27
else compile_error "no SIGPROF"
end

fun winch(): U32 =>
ifdef linux or bsd or osx then 28
else compile_error "no SIGWINCH"


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


new val create(
value: A)
: Real[A] val^

Parameters¶

value: A

Returns¶

Real[A] val^

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


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


MicroBenchmark¶
[Source]
Synchronous benchmarks must provide this trait. The apply method defines a
single iteration in a sample. Setup and Teardown are defined by the before
and after methods respectively. The before method runs before a sample
of benchmarks and after runs after the all iterations in the sample have
completed. If your benchmark requires setup and/or teardown to occur beween
each iteration of the benchmark, then you can use before_iteration and
after_iteration methods respectively that run before/after each iteration.
trait iso MicroBenchmark

Public Functions¶
name¶


if _spec.descr().size() > 0 then
w.write("\n")
w.write(_spec.descr() + "\n")
end

let options = _all_options()
if options.size() > 0 then
w.write("\nOptions:\n")
_write_options(w, options)
end
if _spec.commands().size() > 0 then
w.write("\nCommands:\n")
_write_commands(w)
end
let args = _spec.args()
if args.size() > 0 then
w.write("\nArgs:\n")
_write_args(w, args)
end


fun box ipproto_ggp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_gre¶
[Source]


Equatable[A: Equatable[A] #read]¶
[Source]
interface ref Equatable[A: Equatable[A] #read]

Public Functions¶
eq¶
[Source]
fun box eq(
that: box->A)
: Bool val

Parameters¶


FilePermissionDenied¶
[Source]
primitive val FilePermissionDenied

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

Returns¶

FilePermissionDenied val^


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

Parameters¶

y: I64 val

Returns¶

I64 val

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

Parameters¶


assert_array_eq[A: (Equatable[A] #read & Stringable #read)]¶
[Source]
Assert that the contents of the 2 given ReadSeqs are equal.
fun box assert_array_eq[A: (Equatable[A] #read & Stringable #read)](
expect: ReadSeq[A] box,
actual: ReadSeq[A] box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val

Parameters¶

expect: ReadSeq[A] box
actual: ReadSeq[A] box
msg: String val = ""
loc: SourceLoc val = __loc

Returns¶

Bool val


Parameters¶

y: ULong val

Returns¶

ILong val

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

Parameters¶

y: ULong val

Returns¶


: None val ?

Parameters¶

prop: {(T1, T2, T3, T4, PropertyHelper) ?}[T1, T2, T3, T4] val

Returns¶

None val ?


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


* `list_size` - the number of items in the following list of items
as a big-endian 32-bit integer
* zero or more items of the following data:
* a big-endian 64-bit floating point number
* a string that starts with a big-endian 32-bit integer that
specifies the length of the string, followed by a number of
bytes that represent the string

A message would be something like this:

```
[message_length][list_size][float1][string1][float2][string2]...
```

The following program uses a write buffer to encode an array of
tuples as a message of this type:

```pony
use "buffered"


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


U32 val

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

Returns¶

U32 val

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

Returns¶


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


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


Iter[T^](_gen.value_iter(rnd))
.take(size)
)
let shrink_iter: Iterator[Set[T]^] =
Iter[USize](CountdownIter(size, 0)) // Range(size, 0, -1))
//.skip(1)
.map_stateful[Set[T]^]({
(s: USize): Set[T]^ =>
Set[T].create(s).>union(
Iter[T^](_gen.value_iter(rnd)).take(s)
)
})
(consume result, shrink_iter)
end)

fun set_is_of[T](
gen: Generator[T],
max: USize = 100)
: Generator[SetIs[T]]
=>


i: USize val
value: U8 val

Returns¶

U8 val ?

at_offset¶
[Source]
Returns the byte at the given offset. Raise an error if the offset is out
of bounds.
fun box at_offset(
offset: ISize val)
: U8 val ?

Parameters¶

offset: ISize val


seq: (ReadSeq[A] box & ReadElement[A^] box)
offset: USize val = 0
len: USize val = call

Returns¶

None val

concat¶
[Source]
Add len iterated elements to the end of the array, starting from the given
offset.
fun ref concat(
iter: Iterator[A^] ref,
offset: USize val = 0,
len: USize val = call)
: None val

Parameters¶


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

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

primitive F64 is FloatingPoint[F64]
new create(value: F64 = 0) => value
new pi() => 3.14159265358979323846
new e() => 2.71828182845904523536

new _nan() => compile_intrinsic


fun box shr_unsafe(
y: U64 val)
: U64 val

Parameters¶

y: U64 val

Returns¶

U64 val

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

Parameters¶


# Writing to the field of an object

Like reading the field of an object, writing to a field depends on the reference capability of the object reference being stored and the reference capability of the origin object containing the field. The reference capability of the object being stored must not violate the guarantees made by the origin object's reference capability. For example, a `val` object reference can be stored in an `iso` origin. This is because the `val` reference capability guarantees that no alias to that object exists which could violate the guarantees that the `iso` capability makes.

Here's a simplified version of the table above that shows which reference capabilities can be stored in the field of an origin object.

---

| ◁       | `iso` object | `trn` object | `ref` object | `val` object | `box` object | `tag` object |
| -------------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
| __`iso` origin__ | ✔   |            |            | ✔   |            | ✔   |
| __`trn` origin__ | ✔   | ✔   |            | ✔   |            | ✔   |
| __`ref` origin__ | ✔   | ✔   | ✔   | ✔   | ✔   | ✔   |
| __`val` origin__ |            |            |            |            |            |            |
| __`box` origin__ |            |            |            |            |            |            |
| __`tag` origin__ |            |            |            |            |            |            |

---

The bottom half of this chart is empty, since only origins with a mutable capability can have their fields modified.


Poperator[T: T]¶
[Source]
Iterate over a Seq descructively by poping its elements.
Once has_next() returns false, the Seq is empty.
Nominee for the annual pony class-naming awards.
class ref Poperator[T: T] is
Iterator[T^] ref

Implements¶

Iterator[T^] ref


use @tan[F64](x: F64)
use @cosh[F64](x: F64)
use @sinh[F64](x: F64)
use @tanh[F64](x: F64)
use @acos[F64](x: F64)
use @asin[F64](x: F64)
use @atan[F64](x: F64)
use @atan2[F64](x: F64, y: F64)
use @acosh[F64](x: F64)
use @asinh[F64](x: F64)
use @atanh[F64](x: F64)
use @"llvm.copysign.f32"[F32](x: F32, sign: F32)
use @"llvm.copysign.f64"[F64](x: F64, sign: F64)
use @frexp[F64](value: F64, exponent: Pointer[U32])
use @ldexpf[F32](value: F32, exponent: I32)
use @ldexp[F64](value: F64, exponent: I32)

primitive F32 is FloatingPoint[F32]
new create(value: F32 = 0) => value
new pi() => 3.14159265358979323846


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


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

Parameters¶

that: FileExists val

Returns¶

Bool val


132
133
134
135
136
137
138
139
140
141
142"""


actor Main
new create(env: Env) =>
TCPConnection(TCPConnectAuth(env.root),
recover ThrowItAway end, "", "7669")
```

In general, unless you have a very specific use case, we strongly advise that
you don't implement a load shedding scheme where you drop data.


"""
u64_le(data.u64())

fun ref i64_be(data: I64) =>
"""
Write an I64 to the buffer in big-endian byte order.
"""
u64_be(data.u64())

fun ref f64_le(data: F64) =>
"""
Write an F64 to the buffer in little-endian byte order.
"""
u64_le(data.bits())

fun ref f64_be(data: F64) =>
"""
Write an F64 to the buffer in big-endian byte order.
"""
u64_be(data.bits())


auth: DeserialiseAuth val)
: Any iso^ ?

Parameters¶

auth: DeserialiseAuth val

Returns¶

Any iso^ ?

output¶
[Source]
A caller with OutputSerialisedAuth can gain access to the underlying bytes
that contain the serialised data. This can be used to write those bytes to,
for example, a file or socket.
fun box output(
auth: OutputSerialisedAuth val)
: Array[U8 val] val


.run()

Output:
2
4
6

Public Types¶

class Iter


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


fun has_next(): Bool => _pairs.has_next()

fun ref next(): K ? => _pairs.next()?._1

class MapValues[K: Any #share, V: Any #share, H: mut.HashFunction[K] val]
embed _pairs: MapPairs[K, V, H]

new create(m: HashMap[K, V, H]) => _pairs = MapPairs[K, V, H](m)

fun has_next(): Bool => _pairs.has_next()

fun ref next(): val->V ? => _pairs.next()?._2

interface _MapIter[K: Any #share, V: Any #share, H: mut.HashFunction[K] val] is
Iterator[(_MapEntry[K, V, H] | _MapIter[K, V, H])]

class MapPairs[K: Any #share, V: Any #share, H: mut.HashFunction[K] val]
embed _stack: Array[_MapIter[K, V, H]] = []


from_cpointer¶
[Source]
Create an array from a C-style pointer and length. The contents are not
copied. This must be done only with C-FFI functions that return
pony_alloc'd memory. If a null pointer is given then an empty array
is returned.
new ref from_cpointer(
ptr: Pointer[A] ref,
len: USize val,
alloc: USize val = 0)
: Array[A] ref^

Parameters¶

ptr: Pointer[A] ref
len: USize val
alloc: USize val = 0

Returns¶


fun box ipproto_rccmon()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_reserved_253¶
[Source]


(U16 val , U16 val) ?

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

Parameters¶

y: U16 val

Returns¶

U16 val

shr¶
[Source]


fun box sctp_shutdown_ack()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_shutdown_complete¶
[Source]