// by this string and could potentially cause a segfault if we cross
// a pagemap boundary into a pagemap address that hasn't been allocated
// yet when `reserve` is called next.
if _alloc == 0 then
_ptr = Pointer[U8]
else
_ptr = _ptr._offset(offset)
end

fun val trim(from: USize = 0, to: USize = -1): String val =>
"""
Return a shared portion of this string, covering `from` until `to`.
Both the original and the new string are immutable, as they share memory.
The operation does not allocate a new string pointer nor copy elements.
"""
let last = _size.min(to)
let offset = last.min(from)

recover
let size' = last - offset


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


bytes_to_send = pending_total
else
// We have more buffers than a single writev can handle.
// We must iterate over the buffers being sent to add up to the total.
num_to_send = writev_batch_size
bytes_to_send = 0
var counter: I32 = num_sent.i32()
repeat
bytes_to_send = bytes_to_send + _pending_writev(counter.usize())?._2
counter = counter + 1
until counter >= num_to_send end
end

// Write as much data as possible (vectored i/o).
// On Windows only write 1 buffer at a time.
var len = ifdef windows then
@_write(_fd, _pending_writev(num_sent)?._1,
bytes_to_send.i32()).isize()
else
@writev(_fd, _pending_writev.cpointer(num_sent),


fun ref i16(
min: I16 val = call,
max: I16 val = call)
: I16 val

Parameters¶

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

Returns¶

I16 val

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


fun box fstatfs()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

futimesat¶
[Source]


RuntimeOptions¶
[Source]
Pony struct for the Pony runtime options C struct that can be used to
override the Pony runtime defaults via code compiled into the program.
The way this is done is by adding the following function to your Main actor:
fun @runtime_override_defaults(rto: RuntimeOptions) =>

and then overriding the fields of rto (the RuntimeOptions instance) as
needed.
NOTE: Command line arguments still any values set via
@runtime_override_defaults.
The following example overrides the --ponyhelp argument to default it to
true instead of false causing the compiled program to always display


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


## Fields

These are just like fields in C structures or fields in classes in C++, C#, Java, Python, Ruby, or basically any language, really. There are three kinds of fields: `var`, `let`, and `embed` fields. A `var` field can be assigned to over and over again, but a `let` field is assigned to in the constructor and never again. Embed fields will be covered in more detail in the documentation on [variables](/expressions/variables.md).

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

Here, a `Wombat` has a `name`, which is a `String`, and a `_hunger_level`, which is a `U64` (an unsigned 64-bit integer).

__What does the leading underscore mean?__ It means something is __private__. A __private__ field can only be accessed by code in the same type. A __private__ constructor, function, or behaviour can only be accessed by code in the same package. We'll talk more about packages later.


1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286use "collections"

use @pony_asio_event_create[AsioEventID](owner: AsioEventNotify, fd: U32,
flags: U32, nsec: U64, noisy: Bool)
use @pony_asio_event_unsubscribe[None](event: AsioEventID)
use @pony_asio_event_destroy[None](event: AsioEventID)


fun box tcpopt_fast_open()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpopt_multipath¶
[Source]


this % y

fun neg(): A => -this

fun fld(y: A): A
"""
Floored integer division, rounded towards negative infinity.
"""
fun mod(y: A): A
"""
Calculate the modulo after floored integer division, rounded towards negative infinity (`fld`).

The result has the sign of the divisor.
"""

fun eq(y: box->A): Bool => this == y
fun ne(y: box->A): Bool => this != y
fun lt(y: box->A): Bool => this < y
fun le(y: box->A): Bool => this <= y
fun ge(y: box->A): Bool => this >= y


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


# What You Need

To get started, you'll need a text editor and the [ponyc](https://github.com/ponylang/ponyc) compiler. Or if you are on a not supported platform or don't want to install the compiler you can use the [Pony's Playground](https://playground.ponylang.io/).


primitive AmbientAuth
interface Any
class Array
class ArrayKeys
class ArrayPairs
class ArrayValues
primitive AsioEvent
type AsioEventID
trait AsioEventNotify
primitive Bool
type ByteSeq
interface ByteSeqIter
interface Comparable
type Compare
interface DisposableActor
primitive DoNotOptimise
class Env
primitive Equal
interface Equatable
primitive F32


fun box name()
: String val

Returns¶

String val

params¶
[Source]
Returns parameters to customize execution of this Property.
fun box params()
: PropertyParams val

Returns¶

PropertyParams val

gen¶


y: ULong val

Returns¶

ULong val

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

Parameters¶

y: ULong val

Returns¶


Returns¶

U8 val

u16¶
fun box u16()
: U16 val

Returns¶

U16 val

u32¶
fun box u32()
: U32 val

Returns¶


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


that: ASCIILettersUpper val

Returns¶

Bool val

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

Parameters¶

that: ASCIILettersUpper val

Returns¶


Parameters¶

data: ByteSeqIter box

Returns¶

None val

flush¶
[Source]
Flush any queued data
fun ref flush()
: Bool val

Returns¶

Bool val


fun box dso_condata()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dso_cork¶
[Source]


fun box ipv6_prefer_src_public()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_prefer_src_tmp¶
[Source]


fun sctp_get_addr_len():I32 => @pony_os_sockopt_option(I32(622))
fun sctp_get_asoc_vrf():I32 => @pony_os_sockopt_option(I32(623))
fun sctp_get_assoc_id_list():I32 => @pony_os_sockopt_option(I32(624))
fun sctp_get_assoc_number():I32 => @pony_os_sockopt_option(I32(625))
fun sctp_get_local_addresses():I32 => @pony_os_sockopt_option(I32(626))
fun sctp_get_local_addr_size():I32 => @pony_os_sockopt_option(I32(627))
fun sctp_get_nonce_values():I32 => @pony_os_sockopt_option(I32(628))
fun sctp_get_packet_log():I32 => @pony_os_sockopt_option(I32(629))
fun sctp_get_peer_addresses():I32 => @pony_os_sockopt_option(I32(630))
fun sctp_get_peer_addr_info():I32 => @pony_os_sockopt_option(I32(631))
fun sctp_get_remote_addr_size():I32 => @pony_os_sockopt_option(I32(632))
fun sctp_get_sndbuf_use():I32 => @pony_os_sockopt_option(I32(633))
fun sctp_get_stat_log():I32 => @pony_os_sockopt_option(I32(634))
fun sctp_get_vrf_ids():I32 => @pony_os_sockopt_option(I32(635))
fun sctp_had_no_tcb():I32 => @pony_os_sockopt_option(I32(636))
fun sctp_heartbeat_ack():I32 => @pony_os_sockopt_option(I32(637))
fun sctp_heartbeat_request():I32 => @pony_os_sockopt_option(I32(638))
fun sctp_hmac_ident():I32 => @pony_os_sockopt_option(I32(639))
fun sctp_idata():I32 => @pony_os_sockopt_option(I32(640))
fun sctp_iforward_cum_tsn():I32 => @pony_os_sockopt_option(I32(641))


U32 val

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

Returns¶

U64 val

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

Returns¶


# Automatic receiver recovery

When you have an `iso` or `trn` receiver, you normally can't call `ref` methods on it. That's because the receiver is also an argument to a method, which means both the method body and the caller have access to the receiver at the same time. And _that_ means we have to alias the receiver when we call a method on it. The alias of an `iso` is a `tag` (which isn't a subtype of `ref`) and the alias of a `trn` is a `box` (also not a subtype of `ref`).

But we can get around this! If all the arguments to the method (other than the receiver, which is the implicit argument being recovered) _at the call-site_ are __sendable__, and the return type of the method is either __sendable__ or isn't used _at the call-site_, then we can "automatically recover" the receiver. That just means we don't have to alias the receiver - and _that_ means we can call `ref` methods on an `iso` or `trn`, since `iso` and `trn` are both subtypes of `ref`.

Notice that this technique looks mostly at the call-site, rather than at the definition of the method being called. That makes it more flexible. For example, if the method being called wants a `ref` argument, and we pass it an `iso` argument, that's __sendable__ at the call-site, so we can still do automatic receiver recovery.

This may sound a little complicated, but in practice, it means you can write code that treats an `iso` mostly like a `ref`, and the compiler will complain when it's wrong. For example:

```pony
let s = recover String end
s.append("hi")
```

Here, we create a `String iso` and then append some text to it. The append method takes a `ref` receiver and a `box` parameter. We can automatically recover the `iso` receiver since we pass a `val` parameter, so everything is fine.


fun box ipproto_old_divert()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_pfsync¶
[Source]


# Character Literals

Character literals are enclosed with single quotes (`'`).

Character literals, unlike String literals, encode to a single numeric value. Usually this is a single byte, a `U8`. But they can be coerced to any integer type:

```pony
let big_a: U8 = 'A'                 // 65
let hex_escaped_big_a: U8 = '\x41'  // 65
let newline: U32 = '\n'             // 10
```

The following escape sequences are supported:

* `\x4F` hex escape sequence with 2 hex digits (up to `0xFF`)
* `\a`, `\b`, `\e`, `\f`, `\n`, `\r`, `\t`, `\v`, `\\`, `\0`, `\'`


fun box size()
: USize val

Returns¶

USize val

apply¶
[Source]
Returns the i-th element of the list. Errors if the index is out of bounds.
fun box apply(
i: USize val)
: val->A ?

Parameters¶

i: USize val

Returns¶


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

Parameters¶

y: U8 val

Returns¶

(U8 val , Bool val)

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

Parameters¶


ArrayValues[A: A, B: Array[A] #read]¶
[Source]
class ref ArrayValues[A: A, B: Array[A] #read] is
Iterator[B->A] ref

Implements¶

Iterator[B->A] ref

Constructors¶
create¶
[Source]


Returns¶

U8 val

precision10¶
[Source]
Mantissa precision in decimal digits.
fun tag precision10()
: U8 val

Returns¶

U8 val

min_exp2¶
[Source]
Minimum exponent value such that (2^exponent) - 1 is representable at full


Parameters¶

len: USize val

Returns¶

RingBuffer[A] ref^

Public Functions¶
head¶
[Source]
The first read that will succeed. If nothing has been written to the ring,
this will raise an error.
fun box head()
: USize val ?

Returns¶


Both input arrays are isolated and mutable and were originally chopped from
a single array. This function checks that they are indeed two arrays chopped
from the same original array and can be unchopped before doing the
unchopping and returning the unchopped array. If the two arrays cannot be
unchopped it returns both arrays without modifying them.
The operation does not allocate a new array pointer nor copy elements.
fun iso unchop(
b: Array[A] iso)
: ((Array[A] iso^ , Array[A] iso^) | Array[A] iso^)

Parameters¶

b: Array[A] iso

Returns¶

((Array[A] iso^ , Array[A] iso^) | Array[A] iso^)

copy_from[optional B: (A & Real[B] val & U8 val)]¶


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

Parameters¶

y: U32 val

Returns¶

Bool val

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

Parameters¶


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


# Backpressure support


A

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

Parameters¶

y: A

Returns¶

A

shr¶


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

Returns¶

String val

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

Parameters¶


U128 val

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

Returns¶

ULong val

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

Returns¶


new create(env: Env) =>
"""
This is documentation for my create method
"""
None

trait Readable
fun val read()
"""
This is documentation for my unimplemented read method
"""
```


PipeError¶
[Source]
primitive val PipeError

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

Returns¶

PipeError val^


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


fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8_unsafe¶
[Source]


var _destination_service: (None | String) = None
let _wrapped: TCPConnectionNotify iso

new iso create(wrap: TCPConnectionNotify iso, proxy_host: String, proxy_service: String) =>
_wrapped = wrap
_proxy_host = proxy_host
_proxy_service = proxy_service

fun ref proxy_via(host: String, service: String): (String, String) =>
// Stash the original host & service; return the host & service
// for the proxy; indicating that the initial TCP connection should
// be made to the proxy
_destination_host = host
_destination_service = service
(_proxy_host, _proxy_service)

fun ref connected(conn: TCPConnection ref) =>
// conn is the connection to the *proxy* server. We need to ask the
// proxy server to forward this connection to our intended final
// destination.


GitHub("my token").get_repo("ponylang/ponyc")

//
// do something with the repo once the promise is fulfilled
// in our case, get the issue
//

let issue = Promise[Promise[Issue]] =
repo.next[Promise[Issue]](FetchIssue~apply(1))

// once we get the issue, print the title
issue.next[None](PrintIssueTitle~apply(env.out))

primitive FetchIssue
fun apply(number: I64, repo: Repository): Promise[Issue] =>
repo.get_issue(number)

primitive PrintIssueTitle
fun apply(out: OutStream, issue: Promise[Issue]) =>
// O NO! We can't print the title


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


error
end

fun ref update_u8[B: (A & Real[B] val & U8) = A](offset: USize, value: U8): U8 ? =>
"""
Write a U8 at offset. This is only allowed for an array of U8s.
"""
if offset < _size then
_ptr._offset(offset)._convert[U8]()._update(0, value)
else
error
end

fun ref update_u16[B: (A & Real[B] val & U8) = A](offset: USize, value: U16): U16 ? =>
"""
Write a U16 at offset. This is only allowed for an array of U8s.
"""
let u16_bytes = U16(0).bytewidth()
if (offset + u16_bytes) <= _size then
_ptr._offset(offset)._convert[U16]()._update(0, value)


: Promise[B] tag

Parameters¶

fulfill: Fulfill[A, B] iso
rejected: Reject[B] iso = qualify

Returns¶

Promise[B] tag

flatten_next[B: Any #share]¶
[Source]
Chain a promise after this one and unwrap the promise returned from this
one.
flatten_next is a companion to next. It operates in an identical
fashion except for the type of the fulfilled promise. Whereas next takes
a function that returns a type B, flatten_next takes a function that
returns Promise[B].


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


USize val

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

Returns¶

String iso^

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

Parameters¶


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

fun ref f32(min: F32 = 0.0, max: F32 = 1.0): F32 =>
"""
Generate a F32 in closed interval [min, max]
(default: [0.0, 1.0]).
"""
(_random.real().f32() * (max-min)) + min

fun ref f64(min: F64 = 0.0, max: F64 = 1.0): F64 =>
"""
Generate a F64 in closed interval [min, max]
(default: [0.0, 1.0]).
"""
(_random.real() * (max-min)) + min


fun box has_next()
: Bool val

Returns¶

Bool val

prev¶
[Source]
Return the previous node.
fun box prev()
: (this->ListNode[A] ref | None val)

Returns¶

(this->ListNode[A] ref | None val)

next¶


Returns¶

None val ?


compact¶
[Source]
Try to remove unused space, making it available for garbage collection. The
request may be ignored.
fun ref compact()
: None val

Returns¶

None val

undefined[optional B: (A & Real[B] val & (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))]¶
[Source]
Resize to len elements, populating previously empty elements with random
memory. This is only allowed for an array of numbers.
fun ref undefined[optional B: (A & Real[B] val & (I8 val | I16 val | I32 val |
I64 val | I128 val | ILong val |
ISize val | U8 val | U16 val |
U32 val | U64 val | U128 val |


FileMode¶
[Source]
This stores a UNIX-style mode broken out into a Bool for each bit. For other
operating systems, the mapping will be approximate. For example, on Windows,
if the file is readable all the read Bools will be set, and if the file is
writeable, all the write Bools will be set.
The default mode is read/write for the owner, read-only for everyone else.
class ref FileMode

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


out': OutStream tag,
err': OutStream tag,
args': Array[String val] val,
vars': Array[String val] val,
exitcode': {(I32)} val)
: Env val^

Parameters¶

root': AmbientAuth val
input': InputStream tag
out': OutStream tag
err': OutStream tag
args': Array[String val] val
vars': Array[String val] val
exitcode': {(I32)} val

Returns¶

Env val^


let iter =
match that
| let s: HashSet[A, H] => s.values()
| let i: Iterator[A] => i
end
var s' = this
for v in iter do
s' = s' + v
end
s'

fun val op_and(that: (HashSet[A, H] | Iterator[A])): HashSet[A, H] =>
"""
Return a set with the elements that are in both this and that.
"""
let iter =
match that
| let s: HashSet[A, H] => s.values()
| let i: Iterator[A] => i
end


(U16 val , Bool val)

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

Parameters¶

y: U16 val

Returns¶

U16 val ?

mod_unsafe¶
[Source]


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


A

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

Returns¶

A

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

Returns¶


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


fun tcp_ccalgoopt():I32 => @pony_os_sockopt_option(I32(982))
fun tcp_cc_info():I32 => @pony_os_sockopt_option(I32(983))
fun tcp_congestion():I32 => @pony_os_sockopt_option(I32(984))
fun tcp_connectiontimeout():I32 => @pony_os_sockopt_option(I32(985))
fun tcp_connection_info():I32 => @pony_os_sockopt_option(I32(986))
fun tcp_cookie_in_always():I32 => @pony_os_sockopt_option(I32(987))
fun tcp_cookie_max():I32 => @pony_os_sockopt_option(I32(988))
fun tcp_cookie_min():I32 => @pony_os_sockopt_option(I32(989))
fun tcp_cookie_out_never():I32 => @pony_os_sockopt_option(I32(990))
fun tcp_cookie_pair_size():I32 => @pony_os_sockopt_option(I32(991))
fun tcp_cookie_transactions():I32 => @pony_os_sockopt_option(I32(992))
fun tcp_cork():I32 => @pony_os_sockopt_option(I32(993))
fun tcp_defer_accept():I32 => @pony_os_sockopt_option(I32(994))
fun tcp_enable_ecn():I32 => @pony_os_sockopt_option(I32(995))
fun tcp_fastopen():I32 => @pony_os_sockopt_option(I32(996))
fun tcp_function_blk():I32 => @pony_os_sockopt_option(I32(997))
fun tcp_function_name_len_max():I32 => @pony_os_sockopt_option(I32(998))
fun tcp_info():I32 => @pony_os_sockopt_option(I32(999))
fun tcp_keepalive():I32 => @pony_os_sockopt_option(I32(1000))
fun tcp_keepcnt():I32 => @pony_os_sockopt_option(I32(1001))


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


pad: Bool val = false)
: A^

Parameters¶

data: ReadSeq[U8 val] box
pad: Bool val = false

Returns¶

A^

encode[optional A: Seq[U8 val] iso]¶
[Source]
Configurable encoding. The defaults are for RFC 4648.
fun box encode[optional A: Seq[U8 val] iso](
data: ReadSeq[U8 val] box,
at62: U8 val = 43,
at63: U8 val = 47,


FileWrite¶
[Source]
primitive val FileWrite

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

Returns¶

FileWrite val^


end
end

_pending.clear()

var nsec = _next()

if _event.is_null() then
if nsec != -1 then
// Create a new event.
_event =
@pony_asio_event_create(this, 0, AsioEvent.timer(), nsec, true)
end
else
if nsec != -1 then
// Update an existing event.
@pony_asio_event_setnsec(_event, nsec)
else
// Unsubscribe an existing event.
@pony_asio_event_unsubscribe(_event)


MapKeys[K: K, V: V, H: HashFunction[K] val, M: HashMap[K, V, H] #read]¶
[Source]
An iterator over the keys in a map.
class ref MapKeys[K: K, V: V, H: HashFunction[K] val, M: HashMap[K, V, H] #read] is
Iterator[M->K] ref

Implements¶

Iterator[M->K] ref

Constructors¶
create¶


# Anonymous methods

Pony has anonymous methods (or Lambdas). They look like this:

```pony
use "collections"

actor Main
new create(env: Env) =>
let list_of_numbers = List[U32].from([1; 2; 3; 4])
let is_odd = {(n: U32): Bool => (n % 2) == 1}
for odd_number in list_of_numbers.filter(is_odd).values() do
env.out.print(odd_number.string())
end
```

They are presented more in-depth in the [Object Literals section](/expressions/object-literals.md).


actor Stdin is AsioEventNotify
"""
Asynchronous access to stdin. The constructor is private to ensure that
access is provided only via an environment.

Reading from stdin is done by registering an `InputNotify`:

```pony
actor Main
new create(env: Env) =>
// do not forget to call `env.input.dispose` at some point
env.input(
object iso is InputNotify
fun ref apply(data: Array[U8] iso) =>
env.out.write(String.from_iso_array(consume data))

fun ref dispose() =>
env.out.print("Done.")
end,
512)


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


fun box tipc_dest_droppable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_err_no_name¶
[Source]


* async: if true the property is expected to finish asynchronously by calling
`PropertyHelper.complete(...)`
"""
let seed: U64
let num_samples: USize
let max_shrink_rounds: USize
let max_generator_retries: USize
let timeout: U64
let async: Bool

new val create(
num_samples': USize = 100,
seed': U64 = Time.millis(),
max_shrink_rounds': USize = 10,
max_generator_retries': USize = 5,
timeout': U64 = 60_000_000_000,
async': Bool = false)
=>
num_samples = num_samples'
seed = seed'


fun box ipproto_nhrp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_nsp¶
[Source]


HasEq[A: A]¶
[Source]
interface ref HasEq[A: A]

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

Parameters¶


fun box netlink_inet_diag()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_iscsi¶
[Source]


# Fields

In Pony, fields are variables that live within objects. They work like fields in other object-oriented languages.

Fields have the same lifetime as the object they're in, rather than being scoped. They are set up by the object constructor and disposed of along with the object.

If the name of a field starts with `_`, it's __private__. That means only the type the field is in can have code that reads or writes that field. Otherwise, the field is __public__ and can be read or written from anywhere.

Just like local variables, fields can be `var` or `let`. Nevertheless, rules for field assignment differ a bit from variable assignment. No matter the type of the field (either `var` or `let`), either:

1. an initial value has to be assigned in their definition or
2. an initial value has to be assigned in the constructor method.

In the example below, the initial value of the two fields of the class `Wombat` is assigned at the definition level:

```pony
class Wombat
let name: String = "Fantastibat"
var _hunger_level: U32 = 0
```


ANSI¶
[Source]
These strings can be embedded in text when writing to a StdStream to create
a text-based UI.
primitive val ANSI

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

Returns¶


fun box netlink_usersock()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netrom_idle¶
[Source]


I16 val

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

Returns¶

I32 val

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

Returns¶


fun _next(): U64 =>
"""
Return the next time at which the timing wheels should be advanced. This is
adjusted for slop, so it yields nanoseconds. If no events are pending, this
returns -1.
"""
var next: U64 = -1

try
for i in Range(0, _wheels()) do
next = next.min(_wheel(i)?.next(_current))
end
end

if next != -1 then
next = next << _slop.u64()
end

next


fun box ipctl_intrqmaxlen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipctl_maxid¶
[Source]


recover MyTCPConnectionNotify(env.out) end, "", "8989")
```

Note: when writing to the connection data will be silently discarded if the
connection has not yet been established.


port¶
[Source]
Returns port number in host byte order.
fun box port()
: U16 val

Returns¶

U16 val

scope¶
[Source]
Returns IPv6 scope identifier: Unicast, Anycast, Multicast and
unassigned scopes.
fun box scope()
: U32 val

Returns¶


ArrayValues[A, B] ref


Parameters¶

min: A
max: A
inc: A = 1

Returns¶

Range[A] ref^

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

Returns¶


var hour: I32 = 0
var day_of_month: I32 = 1
var month: I32 = 1
var year: I32 = 1970
var day_of_week: I32 = 4
var day_of_year: I32 = 1

new create(seconds: I64 = 0, nanoseconds: I64 = 0) =>
"""
Create a date from a POSIX time. Negative arguments will be changed to zero.
"""
@ponyint_gmtime(this,
_negative_to_zero(seconds),
_negative_to_zero(nanoseconds))

fun time(): I64 =>
"""
Return a POSIX time. Treats the date as UTC.
"""
@ponyint_timegm(this)


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


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


"""
Generator[Bool](
object is GenObj[Bool]
fun generate(rnd: Randomness): Bool =>
rnd.bool()
end)

fun _int_shrink[T: (Int & Integer[T] val)](t: T^, min: T): ValueAndShrink[T] =>
"""
"""
let relation = t.compare(min)
let t_copy: T = T.create(t)
//Debug(t.string() + " is " + relation.string() + " than min " + min.string())
let sub_iter =
object is Iterator[T^]
var _cur: T = t_copy
var _subtract: F64 = 1.0
var _overflow: Bool = false

fun ref _next_minuend(): T =>


[Source]
Copy len elements from src(src_idx) to this(dst_idx).
Only works for Array[U8].
fun ref copy_from[optional B: (A & Real[B] val & U8 val)](
src: Array[U8 val] box,
src_idx: USize val,
dst_idx: USize val,
len: USize val)
: None val

Parameters¶

src: Array[U8 val] box
src_idx: USize val
dst_idx: USize val
len: USize val

Returns¶

None val


_pending_writev.clear()
end

fun ref _seek(offset: I64, base: I32) =>
"""
Move the cursor position.
"""
if _fd != -1 then
let r = ifdef windows then
@_lseeki64(_fd, offset, base)
else
ifdef linux then
@lseek64(_fd, offset, base)
else
@lseek(_fd, offset, base)
end
end
if r < 0 then
_errno = _get_error()
end


return the provided alternate value.
"""
(let i, let found) = _search(key)

if found then
try
_array(i)? as (_, this->V)
else
// This should never happen as we have already
// proven that _array(i) exists
consume alt
end
else
consume alt
end

fun contains(k: box->K!): Bool =>
"""
Checks whether the map contains the key k
"""


If the operation overflows/underflows this function errors.
"""

fun mul_partial(y: A): A ?
"""
Multiply y with this number.

If the operation overflows this function errors.
"""

fun div_partial(y: A): A ?
"""
Divides this number by `y`, rounds the result towards zero.

If y is `0` or the operation overflows, this function errors.
"""

fun rem_partial(y: A): A ?
"""
Calculates the remainder of this number divided by y.


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

Parameters¶

y: box->A

Returns¶

Bool val

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


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


Returns¶

U64 val

eq¶
[Source]
Use the structural equality function from the type parameter.
fun box eq(
x: box->A,
y: box->A)
: Bool val

Parameters¶

x: box->A
y: box->A

Returns¶


ILong val

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

Returns¶

ISize val

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

Returns¶


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


end

be multicast_join(group: String, to: String = "") =>
"""
Add a multicast group. This can be limited to packets arriving on a
specific interface.
"""
if not _closed then
@pony_os_multicast_join(_fd, group.cstring(), to.cstring())
end

be multicast_leave(group: String, to: String = "") =>
"""
Drop a multicast group. This can be limited to packets arriving on a
specific interface. No attempt is made to check that this socket has
previously added this group.
"""
if not _closed then
@pony_os_multicast_leave(_fd, group.cstring(), to.cstring())
end


fun box so_peerlabel()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_peersec¶
[Source]


Parameters¶

y: A

Returns¶

A

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

Parameters¶

y: A

Returns¶


c: U8 val)
: Bool val

Parameters¶

c: U8 val

Returns¶

Bool val

list_sep¶
[Source]
Return the path list separator as a string.
fun box list_sep()
: String val

Returns¶


F64 val

neg_unsafe¶
fun box neg_unsafe()
: F64 val

Returns¶

F64 val

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

Parameters¶

y: F64 val


U16 val

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

Returns¶

U16 val

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


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


Strings package¶
The Strings package provides utilities for working with sequences of strings.
Public Types¶

primitive CommonPrefix


: Writer iso^

Returns¶

Writer iso^

Public Functions¶
reserve_chunks¶
[Source]
Reserve space for size' chunks.
This needs to be recalled after every call to done
as done resets the chunks.
fun ref reserve_chunks(
size': USize val)
: None val

Parameters¶

size': USize val


None

actor Main
new create(env: Env) =>
try
let destination =
DNS.ip4(DNSAuth(env.root), "localhost", "8989")(0)?
UDPSocket(UDPAuth(env.root),
recover MyUDPNotify(env.out, consume destination) end)
end
```
"""
var _notify: UDPNotify
var _fd: U32
var _event: AsioEventID
var _readable: Bool = false
var _closed: Bool = false
var _packet_size: USize
var _read_buf: Array[U8] iso
var _read_from: NetAddress iso = NetAddress


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


fun box ipproto_reserved_253()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_routing¶
[Source]


Pointer[A] tag

usize¶
[Source]
Convert the pointer into an integer.
fun tag usize()
: USize val

Returns¶

USize val

is_null¶
[Source]
Return true for a null pointer, false for anything else.
fun tag is_null()
: Bool val


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

Parameters¶

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

Returns¶

Bool val

partition¶
[Source]
The only partition of the empty list is two empty lists.
fun box partition(
f: {(val->A): Bool}[A] box)
: (Nil[A] val , Nil[A] val)


This stores a UNIX-style mode broken out into a Bool for each bit. For other
operating systems, the mapping will be approximate. For example, on Windows,
if the file is readable all the read Bools will be set, and if the file is
writeable, all the write Bools will be set.

The default mode is read/write for the owner, read-only for everyone else.
"""
var setuid: Bool = false
"""`true` if the SETUID bit is set."""

var setgid: Bool = false
"""`true` if the SETGID bit is set."""

var sticky: Bool = false
"""`true` if the sticky bit is set."""

var owner_read: Bool = true
"""`true` if the owning user can read the file."""

var owner_write: Bool = true


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


"""
let x = _x
var y = _y
let r = x + y

y = x xor y
_x = x.rotl(24) xor y xor (y << 16)
_y = y.rotl(37)
r

class XorOshiro128StarStar is Random
"""
This is an implementation of xoroshiro128**, as detailed at:

http://xoshiro.di.unimi.it/

This Rand implementation is slightly slower than [XorOshiro128Plus](random-XorOshiro128Plus.md)
but does not exhibit "mild dependencies in Hamming weights" (the lower four bits might fail linearity tests).
"""


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

Parameters¶

y: U8 val

Returns¶

U8 val

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

Parameters¶


Returns¶

Iter[B] ref^

all¶
[Source]
Return false if at least one value of the iterator fails to match the
predicate f. This method short-circuits at the first value where the
predicate returns false, otherwise true is returned.
Examples¶
Iter[I64]([2; 4; 6].values())
.all({(x) => (x % 2) == 0 })

true
Iter[I64]([2; 3; 4].values())
.all({(x) => (x % 2) == 0 })

false


152
153
154
155
156
157
158use mut = "collections"

type Set[A: (mut.Hashable val & Equatable[A])] is HashSet[A, mut.HashEq[A]]

type SetIs[A: Any #share] is HashSet[A, mut.HashIs[A]]

class val HashSet[A: Any #share, H: mut.HashFunction[A] val]
is Comparable[HashSet[A, H] box]
"""
A set, built on top of persistent Map. This is implemented as map of an
alias of a type to itself.
"""
let _map: HashMap[A, A, H]


32
33
34
35struct NullablePointer[A]
"""
A NullablePointer[A] is used to encode a possibly-null type. It should
_only_ be used for structs that need to be passed to and from the C FFI.

An optional type for anything that isn't a struct should be encoded as a
union type, for example (A | None).
"""
new create(that: A) =>
"""
This re-encodes the type of `that` from A to NullablePointer[A], allowing
`that` to be assigned to a field or variable of type NullablePointer[A]. It
doesn't allocate a wrapper object: there is no containing object for `that`.
"""
compile_intrinsic

new none() =>


92
93
94
95
96
97
98
99
100
101
102primitive IsPrime[A: (UnsignedInteger[A] val & Unsigned)]
"""
Primality test using 6k ± 1 method.

All integers (excluding 2 and 3), can be expressed as (6k + i),
where i = −1, 0, 1, 2, 3, or 4. Since 2 divides (6k + 0), (6k + 2),
and (6k + 4), while 3 divides (6k + 3) that leaves only (6k - 1) and (6k + 1)
for expressing primes.
"""


// Using a match table like below provides information to LLVM
// to allocate static globals rather than stack or heap allocation.
fun _low_prime_table(index: USize): A val =>
match index
| 0 => 2 | 1 => 3 | 2 => 5 | 3 => 7 | 4 => 11
| 5 => 13 | 6 => 17 | 7 => 19 | 8 => 23 | 9 => 29
| 10 => 31 | 11 => 37 | 12 => 41 | 13 => 43 | 14 => 47
| 15 => 53 | 16 => 59 | 17 => 61 | 18 => 67 | 19 => 71
| 20 => 73 | 21 => 79 | 22 => 83 | 23 => 89 | 24 => 97
| 25 => 101 | 26 => 103 | 27 => 107 | 28 => 109 | 29 => 113
| 30 => 127 | 31 => 131 | 32 => 137 | 33 => 139 | 34 => 149
| 35 => 151 | 36 => 157 | 37 => 163 | 38 => 167 | 39 => 173
| 40 => 179 | 41 => 181 | 42 => 191 | 43 => 193 | 44 => 197
| 45 => 199 | 46 => 211 | 47 => 223 | 48 => 227 | 49 => 229
| 50 => 233 | 51 => 239 | 52 => 241 | 53 => 251 | 54 => 257
| 55 => 263 | 56 => 269 | 57 => 271 | 58 => 277 | 59 => 281
| 60 => 283 | 61 => 293 | 62 => 307 | 63 => 311 | 64 => 313
| 65 => 317 | 66 => 331 | 67 => 337 | 68 => 347 | 69 => 349
| 70 => 353 | 71 => 359 | 72 => 367 | 73 => 373 | 74 => 379
| 75 => 383 | 76 => 389 | 77 => 397 | 78 => 401 | 79 => 409


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


fun ref next()
: val->V ?

Returns¶

val->V ?


end

fun mulc(y: ULong): (ULong, Bool) =>
ifdef ilp32 or llp64 then
(let r, let o) =
@"llvm.umul.with.overflow.i32"(this.u32(), y.u32())
(r.ulong(), o)
else
(let r, let o) =
@"llvm.umul.with.overflow.i64"(this.u64(), y.u64())
(r.ulong(), o)
end

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

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

fun add_partial(y: ULong): ULong ? =>


type FileErrNo is
( FileOK
| FileError
| FileEOF
| FileBadFileNumber
| FileExists
| FilePermissionDenied
)

primitive CreateFile
"""
Open a File for read/write, creating if it doesn't exist, preserving the
contents if it does exist.
"""
fun apply(from: FilePath): (File | FileErrNo) =>
let file = File(from)
let err = file.errno()

match err
| FileOK => file


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349use "collections"

class CommandParser


Create a new timer. The expiration time should be a nanosecond count
until the first expiration. The interval should also be in nanoseconds.
"""
_expiration = expiration + Time.nanos()
_interval = interval
_notify = consume notify
_node = ListNode[Timer]
try _node()? = this end

new abs(notify: TimerNotify, expiration: (I64, I64), interval: U64 = 0) =>
"""
Creates a new timer with an absolute expiration time rather than a relative
time. The expiration time is wall-clock adjusted system time.
"""
_expiration = _abs_expiration_time(expiration)
_interval = interval
_notify = notify
_node = ListNode[Timer]
try _node()? = this end


(ILong val , Bool val)

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

Parameters¶

y: ILong val

Returns¶

(ILong val , Bool val)

divc¶


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

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

Look at the constructor for `TCPConnectAuth`:

```pony
new create(from: (AmbientAuth | NetAuth | TCPAuth))
```

you might notice that this looks like a hierarchy of authorities:

`AmbientAuth >> NetAuth >> TCPAuth >> TCPConnectAuth`


true
```
"""
embed _workers: SetIs[DisposableActor] = _workers.create()

be apply(worker: DisposableActor) =>
"""
Add an actor to be disposed of.
"""
_workers.set(worker)

be remove(worker: DisposableActor) =>
"""
Removes an actor from the set of things to be disposed.
"""
_workers.unset(worker)

be dispose() =>
"""
Dispose of the actors in the set and then clear the set.


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


Bool val

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

Parameters¶

that: FormatGeneral val

Returns¶

Bool val


y: U8 val

Returns¶

U8 val

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

Parameters¶

y: U8 val

Returns¶


TCPAuth¶
[Source]
primitive val TCPAuth

Constructors¶
create¶
[Source]
new val create(
from: (AmbientAuth val | NetAuth val))
: TCPAuth val^

Parameters¶


| 0 => _child_fork(path, argp, envp, wdir, err, stdin, stdout, stderr)
end

fun tag _make_argv(args: Array[String] box): Array[Pointer[U8] tag] =>
"""
Convert an array of String parameters into an array of
C pointers to same strings.
"""
let argv = Array[Pointer[U8] tag](args.size() + 1)
for s in args.values() do
argv.push(s.cstring())
end
argv.push(Pointer[U8]) // nullpointer to terminate list of args
argv

fun _child_fork(
path: String,
argp: Array[Pointer[U8] tag],
envp: Array[Pointer[U8] tag],
wdir: (FilePath | None),


http://xoshiro.di.unimi.it/ and http://gee.cs.oswego.edu/dl/papers/oopsla14.pdf

Using [XorOshiro128StarStar](random-XorOshiro128StarStar.md) or [XorOshiro128Plus](random-XorOshiro128Plus.md)
should be prefered unless using only 64 bit of state is a requirement.
"""
// state
var _x: U64

new from_u64(x: U64 = 5489) =>
_x = x

new create(x: U64 = 5489, y: U64 = 0) =>
"""
Only x is used, y is discarded.
"""
_x = x

fun ref next(): U64 =>
_x = _x + U64(0x9e3779b97f4a7c15)


target: String val)
: Directory iso^ ?

Parameters¶

target: String val

Returns¶

Directory iso^ ?

mkdir¶
[Source]
Creates a directory relative to this one. Returns false if the path is
not within this directory hierarchy or if FileMkdir permission is missing.
fun box mkdir(
target: String val)
: Bool val


type BinaryHeapPriority
interface Flag
class Flags
primitive HashByteSeq
primitive HashEq
primitive HashEq64
interface HashFunction
interface HashFunction64
primitive HashIs
class HashMap
class HashSet
interface Hashable
interface Hashable64
class List
class ListNode
class ListNodes
class ListValues
type Map
type MapIs
class MapKeys


: ISize val

Returns¶

ISize val

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

Parameters¶

n: N

Returns¶


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


: A

Parameters¶

y: A

Returns¶

A

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

Returns¶

A


ULong val

usize¶
[Source]
A random integer in [0, USize.max_value()]
fun ref usize()
: USize val

Returns¶

USize val

i8¶
[Source]
A random integer in [-2^7, 2^7)
fun ref i8()
: I8 val


fun box usize()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64¶
[Source]


end

fun val trim(from: USize = 0, to: USize = -1): Array[A] val =>
"""
Return a shared portion of this array, covering `from` until `to`.
Both the original and the new array are immutable, as they share memory.
The operation does not allocate a new array pointer nor copy elements.
"""
let last = _size.min(to)
let offset = last.min(from)

recover
let size' = last - offset

// use the new size' for alloc if we're not including the last used byte
// from the original data and only include the extra allocated bytes if
// we're including the last byte.
let alloc = if last == _size then _alloc - offset else size' end

if size' > 0 then


992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011


532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547use @"llvm.fabs.f32"[F32](x: F32)
use @"llvm.fabs.f64"[F64](x: F64)
use @"llvm.ceil.f32"[F32](x: F32)
use @"llvm.ceil.f64"[F64](x: F64)
use @"llvm.floor.f32"[F32](x: F32)


# Restrict, then delegate your authority

In order to handle our own code and that of others more safely, and also to understand our code better, we want to split up the authority, and only grant the particular authority a piece of code actually requires.

The first parameter of the `TCPConnection` constructor has the type `TCPConnectAuth`. This is what we call "the most specific authority". All classes in the standard library that require an authority token only accept a single type of token; the token of "most specific authority". In the case of `TCPConnection`, this is `TCPConnectAuth`.

Now imagine we don't trust the `Connect` actor, so we don't want to provide it with more authority than needed. For example, there is no point in granting it filesystem access, since it is supposed to do network things (specifically, TCP), not access the filesystem. Instead of passing the entire `AmbientAuth` (the root of all authority), we "downgrade" that to a `TCPConnectAuth` (the most restrictive authority in `net`), pass it to the `Connect` actor, and have that pass it to the `TCPConnection` constructor:

```pony
actor Connect
new create(out: OutStream, auth: TCPConnectAuth) =>
TCPConnection(auth, MyTCPConnectionNotify(out), "example.com", "80")

actor Main
new create(env: Env) =>
try Connect(env.out, TCPConnectAuth(env.root)) end
```

Now we are sure it cannot access the filesystem or listen on a TCP or UDP port. Pay close mind to the authority that code you are calling is asking for. Never give `AmbientAuth` to __any__ code you do not trust completely both now and in the future. You should always create the most specific authority and give the library that authority. If the library is asking for more authority than it needs, __do not use the library__.


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


"""
"\x1B[30m"

fun red(): String =>
"""
Red text.
"""
"\x1B[31m"

fun green(): String =>
"""
Green text.
"""
"\x1B[32m"

fun yellow(): String =>
"""
Yellow text.
"""
"\x1B[33m"


class iso _PromiseFulFill[A: Any #share, B: Any #share] is Fulfill[A, Promise[B]]
"""
Fulfill discarding its input value of `A` and returning a promise of type `B`.
"""
new iso create() => None
fun ref apply(value: A): Promise[B] => Promise[B]


## Set Up

Any kind of fixture or environment necessary for executing a [UnitTest](pony_test-UnitTest.md)
can be set up either in the tests constructor or in a function called [set_up()](pony_test-UnitTest.md#set_up).

[set_up()](pony_test-UnitTest.md#set_up) is called before the test is executed. It is partial,
if it errors, the test is not executed but reported as failing during set up.
The test's [TestHelper](pony_test-TestHelper.md) is handed to [set_up()](pony_test-UnitTest.md#set_up)
in order to log messages or access the tests [Env](builtin-Env.md) via [TestHelper.env](pony_test-TestHelper.md#let-env-env-val).


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

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

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

trait Property3[T1, T2, T3] is Property1[(T1, T2, T3)]

fun gen1(): Generator[T1]


Returns a copy of the string repeated `num` times.
"""
repeat_str(num)

fun find(s: String box, offset: ISize = 0, nth: USize = 0): ISize ? =>
"""
Return the index of the n-th instance of s in the string starting from the
beginning. Raise an error if there is no n-th occurrence of s or s is empty.
"""
var i = offset_to_index(offset)
var steps = nth + 1

while i < _size do
var j: USize = 0

let same = while j < s._size do
if _ptr._apply(i + j) != s._ptr._apply(j) then
break false
end
j = j + 1


// We don't have an issue, we have a promise for an issue

Take a look at what happens in the example, when we get to
PrintIssueTitle, we can't print anything because we "don't have anything".
In order to print the issue title, we need an Issue not a
Promise[Issue].
We could solve this by doing something like this:
primitive PrintIssueTitle
fun apply(out: OutStream, issue: Promise[Issue]) =>
issue.next[None](ActuallyPrintIssueTitle~apply(out))

primitive ActuallyPrintIssueTitle
fun apply(out: OutStream, issue: Issue) =>
out.print(issue.title())

That will work, however, it is kind of awful. When looking at:
let repo: Promise[Repoository] =
GitHub("my token").get_repo("ponylang/ponyc")
let issue = Promise[Promise[Issue]] =
repo.next[Promise[Issue]](FetchIssue~apply(1))


y: U32 val

Returns¶

U32 val

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

Parameters¶

y: U32 val

Returns¶


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

Parameters¶

y: U32 val

Returns¶

(U32 val , Bool val)

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

Parameters¶


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

Parameters¶

t: U64 val

Returns¶

U64 val

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


: ForAll4[T1, T2, T3, T4] ref^

Parameters¶

gen1': Generator[T1] val
gen2': Generator[T2] val
gen3': Generator[T3] val
gen4': Generator[T4] val
h: TestHelper val

Returns¶

ForAll4[T1, T2, T3, T4] ref^

Public Functions¶
apply¶
[Source]
fun ref apply(
prop: {(T1, T2, T3, T4, PropertyHelper) ?}[T1, T2, T3, T4] val)


U64 val

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

Parameters¶

y: U64 val

Returns¶

U64 val

hash¶
[Source]


# Operator overloading (easy for copy and paste)

```pony
fun add(other: A): A
fun sub(other: A): A
fun mul(other: A): A
fun div(other: A): A
fun rem(other: A): A
fun mod(other: A): A
fun eq(other: A): Bool
fun ne(other: A): Bool
fun lt(other: A): Bool
fun le(other: A): Bool
fun ge(other: A): Bool
fun gt(other: A): Bool
fun shl(other: A): A
fun shr(other: A): A
fun op_and(other:A): A
fun op_or(other: A): A
fun op_xor(othr: A): A


Ini package¶
The Ini package provides support for parsing
INI file formatted text.

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

Example code¶
// Parses the file 'example.ini' in the current working directory
// Output all the content
use "ini"
use "files"


12
13
14
15
16
17
18use "promises"

interface ReadlineNotify
"""
Notifier for readline.
"""
fun ref apply(line: String, prompt: Promise[String]) =>
"""
Receives finished lines. The next prompt is set by fulfilling the promise.
If the promise is rejected, readline will stop handling input.
"""
None

fun ref tab(line: String): Seq[String] box =>


fun box ipv6_unicast_hops()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_use_min_mtu¶
[Source]


y: box->A

Returns¶

Bool val

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

Parameters¶

y: box->A

Returns¶


: String val

Returns¶

String val

option¶
[Source]
Returns the Option by name, defaulting to a fake Option if unknown.
fun box option(
name: String val)
: Option val

Parameters¶

name: String val

Returns¶


y: F64 val

Returns¶

F64 val

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

Parameters¶

y: F64 val

Returns¶


@clock_gettime_nsec_np(_ClockUptimeRaw())
elseif linux or bsd then
var ts = _clock_gettime(_ClockMonotonic)
((ts._1 * 1000000000) + ts._2).u64()
elseif windows then
_subseconds_from_query_performance_counter(1000000000)
else
compile_error "unsupported platform"
end

fun cycles(): U64 =>
"""
Processor cycle count. Don't use this for performance timing, as it does
not control for out-of-order execution.
"""
@"llvm.readcyclecounter"()

fun perf_begin(): U64 =>
"""
Get a cycle count for beginning a performance testing block. This will


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


I128 val ?

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

Parameters¶

y: I128 val

Returns¶

I128 val ?

rem_partial¶
[Source]


U16 val

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

Parameters¶

y: U16 val

Returns¶

U16 val

rotr¶
[Source]


ISize val

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

Returns¶

U8 val

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

Returns¶


fun box so_no_ddp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_np_extensions¶
[Source]


| 0 =>
// System call was successful
| let errno: U32 =>
// System call failed
end

fun ref setsockopt(
level: I32 val,
option_name: I32 val,
option: Array[U8 val] ref)
: U32 val

Parameters¶

level: I32 val
option_name: I32 val
option: Array[U8 val] ref

Returns¶


Parameters¶

h: TestHelper val

Returns¶

None val

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

Parameters¶

h: TestHelper val

Returns¶


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

Returns¶

String val

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

Parameters¶


"""
Returns a 64-bit hash of the address.
"""
usize().hash64()


end
end
this

fun ref skip_while(f: {(A!): Bool ?} box): Iter[A!]^ =>
"""
Skip values of the iterator while the predicate `f` returns true.


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


A

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

Returns¶

String iso^

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

Parameters¶


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


: U16 val ?

Returns¶

U16 val ?

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

Returns¶

I16 val ?

i16_le¶
[Source]


ProcessError¶
[Source]
class val ProcessError

Constructors¶
create¶
[Source]
new val create(
error_type': (ExecveError val | PipeError val | ForkError val |
WaitpidError val | WriteError val | KillError val |
CapError val | ChdirError val | UnknownError val),
message': (String val | None val) = reference)
: ProcessError val^


"""
Creates the directory. Will recursively create each element. Returns true
if the directory exists when we're done, false if it does not. If we do not
have the FileStat permission, this will return false even if the directory
does exist.
"""
if not caps(FileMkdir) then
return false
end

var offset: ISize = 0

repeat
let element = try
offset = path.find(Path.sep(), offset)? + 1
path.substring(0, offset - 1)
else
offset = -1
path
end


be _run_finished(round: _Round) =>
if not _params.async and _pass then
// otherwise complete_run has already been called
complete_run(round, true)
end

// SHRINKING //

be complete_shrink(failed_repr: String, last_repr: String, shrink_round: _Round, success: Bool) =>

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

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

if success then


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

Parameters¶

iter: Iterator[A^] ref
offset: USize val = 0
len: USize val = call

Returns¶

None val

values¶
[Source]


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


U64 val ?

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

Returns¶

U64 val ?

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


fun ref dispose() =>
env.out.print("Done.")
end,
512)

Note: For reading user input from a terminal, use the term package.
actor tag Stdin is
AsioEventNotify tag

Implements¶

AsioEventNotify tag

Public Behaviours¶
apply¶
[Source]
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 apply(


fun box recv()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

setsockopt¶
[Source]


fun box ip_max_group_src_filter()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_max_sock_mute_filter¶
[Source]


len: USize val

Returns¶

String iso^

print¶
[Source]
Same as write, buts adds a newline.
fun ref print(
data: (String box | Array[U8 val] box))
: Bool val

Parameters¶

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

Returns¶


"""
This returns a null pointer typed as a NullablePointer[A].
"""
compile_intrinsic

fun apply(): this->A ? =>
"""
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.
"""
compile_intrinsic

fun is_none(): Bool =>
"""
Returns true if `this` is null (ie apply would raise an error).
"""
compile_intrinsic


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387use "time"
use "signals"
use @ioctl[I32](fx: I32, cmd: ULong, ...) if posix

struct _TermSize


argument, expecting a null-terminator. If the underlying string
is already null terminated, this is returned; otherwise the string
is copied into a new, null-terminated allocation.
fun box cstring()
: Pointer[U8 val] tag

Returns¶

Pointer[U8 val] tag

array¶
[Source]
Returns an Array[U8] that reuses the underlying data pointer.
fun val array()
: Array[U8 val] val

Returns¶

Array[U8 val] val


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


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128_unsafe¶
[Source]


USize val

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

Parameters¶

y: USize val

Returns¶

USize val

addc¶
[Source]


that: WriteError val

Returns¶

Bool val

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

Parameters¶

that: WriteError val

Returns¶


: None val

Parameters¶

name: String val

Returns¶

None val

fail_action¶
[Source]
Mark an expected action as failed.
If all expected actions are completed successfully,
the property is considered successful.
If 1 action fails, the property is considered failing.
fun val fail_action(
name: String val)
: None val


is_prime.pony

1
2
3
4
5
6
7
8
9
10
11


fun box tcp_vendor()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_addr_id¶
[Source]


I8 val

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

Parameters¶

y: I8 val

Returns¶

I8 val

mod¶
[Source]


Returns¶

U64 val

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

Parameters¶

t: F64 val

Returns¶

U64 val


service: String,
from: String = "",
read_buffer_size: USize = 16384,
yield_after_reading: USize = 16384,
yield_after_writing: USize = 16384)
=>
"""
Connect via IPv4 or IPv6. If `from` is a non-empty string, the connection
will be made from the specified interface.
"""
_read_buf = recover Array[U8] .> undefined(read_buffer_size) end
_read_buffer_size = read_buffer_size
_yield_after_reading = yield_after_reading
_yield_after_writing = yield_after_writing
_notify = consume notify
let asio_flags =
ifdef not windows then
AsioEvent.read_write_oneshot()
else
AsioEvent.read_write()


I16 val

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

Returns¶

I32 val

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

Returns¶


n: USize = USize.max_value())
: Array[String] iso^
=>
"""
Split the string into an array of strings that are delimited by `delim` in
the original string. If `n > 0`, then the split count is limited to n.

Example:

```pony
let original: String = "Hello!"
let delimiter: String = "><"
let split_array: Array[String] = original.split_by(delimiter)
env.out.print("OUTPUT:")
for value in split_array.values() do
env.out.print(value)
end

// OUTPUT:
// <b


align: (AlignLeft val | AlignRight val | AlignCenter val) = reference,
fill: U32 val = 32)
: String iso^

Parameters¶

x: A
fmt: (FormatDefault val | FormatUTF32 val | FormatBinary val |
FormatBinaryBare val | FormatOctal val | FormatOctalBare val |
FormatHex val | FormatHexBare val | FormatHexSmall val |
FormatHexSmallBare val) = reference
prefix: (PrefixDefault val | PrefixSpace val | PrefixSign val) = reference
prec: USize val = call
width: USize val = 0
align: (AlignLeft val | AlignRight val | AlignCenter val) = reference
fill: U32 val = 32

Returns¶

String iso^


U64 val ?

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

Parameters¶

y: U64 val

Returns¶

U64 val ?

divrem_partial¶
[Source]


# Variables

Like most other programming languages Pony allows you to store data in variables. There are a few different kinds of variables which have different lifetimes and are used for slightly different purposes.


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

Returns¶

F32 val

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

Returns¶

F32 val


fun box tcpolen_sack()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpolen_sack_permitted¶
[Source]


_stderr = _Pipe.incoming()?
else
_stdin.close()
_stdout.close()
_stderr.close()
_notifier.failed(this, ProcessError(PipeError,
"Failed to open pipe for stderr."))
return
end

try
_err = _Pipe.incoming()?
else
_stdin.close()
_stdout.close()
_stderr.close()
_err.close()
_notifier.failed(this, ProcessError(PipeError,
"Failed to open auxiliary error pipe."))
return


: None val

Parameters¶

that: List[A] ref

Returns¶

None val

push¶
[Source]
Adds a new tail value.
let my_list = List[String].from(["a"; "b"; "c"])
my_list.push("d")  // my_list is ["a"; "b"; "c"; "d"]

fun ref push(
a: A)
: None val


Parameters¶

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

Returns¶

Bool val

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


IniError¶
[Source]
type IniError is
(IniIncompleteSection val | IniNoDelimiter val)

Type Alias For¶

(IniIncompleteSection val | IniNoDelimiter val)


This is what the example shown before looks like but with any reference capability accepted:

```pony
// Note - this won't compile
class Foo[A]
var _c: A

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

fun get(): A => _c

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

actor Main
new create(env:Env) =>
let a = Foo[U32](42)
env.out.print(a.get().string())
a.set(21)
env.out.print(a.get().string())


fun box ipv6_recverr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_recvhopopts¶
[Source]


primitive PrefixDefault
type PrefixNumber
primitive PrefixSign
primitive PrefixSpace
trait PrefixSpec


fun box sctp_lock_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_log_at_send_2_sctp¶
[Source]


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

Parameters¶

y: I16 val

Returns¶

I16 val

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

Parameters¶


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


fun box sock_seqpacket()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

somaxconn¶
[Source]


# Complex types

If a type is complicated, it can be nice to give it a mnemonic name. For example, if we want to say that a type must implement more than one interface, we could say:

```pony
interface HasName
fun name(): String

interface HasAge
fun age(): U32

interface HasFeelings
fun feeling(): String

type Person is (HasName & HasAge & HasFeelings)
```

This use of complex types applies to traits, not just interfaces:

```pony


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


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


m: HashMap[K, V, H] val

Returns¶

MapValues[K, V, H] ref^

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

Returns¶

Bool val

next¶
[Source]


Returns¶

Bool val

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

Parameters¶

that: MinHeapPriority[A] val

Returns¶

Bool val


Fact val^

Public Functions¶
apply¶
[Source]
fun box apply(
test: Bool val,
msg: String val = "")
: None val ?

Parameters¶

test: Bool val
msg: String val = ""

Returns¶

None val ?


fun box ctz_unsafe()
: U32 val

Returns¶

U32 val

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

Returns¶

U32 val

bytewidth¶
[Source]


ILong val

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

Parameters¶

y: ILong val

Returns¶

ILong val

op_xor¶


TCPConnectionNotify¶
[Source]
Notifications for TCP connections.
For an example of using this class please see the documentation for the
TCPConnection and TCPListener actors.
interface ref TCPConnectionNotify

Public Functions¶
accepted¶
[Source]
Called when a TCPConnection is accepted by a TCPListener.
fun ref accepted(
conn: TCPConnection ref)


# Hello World -- How It Works

Let's look at our `helloworld` code again:

```pony
actor Main
new create(env: Env) =>
env.out.print("Hello, world!")
```

Let's go through that line by line.


fun box ip_pmtudisc_do()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_pmtudisc_interface¶
[Source]


```

Repeated use of a single operator, however, is fine:

```pony
1 + 2 + 3  // 6
```

Meanwhile, mixing unary and infix operators do not need additional parentheses as unary operators always bind more closely, so if our example above used a negative three:

```pony
1 + 2 * -3  // Compilation failed.
```

We would still need parentheses to remove the ambiguity for our infix operators like we did above, but not for the unary arithmetic negative (`-`):

```pony
1 + (2 * -3)  // -5
```


y: U8 val

Returns¶

U8 val

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

Parameters¶

y: U8 val

Returns¶


U32 val

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

Returns¶

U64 val

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

Returns¶


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


Bool val

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

Parameters¶

that: PrefixSpace val

Returns¶

Bool val


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


# Loops

`if` allows you to choose what to do, but in order to do something more than once, you want a loop.


for i in Range(0, data.size()) do
input = data(i)?

let value =
match input
| ' ' | '\t' | '\r' | '\n' => continue
| pad => break
| at62 => 62
| at63 => 63
| if (input >= 'A') and (input <= 'Z') =>
(input - 'A')
| if (input >= 'a') and (input <= 'z') =>
((input - 'a') + 26)
| if (input >= '0') and (input <= '9') =>
((input - '0') + 52)
else
error
end

match state


if n <= 1 then
"\x1B[C"
else
"\x1B[" + n.string() + "C"
end

fun left(n: U32 = 0): String =>
"""
Move the cursor left n columns. 0 is the same as 1.
"""
if n <= 1 then
"\x1B[D"
else
"\x1B[" + n.string() + "D"
end

fun cursor(x: U32 = 0, y: U32 = 0): String =>
"""
Move the cursor to line y, column x. 0 is the same as 1. This indexes from
the top left corner of the screen.


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


notify: UDPNotify iso
host: String val = ""
service: String val = "0"
size: USize val = 1024

Returns¶

UDPSocket tag^

ip6¶
[Source]
Listens for IPv6 datagrams.
new tag ip6(
auth: UDPAuth val,
notify: UDPNotify iso,
host: String val = "",
service: String val = "0",
size: USize val = 1024)
: UDPSocket tag^


"""
Get a big-endian I16.
"""
u16_be()?.i16()

fun ref i16_le(): I16 ? =>
"""
Get a little-endian I16.
"""
u16_le()?.i16()

fun ref u32_be(): U32 ? =>
"""
Get a big-endian U32.
"""
let num_bytes = U32(0).bytewidth()
if _available >= num_bytes then
let node = _chunks.head()?
(var data, var offset) = node()?
if (data.size() - offset) >= num_bytes then


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


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


"""
data

fun ref sentv(conn: TCPConnection ref, data: ByteSeqIter): ByteSeqIter =>
"""
Called when multiple chunks of data are sent to the connection in a single
call. This gives the notifier an opportunity to modify the sent data chunks
before they are written. To swallow the send, return an empty
Array[String].
"""
data

fun ref received(
conn: TCPConnection ref,
data: Array[U8] iso,
times: USize)
: Bool
=>
"""
Called when new data is received on the connection. Return true if you


fun box sctp_events()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_flight_logging_enable¶
[Source]


fun box local_address()
: NetAddress val

Returns¶

NetAddress val

close¶
[Source]
Dispose of resources.
fun ref close()
: None val

Returns¶

None val


### Example
```pony
Iter[USize](Range(0, 10))
.step_by(2)
```
`1 3 5 7 9`
"""
Iter[A!](
object is Iterator[A!]
let _step: USize = if n == 0 then 1 else n end

fun ref has_next(): Bool =>
_iter.has_next()

fun ref next(): A! ? =>
var steps_to_burn: USize = _step - 1
while steps_to_burn != 0 do
try _iter.next()? end
steps_to_burn = steps_to_burn - 1
end


fun string(): String iso^
"""
Generate a string representation of this object.
"""


```

**Note:** For reading user input from a terminal, use the [term](term--index.md) package.
"""
var _notify: (InputNotify | None) = None
var _chunk_size: USize = 32
var _event: AsioEventID = AsioEvent.none()
let _use_event: Bool

new _create(use_event: Bool) =>
"""
Create an asynchronous stdin provider.
"""
_use_event = use_event

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


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

Parameters¶

y: I8 val

Returns¶

I8 val

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

Parameters¶


AsioEvent val^

Public Functions¶
none¶
[Source]
An empty event.
fun box none()
: Pointer[AsioEvent val] tag

Returns¶

Pointer[AsioEvent val] tag

readable¶
[Source]
Returns true if the flags contain the readable flag.
fun box readable(
flags: U32 val)


1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331


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

Parameters¶

y: ISize val

Returns¶

(ISize val , ISize val)

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


U64 val

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

Parameters¶

y: U64 val

Returns¶

U64 val

fldc¶
[Source]


random.pony

1
2
3
4
5
6
7
8
9
10
11


y: U128 val

Returns¶

(U128 val , Bool val)

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

Parameters¶

y: U128 val

Returns¶


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


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


x: U32 val = 0
y: U32 val = 0

Returns¶

String val

clear¶
[Source]
Clear the screen and move the cursor to the top left corner.
fun box clear()
: String val

Returns¶

String val

erase¶


if _size > 0 then
let chars = Array[U32](s.size())
var i = _size - 1
var truncate_at = _size

for rune in s.runes() do
chars.push(rune)
end

repeat
try
match utf32(i.isize())?
| (0xFFFD, 1) => None
| (let c: U32, _) =>
if not chars.contains(c) then
break
end
truncate_at = i
end
else


end

fun hash(): USize =>
@ponyint_hash_block(_ptr, _size)

fun hash64(): U64 =>
@ponyint_hash_block64(_ptr, _size)

fun string(): String iso^ =>
clone()

fun values(): StringBytes^ =>
"""
Return an iterator over the bytes in the string.
"""
StringBytes(this)

fun runes(): StringRunes^ =>
"""
Return an iterator over the codepoints in the string.


TCPListenNotify¶
[Source]
Notifications for TCP listeners.
For an example of using this class, please see the documentation for the
TCPListener actor.
interface ref TCPListenNotify

Public Functions¶
listening¶
[Source]
Called when the listener has been bound to an address.
fun ref listening(
listen: TCPListener ref)


observe¶
[Source]
Prevent the compiler from optimising out writes to an object marked by
the apply function.
fun box observe()
: None val

Returns¶

None val

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


from: (AmbientAuth val | NetAuth val)

Returns¶

UDPAuth val^

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

Parameters¶

that: UDPAuth val

Returns¶


Returns¶

None val

contains¶
[Source]
Check that this is a superset of the rights in that.
fun box contains(
that: CapRights0 ref)
: Bool val

Parameters¶

that: CapRights0 ref

Returns¶

Bool val


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


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


1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571


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


i128¶
fun ref i128()
: I128 val

Returns¶

I128 val

ilong¶
fun ref ilong()
: ILong val

Returns¶

ILong val

isize¶
fun ref isize()


Returns¶

Flags[A, B] iso^

clone¶
[Source]
Create a clone.
fun box clone()
: Flags[A, B] iso^

Returns¶

Flags[A, B] iso^

eq¶
[Source]
Returns true if this has the same flags set as that.
fun box eq(


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


Float¶
[Source]
type Float is
(F32 val | F64 val)

Type Alias For¶

(F32 val | F64 val)


ptr._update(_size, 0)
ptr

fun val array(): Array[U8] val =>
"""
Returns an Array[U8] that reuses the underlying data pointer.
"""
recover
Array[U8].from_cpointer(_ptr._unsafe(), _size, _alloc)
end

fun iso iso_array(): Array[U8] iso^ =>
"""
Returns an Array[U8] iso that reuses the underlying data pointer.
"""
recover
Array[U8].from_cpointer(_ptr._unsafe(), _size, _alloc)
end

fun size(): USize =>


DebugOut¶
[Source]
primitive val DebugOut

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

Returns¶

DebugOut val^


92
93
94
95
96"""


_final_wait_result = exit_status
_notifier.dispose(this, exit_status)
_dispose_timers()
| let wpe: WaitpidError =>
_final_wait_result = wpe
_notifier.failed(this, ProcessError(WaitpidError))
_dispose_timers()
end
end

fun ref _ensure_timers(): Timers tag =>
match _timers
| None =>
let ts = Timers
_timers = ts
ts
| let ts: Timers => ts
end

fun ref _dispose_timers() =>


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


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


if (a and 4) != 0 then
a = a or 1
end

a = (a + 1) >> 2

if (a and (1 << 53)) != 0 then
a = a >> 1
e = e + 1
end
else
a = a << (53 - sd)
end

F64.from_bits(((e + 1023) << 52) or (a.u64() and 0xF_FFFF_FFFF_FFFF))

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


AlignRight¶
[Source]
primitive val AlignRight

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

Returns¶

AlignRight val^


Returns¶

U8 val

precision10¶
[Source]
Mantissa precision in decimal digits.
fun tag precision10()
: U8 val

Returns¶

U8 val

min_exp2¶
[Source]
Minimum exponent value such that (2^exponent) - 1 is representable at full


fun box netlink_firewall()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_inet_diag¶
[Source]


y: USize val

Returns¶

USize val

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

Parameters¶

y: USize val

Returns¶


1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046use "collections"

class Iter[A] is Iterator[A]
"""
Wrapper class containing methods to modify iterators.
"""


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


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

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

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

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

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

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

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


if (offset + u64_bytes) <= _size then
_ptr._offset(offset)._convert[U64]()._update(0, value)
else
error
end

fun ref update_u128[B: (A & Real[B] val & U8) = A](offset: USize, value: U128): U128 ? =>
"""
Write a U128 at offset. This is only allowed for an array of U8s.
"""
let u128_bytes = U128(0).bytewidth()
if (offset + u128_bytes) <= _size then
_ptr._offset(offset)._convert[U128]()._update(0, value)
else
error
end

fun ref update(i: USize, value: A): A^ ? =>
"""
Change the i-th element, raising an error if the index is out of bounds.


fun ref i8(
min: I8 val = call,
max: I8 val = call)
: I8 val

Parameters¶

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

Returns¶

I8 val

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


fun box sctp_cc_opt_steady_step()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cc_rfc2581¶
[Source]


FileRename¶
[Source]
primitive val FileRename

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

Returns¶

FileRename val^


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


Bool val

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

Parameters¶

y: ULong val

Returns¶

Bool val

hash64¶
[Source]


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

Parameters¶

that: FileOK val

Returns¶

Bool val


FileCaps¶
[Source]
type FileCaps is
Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] ref

Type Alias For¶

Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] ref


Bool val


492
493
494
495
496
497
498use "backpressure"
use "collections"
use "files"
use "time"

actor ProcessMonitor is AsioEventNotify
"""
Fork+execs / creates a child process and monitors it. Notifies a client about
STDOUT / STDERR events.
"""
let _notifier: ProcessNotify
let _backpressure_auth: ApplyReleaseBackpressureAuth

var _stdin: _Pipe = _Pipe.none()


y: U64 val

Returns¶

U64 val

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

Parameters¶

y: U64 val

Returns¶


that: WaitpidError val

Returns¶

Bool val

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

Parameters¶

that: WaitpidError val

Returns¶


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


[Source]
Get a big-endian I129.
fun ref i128_be()
: I128 val ?

Returns¶

I128 val ?

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

Returns¶

I128 val ?


# Behaviours

A __behaviour__ is like a __function__, except that functions are _synchronous_ and behaviours are _asynchronous_. In other words, when you call a function, the body of the function is executed immediately, and the result of the call is the result of the body of the function. This is just like method invocation in any other object-oriented language.

But when you call a behaviour, the body is __not__ executed immediately. Instead, the body of the behaviour will execute at some indeterminate time in the future.

A behaviour looks like a function, but instead of being introduced with the keyword `fun`, it is introduced with the keyword `be`.

Like a function, a behaviour can have parameters. Unlike a function, it doesn't have a receiver capability (a behaviour can be called on a receiver of any capability) and you can't specify a return type.

__So what does a behaviour return?__ Behaviours always return `None`, like a function without explicit result type, because they can't return something they calculate (since they haven't run yet).

```pony
actor Aardvark
let name: String
var _hunger_level: U64 = 0

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


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


value.rstrip()
end
end

if not f(section, consume current, consume value) then
return ok
end
else
ok = false

if not f.errors(lineno, IniNoDelimiter) then
return false
end
end
end
end
end
ok


_start_time = 0
_bench.before_iteration(_before_iteration_cont)

be _before_iteration_done_cont(e: U64) =>
_run_iteration()

be _run_iteration() =>
try
_n = _n + 1
_gc_next_behavior()
_start_time = Time.nanos()
_bench(_iteration_cont)?
else
_fail()
end

be _iteration_done_cont(e: U64) =>
_a = _a + (e - _start_time)
_bench.after_iteration(_after_iteration_cont)


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


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


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


source: FilePath val
link_name: String val

Returns¶

Bool val

remove¶
[Source]
Remove the file or directory. The directory contents will be removed as
well, recursively. Symlinks will be removed but not traversed.
fun box remove(
target: String val)
: Bool val

Parameters¶

target: String val


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128_unsafe¶
[Source]


FileMkdir¶
[Source]
primitive val FileMkdir

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

Returns¶

FileMkdir val^


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


# How to use the `cli` package to parse command line arguments

```pony
use "cli"

actor Main
new create(env: Env) =>
let command_spec =
try
CommandSpec.leaf(
"pony-embed",
"sample program",
[ OptionSpec.string("output", "output filename", 'o') ],
[ ArgSpec.string("input", "source of input" where default' = "-") ]
)? .> add_help()?
else
env.exitcode(1)
return
end
let command =


Returns¶

Generator[(T | U)] box

iter¶
[Source]
fun box iter(
rnd: Randomness ref)
: Iterator[(T^ | (T^ , Iterator[T^] ref))] ref^

Parameters¶

rnd: Randomness ref

Returns¶

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


common_prefix.pony

1
2
3
4
5
6
7
8
9
10
11


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


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


and then overriding the fields of `rto` (the `RuntimeOptions` instance) as
needed.

NOTE: Command line arguments still any values set via
`@runtime_override_defaults`.

The following example overrides the `--ponyhelp` argument to default it to
`true` instead of `false` causing the compiled program to always display
the Pony runtime help:

```
actor Main
new create(env: Env) =>
env.out.print("Hello, world.")

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


fun box shr_unsafe(
y: U16 val)
: I16 val

Parameters¶

y: U16 val

Returns¶

I16 val

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

Returns¶


fun box sctp_ecn_cwr()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_ecn_supported¶
[Source]


92
93
94
95
96
97
98
99
100
101class MT is Random
"""
A Mersenne Twister. This is a non-cryptographic random number generator. This
should only be used for legacy applications that require a Mersenne Twister,
otherwise use Rand.
"""
embed _state: Array[U64]
var _index: USize

new create(x: U64 = 5489, y: U64 = 0) =>
"""


Set the cursor position relative to the end of the file.
fun ref seek_end(
offset: USize val)
: None val

Parameters¶

offset: USize val

Returns¶

None val

seek¶
[Source]
Move the cursor position.
fun ref seek(
offset: ISize val)
: None val


Parameters¶

y: A

Returns¶

A ?

rem_partial¶
[Source]
Calculates the remainder of this number divided by y.
The result has the sign of the dividend.
If y is 0 or the operation overflows, this function errors.
fun box rem_partial(
y: A)
: A ?

Parameters¶


fun ipproto_ggp():I32 => @pony_os_sockopt_level(I32(4031))
fun ipproto_gmtp():I32 => @pony_os_sockopt_level(I32(4032))
fun ipproto_gre():I32 => @pony_os_sockopt_level(I32(4033))
fun ipproto_hello():I32 => @pony_os_sockopt_level(I32(4034))
fun ipproto_hip():I32 => @pony_os_sockopt_level(I32(4035))
fun ipproto_hmp():I32 => @pony_os_sockopt_level(I32(4036))
fun ipproto_hopopts():I32 => @pony_os_sockopt_level(I32(4037))
fun ipproto_icmp():I32 => @pony_os_sockopt_level(I32(4038))
fun ipproto_icmpv6():I32 => @pony_os_sockopt_level(I32(4039))
fun ipproto_idp():I32 => @pony_os_sockopt_level(I32(4040))
fun ipproto_idpr():I32 => @pony_os_sockopt_level(I32(4041))
fun ipproto_idrp():I32 => @pony_os_sockopt_level(I32(4042))
fun ipproto_igmp():I32 => @pony_os_sockopt_level(I32(4043))
fun ipproto_igp():I32 => @pony_os_sockopt_level(I32(4044))
fun ipproto_igrp():I32 => @pony_os_sockopt_level(I32(4045))
fun ipproto_il():I32 => @pony_os_sockopt_level(I32(4046))
fun ipproto_inlsp():I32 => @pony_os_sockopt_level(I32(4047))
fun ipproto_inp():I32 => @pony_os_sockopt_level(I32(4048))
fun ipproto_ip():I32 => @pony_os_sockopt_level(I32(4049))
fun ipproto_ipcomp():I32 => @pony_os_sockopt_level(I32(4050))


## String Literal Instances

When a single string literal is used several times in your Pony program, all of them will be converted to a single common instance. This means they will always be equal based on identity.

```pony
let pony = "🐎"
let another_pony = "🐎"
if pony is another_pony then
// True, therefore this line will run.
end
```


be dispose() =>
"""
Stop accepting input, inform the notifier we have closed, and dispose of
our source.
"""
if not _closed then
_esc_clear()
_notify.closed()
_source.dispose()
_closed = true
end

be _timeout() =>
"""
Our timer since receiving an ESC has expired. Send the buffered data as if
it was not an escape sequence.
"""
_timer = None
_esc_flush()


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


Bool val

oneshotable¶
[Source]
Returns true if the flags contain the oneshot flag.
fun box oneshotable(
flags: U32 val)
: Bool val

Parameters¶

flags: U32 val

Returns¶

Bool val

dispose¶


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


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


class iso _Nothing is MicroBenchmark
// Benchmark absolutely nothing.
fun name(): String => "Nothing"

fun apply() =>
// prevent compiler from optimizing out this operation
DoNotOptimise[None](None)
DoNotOptimise.observe()

class iso _Fib is MicroBenchmark
// Benchmark non-tail-recursive fibonacci
let _n: U64

new iso create(n: U64) =>
_n = n

fun name(): String =>
"_Fib(" + _n.string() + ")"

fun apply() =>


}
```

`sqlite3_callback` is the type of the callback function that will be called by `sqlite3_exec` for each row returned by the `sql` statement. The first argument to the callback function is the pointer `pArg` that was passed to `sqlite3_exec`, the second argument is the number of columns in the row being processed, the third argument is data for each column, and the fourth argument is the name of each column.

Here's the skeleton of some Pony code that uses `sqlite3_exec` to query an SQLite database, with examples of both the bare method way and the bare lambda way:

```pony
use @sqlite3_exec[I32](db: Pointer[None] tag, sql: Pointer[U8] tag,
callback: Pointer[None], data: Pointer[None], err_msg: Pointer[Pointer[U8] tag] tag)

class SQLiteClient
fun client_code() =>
...
@sqlite3_exec(db, sql.cstring(), addressof this.method_callback,
this, addressof zErrMsg)
...

fun @method_callback(client: SQLiteClient, argc: I32,
argv: Pointer[Pointer[U8]], azColName: Pointer[Pointer[U8]]): I32


I8 val

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

Parameters¶

y: U8 val

Returns¶

I8 val

shr_unsafe¶
[Source]


Bool val

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

Parameters¶

that: Nil[A] val

Returns¶

Bool val


fun box ip_recvopts()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_recvpktinfo¶
[Source]


(let t21, let t2_shrunken) = gen2.shrink(consume t2)
(let t31, let t3_shrunken) = gen3.shrink(consume t3)
(let t41, let t4_shrunken) = gen4.shrink(consume t4)

let shrunken = Iter[T1^](t1_shrunken)
.zip3[T2^, T3^, T4^](t2_shrunken, t3_shrunken, t4_shrunken)
((consume t11, consume t21, consume t31, consume t41), shrunken)
end)

fun map2[T1, T2, T3](
gen1: Generator[T1],
gen2: Generator[T2],
fn: {(T1, T2): T3^})
: Generator[T3]
=>
"""
Convenience combinator for mapping 2 generators into 1.
"""
Generators.zip2[T1, T2](gen1, gen2)
.map[T3]({(arg) =>


U32 val

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

Returns¶

U64 val

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

Returns¶


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


a: val->T

Returns¶

Bool val

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

Parameters¶

that: Nil[A] val

Returns¶


let root: AmbientAuth
"""
The root capability.
"""

let input: InputStream
"""
Stdin represented as an actor.
"""

let out: OutStream
"""Stdout"""

let err: OutStream
"""Stderr"""

let args: Array[String] val
"""The command line used to start the program."""

let vars: Array[String] val


new ref create(seed1: U64 = 42, seed2: U64 = 0) =>
_random = Rand(seed1, seed2)

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

Behavior is undefined if `min` > `max`.
"""
if (min == U8.min_value()) and (max == U8.max_value()) then
_random.u8()
else
min + _random.int((max - min).u64() + 1).u8()
end

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


primitive WriteError
fun string(): String iso^ => "WriteError".clone()

primitive KillError   // Not thrown at this time
fun string(): String iso^ => "KillError".clone()

primitive CapError
fun string(): String iso^ => "CapError".clone()

primitive ChdirError
fun string(): String iso^ => "ChdirError".clone()

primitive UnknownError
fun string(): String iso^ => "UnknownError".clone()


Returns¶

String iso^

spec¶
[Source]
Returns the spec for this command.
fun box spec()
: CommandSpec box

Returns¶

CommandSpec box

fullname¶
[Source]
Returns the full name of this command, with its parents prefixed.
fun box fullname()


I16 val

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

Returns¶

I32 val

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

Returns¶


fun box u128_unsafe()
: U128 val

Returns¶

U128 val

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

Returns¶

ULong val

usize_unsafe¶
[Source]


fun box dccp_single_opt_maxlen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dccp_sockopt_ccid¶
[Source]


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


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


pad: U8 val = 61,
linelen: USize val = 0,
linesep: String val = "
")
: A^

Parameters¶

data: ReadSeq[U8 val] box
at62: U8 val = 43
at63: U8 val = 47
pad: U8 val = 61
linelen: USize val = 0
linesep: String val = "
"

Returns¶

A^


Generator[I32 val] box

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

Parameters¶

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

Returns¶

Generator[I64 val] box


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

Parameters¶

array: Array[A] ref

Returns¶

None val


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

Parameters¶

y: F64 val

Returns¶

Bool val

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

Parameters¶


fun box so_acceptconn()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_atmpvc¶
[Source]


ASCIIPunctuation¶
[Source]
primitive val ASCIIPunctuation

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

Returns¶

ASCIIPunctuation val^


SourceLoc¶
[Source]
Represents a location in a Pony source file, as reported by __loc.
interface val SourceLoc

Public Functions¶
file¶
[Source]
Name and path of source file.
fun box file()
: String val

Returns¶


Parameters¶

data: Array[U8 val] iso

Returns¶

None val

dispose¶
[Source]
Called when no more data will arrive on the stream.
fun ref dispose()
: None val

Returns¶

None val


fun box sctp_default_prinfo()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_default_sndinfo¶
[Source]


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126use "collections"

class Timer
"""
The `Timer` class represents a timer that fires after an expiration
time, and then fires at an interval. When a `Timer` fires, it calls


: MapKeys[K, V, H, this->HashMap[K, V, H] ref] ref^

Returns¶

MapKeys[K, V, H, this->HashMap[K, V, H] ref] ref^

values¶
[Source]
Return an iterator over the values.
fun box values()
: MapValues[K, V, H, this->HashMap[K, V, H] ref] ref^

Returns¶

MapValues[K, V, H, this->HashMap[K, V, H] ref] ref^

pairs¶
[Source]


fun box tcpopt_timestamp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpopt_window¶
[Source]


CapRights0 ref^

from¶
[Source]
Initialises with the rights from a FileCaps.
new ref from(
caps: Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] box)
: CapRights0 ref^

Parameters¶

caps: Flags[(FileCreate val | FileChmod val | FileChown val | FileLink val | FileLookup val | FileMkdir val | FileRead val | FileRemove val | FileRename val | FileSeek val | FileStat val | FileSync val | FileTime val | FileTruncate val | FileWrite val | FileExec val), U32 val] box

Returns¶

CapRights0 ref^


y: USize val

Returns¶

Bool val

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

Parameters¶

y: USize val

Returns¶


Parameters¶

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

Returns¶

Bool val

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


big-endian 32-bit integer
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:
use "buffered"

actor Main
new create(env: Env) =>
let wb = Writer
let messages = [[(F32(3597.82), "Anderson"); (F32(-7979.3), "Graham")]


end
else
true
end

fun ref next(): A! ? =>
match _next = _None
| let a: A! => a
else
if _iter.has_next() then
_find_next()
next()?
else
error
end
end
end)

fun ref filter_map_stateful[B](f: {ref(A!): (B^ | None) ?}): Iter[B]^ =>
"""


let len = 40 + _cur_prompt.size() + _edit.size()
let out = recover String(len) end

// Move to the left edge.
out.append("\r")

// Print the prompt.
out.append(_cur_prompt)

// Print the current line.
out.append(_edit.clone())

// Erase to the right edge.
out.append(ANSI.erase())

// Set the cursor position.
var pos = _cur_prompt.codepoints()

if _cur_pos > 0 then
pos = pos + _edit.codepoints(0, _cur_pos)


: String iso^

Parameters¶

num: USize val

Returns¶

String iso^

find¶
[Source]
Return the index of the n-th instance of s in the string starting from the
beginning. Raise an error if there is no n-th occurrence of s or s is empty.
fun box find(
s: String box,
offset: ISize val = 0,
nth: USize val = 0)
: ISize val ?


my_list.unshift("d")  // my_list is ["d"; "a"; "b"; "c"]
```
"""
prepend_node(ListNode[A](consume a))

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

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

fun ref append(
seq: (ReadSeq[A] & ReadElement[A^]),
offset: USize = 0,
len: USize = -1)


y: USize val

Returns¶

USize val

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

Parameters¶

y: USize val

Returns¶


Called with the the number of times the timer has fired since this was last
called. Usually, the value of `count` will be 1. If it is not 1, it means
that the timer isn't firing on schedule.

For example, if your timer is set to fire every 10 milliseconds, and
`count` is 2, that means it has been between 20-29 milliseconds since the
last time your timer fired. Non 1 values for a timer are rare and indicate
a system under heavy load.

Return true to reschedule the timer (if it has an interval), or
false to cancel the timer (even if it has an interval).
"""
true

fun ref cancel(timer: Timer) =>
"""
Called if the timer is cancelled. This is also called if the notifier
returns false from its `apply` method.
"""
None


1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151


Private helper for reverse, recursively working on elements.
"""
match l
| let cons: Cons[A] => _reverse(cons.tail(), acc.prepend(cons.head()))
else
acc
end

fun val prepend(a: val->A!): Cons[A] =>
"""
Builds a new list with an element added to the front of this list.
"""
Cons[A](consume a, this)

fun val concat(l: List[A]): List[A] =>
"""
Builds a new list that is the concatenation of this list and the provided
list.
"""
_concat(l, this.reverse())


U64 val

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

Parameters¶

y: U64 val

Returns¶

U64 val

op_not¶
[Source]


fun box so_nofcs()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_notifyconflict¶
[Source]


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