```pony
class Foo[A: Any #read]
var _c: A

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

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

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

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

let b = Foo[String val]("World")
env.out.print(b.get().string())
```


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).
fun ref apply(
timer: Timer ref,
count: U64 val)
: Bool val

Parameters¶

timer: Timer ref
count: U64 val

Returns¶

Bool val

cancel¶


y: A

Returns¶

A

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

Parameters¶

y: A

Returns¶


FileChmod¶
[Source]
primitive val FileChmod

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

Returns¶

FileChmod val^


Parameters¶

name: String val

Returns¶

None val

complete¶
[Source]
Complete an asynchronous property successfully.
Once this method is called the property
is considered successful or failing
depending on the value of the parameter success.
For more fine grained control over completing or failing
a property that consists of many steps, consider using
expect_action, complete_action and fail_action.
fun box complete(


HashSet[this->A!, K] ref^

op_and[optional K: HashFunction[this->A!] val]¶
[Source]
Create a set with the elements that are in both this and that.
fun box op_and[optional K: HashFunction[this->A!] val](
that: this->HashSet[A, H] ref)
: HashSet[this->A!, K] ref^

Parameters¶

that: this->HashSet[A, H] ref

Returns¶

HashSet[this->A!, K] ref^


fun bus(): U32 =>
ifdef bsd or osx then 10
elseif linux then 7
else compile_error "no SIGBUS"
end

fun segv(): U32 =>
ifdef linux or bsd or osx then 11
else compile_error "no SIGSEGV"
end

fun sys(): U32 =>
ifdef bsd or osx then 12
elseif linux then 31
else compile_error "no SIGSYS"
end

fun pipe(): U32 =>
ifdef linux or bsd or osx then 13


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

Parameters¶

that: FileEOF val

Returns¶

Bool val

ne¶
[Source]


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

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

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

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


ASCIILettersUpper¶
[Source]
primitive val ASCIILettersUpper

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

Returns¶

ASCIILettersUpper val^


"""
A promise to eventually produce a result of type A. This promise can either
be fulfilled or rejected.

Any number of promises can be chained after this one.
"""
var _value: (_Pending | _Reject | A) = _Pending
embed _list: Array[_IThen[A]] = _list.create()

be apply(value: A) =>
"""
Fulfill the promise.
"""
if _value isnt _Pending then
return
end

_value = value

for f in _list.values() do


file.pony

1
2
3
4
5
6
7
8
9
10
11


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


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


(U8 val , Bool val)

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

Parameters¶

y: U8 val

Returns¶

U8 val ?

fld_unsafe¶
[Source]


1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171


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


| FileTime
| FileTruncate
| FileWrite
| FileExec
),
U32 ]


GenObj[T: T]¶
[Source]
trait box GenObj[T: T]

Public Functions¶
generate¶
[Source]
fun box generate(
rnd: Randomness ref)
: (T^ | (T^ , Iterator[T^] ref)) ?

Parameters¶


Subtract `y` from this integer and return the result and a flag indicating overflow.
"""
fun mulc(y: A): (A, Bool)
"""
Multiply `y` with this integer and return the result and a flag indicating overflow.
"""
fun divc(y: A): (A, Bool)
"""
Divide this integer by `y` and return the result and a flag indicating overflow or division by zero.
"""
fun remc(y: A): (A, Bool)
"""
Calculate the remainder of this number divided by `y` and return the result and a flag indicating division by zero or overflow.

The result will have the sign of the dividend.
"""
fun fldc(y: A): (A, Bool)
"""
Divide this integer by `y` and return the result, rounded towards negative infinity and a flag indicating overflow or division by zero.
"""


fun box ipx_special_none()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipx_stopfilterptype¶
[Source]


1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391


fun box tcp_keepintvl()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_maxburst¶
[Source]


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


fun box sub_partial(
y: I64 val)
: I64 val ?

Parameters¶

y: I64 val

Returns¶

I64 val ?

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

Parameters¶


## Working with Structs: from Pony to C

Like we mentioned above, Pony classes and structs correspond directly to pointers to the class or struct in C. This means that in most cases we won't need to use the `addressof` operator when passing struct types to C. For example, let's imagine we want to use the `writev` function from Pony on Linux:

```pony
// In C: ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
use @writev[USize](fd: U32, iov: IOVec tag, iovcnt: I32)

// In C:
// struct iovec {
//     void  *iov_base;    /* Starting address */
//     size_t iov_len;     /* Number of bytes to transfer */
// };
struct IOVec
var base: Pointer[U8] tag = Pointer[U8]
var len: USize = 0

let data = "Hello from Pony!"
var iov = IOVec
iov.base = data.cpointer()


path: String val

Returns¶

String val

from_slash¶
[Source]
Changes each / in the path to the OS specific separator.
fun box from_slash(
path: String val)
: String val

Parameters¶

path: String val

Returns¶


fun box dso_services()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_address¶
[Source]


# Apply

Many Pony classes have a function called `apply` which performs whatever action is most common for that type. Pony allows you to omit the word `apply` and just attempt to do a call directly on the object. So:

```pony
var foo = Foo.create()
foo()
```

becomes:

```pony
var foo = Foo.create()
foo.apply()
```

Any required arguments can be added just like normal method calls.

```pony
var foo = Foo.create()


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


I64 val

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

Returns¶

I128 val

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

Returns¶


# Primitive initialisation and finalisation

Primitives can have two special functions, `_init` and `_final`. `_init` is called before any actor starts. `_final` is called after all actors have terminated. The two functions take no parameter. The `_init` and `_final` functions for different primitives always run sequentially.

A common use case for this is initialising and cleaning up C libraries without risking untimely use by an actor.


_random.u128()
elseif min > U64.max_value().u128() then
// both above U64 range - chose random low 64 bits
(u64((min >> 64).u64(), (max >> 64).u64()).u128() << 64) or u64().u128()
elseif max > U64.max_value().u128() then
// min below U64 max value
let high = (u64((min >> 64).u64(), (max >> 64).u64()).u128() << 64)
let low =
if high > 0 then
// number will be bigger than U64 max anyway, so chose a random lower u64
u64().u128()
else
// number <= U64 max, so chose lower u64 while considering requested range min
u64(min.u64(), U64.max_value()).u128()
end
high or low
else
// range within u64 range
u64(min.u64(), max.u64()).u128()
end


max: USize val = 100

Returns¶

Generator[String val] box

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

Parameters¶

min: USize val = 0


fun box sctp_pcb_flags_recvsendfailevnt()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_socket_allgone¶
[Source]


fun box mrt_api_support()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mrt_del_bw_upcall¶
[Source]


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

Returns¶

None val

down¶
[Source]
Next line.
fun ref down(
ctrl: Bool val = false,
alt: Bool val = false,
shift: Bool val = false)
: None val

Parameters¶


Unlike a TCPConnection and other forms of input receiving, creating a
SignalHandler will not keep your program running. As such, you are not
required to call dispose on your signal handlers in order to shutdown your
program.
Public Types¶

primitive Sig
actor SignalHandler
interface SignalNotify
primitive SignalRaise


"""
fun apply(i: USize): A ?


_event = AsioEvent.none()
end

be _read_again() =>
"""
Resume reading.
"""
if not _closed then
_pending_reads()
end

fun ref _pending_reads() =>
"""
Read while data is available, guessing the next packet length as we go. If
we read 4 kb of data, send ourself a resume message and stop reading, to
avoid starving other actors.
"""
ifdef not windows then
try
var sum: USize = 0


auth.pony

1
2
3primitive FileAuth
new create(from: AmbientAuth) =>
None


_cur_line = _cur_line - 1
_edit = _history(_cur_line)?.clone()
end_key()
end
end

fun ref down(ctrl: Bool = false, alt: Bool = false, shift: Bool = false) =>
"""
Next line.
"""
try
if _cur_line < (_history.size() - 1) then
_cur_line = _cur_line + 1
_edit = _history(_cur_line)?.clone()
else
_cur_line = _history.size()
_edit.clear()
end

end_key()


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


fun box tcpci_flag_lossrecovery()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpci_opt_ecn¶
[Source]


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


892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911


tail¶
[Source]
Returns an error, since Nil has no tail.
fun box tail()
: (Cons[A] val | Nil[A] val) ?

Returns¶

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

reverse¶
[Source]
The reverse of the empty list is the empty list.
fun box reverse()
: Nil[A] val

Returns¶


Returns¶

CommandSpec ref^ ?

leaf¶
[Source]
Creates a command spec that can accept options and arguments, but not child
commands.
new ref leaf(
name': String val,
descr': String val = "",
options': Array[OptionSpec val] box = call,
args': Array[ArgSpec val] box = call)
: CommandSpec ref^ ?

Parameters¶

name': String val


Parameters¶

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

Returns¶

UDPSocket tag^

Public Behaviours¶
write¶
[Source]
Write a single sequence of bytes.
be write(
data: (String val | Array[U8 val] val),


Reject[A: Any #share]¶
[Source]
A function on A that is called when a promise is rejected.
interface iso Reject[A: Any #share]

Public Functions¶
apply¶
[Source]
fun ref apply()
: A ?

Returns¶


that: ASCIILettersLower val

Returns¶

Bool val

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

Parameters¶

that: ASCIILettersLower val

Returns¶


U128 val

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

Returns¶

ULong val

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

Returns¶


ASCIIWhiteSpace¶
[Source]
primitive val ASCIIWhiteSpace

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

Returns¶

ASCIIWhiteSpace val^


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


let pid: I32

new create(
path: String,
args: Array[String] val,
vars: Array[String] val,
wdir: (FilePath | None),
err: _Pipe,
stdin: _Pipe,
stdout: _Pipe,
stderr: _Pipe) ?
=>
// Prepare argp and envp ahead of fork() as it's not safe to allocate in
// the child after fork() is called.
let argp = _make_argv(args)
let envp = _make_argv(vars)
// Fork the child process, handling errors and the child fork case.
pid = @fork()
match pid
| -1 => error


Random¶
[Source]
The Random trait should be implemented by all random number generators. The
only method you need to implement is fun ref next(): 64. Once that method
has been implemented, the Random trait provides default implementations of
conversions to other number types.
trait ref Random

Constructors¶
create¶
[Source]
Create with the specified seed. Returned values are deterministic for a
given seed.


fun box ipproto_nsp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_old_divert¶
[Source]


Parameters¶

arr: Array[val->A] ref

Returns¶

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

from¶
[Source]
Builds a new list from an iterator
fun box from(
iter: Iterator[val->A] ref)
: (Cons[A] val | Nil[A] val)

Parameters¶

iter: Iterator[val->A] ref


TestHelper¶
[Source]
Per unit test class that provides control, logging and assertion functions.
Each unit test is given a TestHelper when it is run. This is val and so can
be passed between methods and actors within the test without restriction.
The assertion functions check the relevant condition and mark the test as a
failure if appropriate. The success or failure of the condition is reported
back as a Bool which can be checked if a different code path is needed when
that condition fails.
All assert functions take an optional message argument. This is simply a
string that is printed as part of the error message when the condition fails.
It is intended to aid identifying what failed.
class val TestHelper


32
33"""


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


service: Pointer[U8] tag)
use @pony_os_getaddr[None](addr: Pointer[None] tag, ipaddr: NetAddress tag)
use @pony_os_nextaddr[Pointer[U8]](addr: Pointer[None] tag)
use @freeaddrinfo[None](addr: Pointer[None] tag)
use @pony_os_host_ip4[Bool](host: Pointer[U8] tag)
use @pony_os_host_ip6[Bool](host: Pointer[U8] tag)

primitive DNS
"""
Helper functions for resolving DNS queries.
"""
fun apply(auth: DNSAuth, host: String, service: String)
: Array[NetAddress] iso^
=>
"""
Gets all IPv4 and IPv6 addresses for a host and service.
"""
_resolve(auth, 0, host, service)

fun ip4(auth: DNSAuth, host: String, service: String)


else
// single array did not have all the bytes needed
u8()?.u128() or (u8()?.u128() << 8) or
(u8()?.u128() << 16) or (u8()?.u128() << 24) or
(u8()?.u128() << 32) or (u8()?.u128() << 40) or
(u8()?.u128() << 48) or (u8()?.u128() << 56) or
(u8()?.u128() << 64) or (u8()?.u128() << 72) or
(u8()?.u128() << 80) or (u8()?.u128() << 88) or
(u8()?.u128() << 96) or (u8()?.u128() << 104) or
(u8()?.u128() << 112) or (u8()?.u128() << 120)
end
else
error
end

fun ref i128_be(): I128 ? =>
"""
Get a big-endian I129.
"""
u128_be()?.i128()


u16¶
[Source]
create a generator for U16 values
fun box u16(
min: U16 val = call,
max: U16 val = call)
: Generator[U16 val] box

Parameters¶

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

Returns¶

Generator[U16 val] box


if _pending_writes() then
// Sent all data. Release backpressure.
_release_backpressure()
end
end
end

if AsioEvent.readable(flags) then
_readable = true
_complete_reads(arg)
_pending_reads()
end

if AsioEvent.disposable(flags) then
@pony_asio_event_destroy(event)
_event = AsioEvent.none()
end

_try_shutdown()
end


Path val^

Public Functions¶
is_sep¶
[Source]
Determine if a byte is a path separator.
fun box is_sep(
c: U8 val)
: Bool val

Parameters¶

c: U8 val

Returns¶

Bool val


# Docstrings

Including documentation in your code makes you awesome. If you do it, everyone will love you.

Pony makes it easy by allowing you to put a __docstring__ on every type, field, or method. Just put a string literal right after declaring the type or field, or right after the `=>` of a method, before writing the body. The compiler will know what to do with them.

For traits and interfaces that have methods without bodies, you can put the docstring after the method declaration, even though there is no `=>`.

By convention, a docstring should be a triple-quoted string, and it should use Markdown for any formatting.

```pony
actor Main
"""
This is documentation for my Main actor
"""

var count: USize = 0
"""
This is documentation for my count field
"""


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30interface val SourceLoc
"""


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


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


fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8_unsafe¶
[Source]


y: I8 val

Returns¶

(I8 val , Bool val)

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

Parameters¶

y: I8 val

Returns¶


file_lines.pony

1
2
3
4
5
6
7
8
9
10
11


Reader¶
[Source]
Store network data and provide a parsing interface.
Reader provides a way to extract typed data from a sequence of
bytes. The Reader manages the underlying data structures to
provide a read cursor over a contiguous sequence of bytes. It is
useful for decoding data that is received over a network or stored
in a file. Chunk of bytes are added to the Reader using the
append method, and typed data is extracted using the getter
methods.
For example, suppose we have a UDP-based network data protocol where
messages consist of the following:


I16 val

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

Returns¶

F64 val

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

Returns¶


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


var row: U16 = 0
var col: U16 = 0
var xpixel: U16 = 0
var ypixel: U16 = 0

primitive _EscapeNone
primitive _EscapeStart
primitive _EscapeSS3
primitive _EscapeCSI
primitive _EscapeMod

type _EscapeState is
( _EscapeNone
| _EscapeStart
| _EscapeSS3
| _EscapeCSI
| _EscapeMod
)

class _TermResizeNotify is SignalNotify


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

fun infoat(target: String): FileInfo ? =>
"""
Return a FileInfo for some path relative to this directory.
"""
if
not path.caps(FileStat)
or not path.caps(FileLookup)
or (_fd == -1)
then
error
end


Random package¶
The Random package provides support generating random numbers. The package
provides random number generators you can use in your code, a dice roller and
a trait for implementing your own random number generator.
If your application does not require a specific generator, use Rand.
Seed values can contain up to 128 bits of randomness in the form of two U64s.
A common non-cryptographically secure way to seed a generator is with
Time.now.
let rand = Rand
let n = rand.next()

Public Types¶


ASCIIAll¶
[Source]
Represents all ASCII characters,
excluding the NUL (\x00) character for its special treatment in C strings.
primitive val ASCIIAll

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

Returns¶


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


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


"""
Pass a partial or unrecognised escape sequence to the notifier.
"""
for c in _esc_buf.values() do
_notify(this, c)
end

_esc_clear()

fun ref _esc_clear() =>
"""
Clear the escape state.
"""
if _timer isnt None then
try _timers.cancel(_timer as Timer tag) end
_timer = None
end

_escape = _EscapeNone
_esc_buf.clear()


# Partially applying a partial application

Since partial application results in an object with an apply method, we can partially apply the result!

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


fun ref skip(n: USize): Iter[A]^ =>
"""
Skip the first n values of the iterator.


# Conditionals

The simplest control structure is the good old `if`. It allows you to perform some action only when a condition is true.
In Pony it looks like this:

```pony
if condition then
control_body
end
```

Here is a simple example:

```pony
if a > b then
env.out.print("a is bigger")
end
```

Often the condition may be composed of many sub conditions connected by `and` and `or`.


fun ref ilong(
min: ILong val = call,
max: ILong val = call)
: ILong val

Parameters¶

min: ILong val = call
max: ILong val = call

Returns¶

ILong val

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


: Bool val

Parameters¶

that: String box

Returns¶

Bool val

lt¶
[Source]
Returns true if this is lexically less than that. Needs to be made UTF-8
safe.
fun box lt(
that: String box)
: Bool val

Parameters¶


"""
if _connected and not _closed then
_in_sent = true

ifdef windows then
try
var num_to_send: I32 = 0
for bytes in _notify.sentv(this, data).values() do
// don't sent 0 byte payloads; windows doesn't like it (and it's wasteful)
if bytes.size() == 0 then
continue
end

// Add an IOCP write.
_pending_writev_windows
.> push((bytes.size(), bytes.cpointer()))
_pending_writev_total = _pending_writev_total + bytes.size()
num_to_send = num_to_send + 1
end


List[this->A!] ref

take_while¶
[Source]
Builds a List of elements satisfying the predicate, stopping at the first false return.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.take_while( {(s: String): Bool => s < "b"} )  // ["a"]

fun box take_while(
f: {(this->A!): Bool}[A] box)
: List[this->A!] ref^

Parameters¶

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

Returns¶


Returns¶

USize val

dispose¶
[Source]
Called when ProcessMonitor terminates to cleanup ProcessNotify if a child
process was in fact started. dispose will not be called if a child process
was never started. The notify will know that a process was started and to
expect a dispose call by having received a created call.
dispose includes the exit status of the child process. If the process
finished, then child_exit_status will be an instance of Exited.
The childs exit code can be retrieved from the Exited instance by using
Exited.exit_code().
On Posix systems, if the process has been killed by a signal (e.g. through
the kill command), child_exit_status will be an instance of
Signaled with the signal number that terminated the
process available via Signaled.signal().


[Source]
Returns a formated help string for this option.
fun box help_string()
: String val

Returns¶

String val

deb_string¶
[Source]
fun box deb_string()
: String val

Returns¶

String val


dispose¶
[Source]
be dispose()

log¶
[Source]
be log(
msg: String val,
verbose: Bool val = false)

Parameters¶

msg: String val
verbose: Bool val = false

Public Functions¶
complete¶
[Source]


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


fun box ipv6_tlv_routeralert()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_unicast_hops¶
[Source]


| let p: CommandParser box => p._option_with_name(name)
else
None
end

fun _option_with_short(short: U8): (OptionSpec | None) =>
for o in _spec.options().values() do
if o._has_short(short) then
return o
end
end
match _parent
| let p: CommandParser box => p._option_with_short(short)
else
None
end

fun tag _short_string(c: U8): String =>
recover String.from_utf32(c.u32()) end


: Bool val

Parameters¶

that: IniParse val

Returns¶

Bool val


Returns¶

String val

string¶
[Source]
fun box string()
: String val

Returns¶

String val

help_string¶
[Source]
Renders the help message as a String.
fun box help_string()


fun multiply(a: U64, b: U64): U64 =>
a * b

actor Main
new create(env: Env) =>
let doorState : DoorState = ClosedDoor
let isDoorOpen : Bool = match doorState
| OpenedDoor => true
| ClosedDoor => false
end
env.out.print("Is door open? " + isDoorOpen.string())
env.out.print("2 + 3 = " + BasicMath.add(2,3).string())
```

Primitives are quite powerful, particularly as enumerations. Unlike enumerations in other languages, each "value" in the enumeration is a complete type, which makes attaching data and functionality to enumeration values easy.


U32 val

radix¶
[Source]
Exponent radix.
fun tag radix()
: U8 val

Returns¶

U8 val

precision2¶
[Source]
Mantissa precision in bits.
fun tag precision2()
: U8 val


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


Dispose the actor after a property run / a shrink is done.
"""
_runner.dispose_when_done(disposable, _run)

fun _fail(msg: String) =>
_runner.log(msg)
_run_notify.apply(_run, false)

fun _fmt_msg(loc: SourceLoc, msg: String): String =>
let msg_prefix = _params + " " + _run.string() + " " + _format_loc(loc)
if msg.size() > 0 then
msg_prefix + ": " + msg
else
msg_prefix
end

fun _format_loc(loc: SourceLoc): String =>
loc.file() + ":" + loc.line().string()


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


fibonacci.pony

1
2
3
4
5
6
7
8
9
10
11


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

Parameters¶

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

Returns¶

Generator[List[T] ref] box

set_of[T: (Hashable #read & Equatable[T] #read)]¶
[Source]


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


fun box divrem_unsafe(
y: I128 val)
: (I128 val , I128 val)

Parameters¶

y: I128 val

Returns¶

(I128 val , I128 val)

div_unsafe¶
[Source]
Unsafe operation.
If y is 0, the result is undefined.
If the operation overflows, the result is undefined.
fun box div_unsafe(
y: I128 val)


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


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


signal_handler.pony

1
2
3
4
5
6
7
8
9
10
11


fun ip_origdstaddr():I32 => @pony_os_sockopt_option(I32(302))
fun ip_passsec():I32 => @pony_os_sockopt_option(I32(303))
fun ip_pktinfo():I32 => @pony_os_sockopt_option(I32(304))
fun ip_pktoptions():I32 => @pony_os_sockopt_option(I32(305))
fun ip_pmtudisc_do():I32 => @pony_os_sockopt_option(I32(306))
fun ip_pmtudisc_dont():I32 => @pony_os_sockopt_option(I32(307))
fun ip_pmtudisc_interface():I32 => @pony_os_sockopt_option(I32(308))
fun ip_pmtudisc_omit():I32 => @pony_os_sockopt_option(I32(309))
fun ip_pmtudisc_probe():I32 => @pony_os_sockopt_option(I32(310))
fun ip_pmtudisc_want():I32 => @pony_os_sockopt_option(I32(311))
fun ip_portrange():I32 => @pony_os_sockopt_option(I32(312))
fun ip_portrange_default():I32 => @pony_os_sockopt_option(I32(313))
fun ip_portrange_high():I32 => @pony_os_sockopt_option(I32(314))
fun ip_portrange_low():I32 => @pony_os_sockopt_option(I32(315))
fun ip_recvdstaddr():I32 => @pony_os_sockopt_option(I32(316))
fun ip_recverr():I32 => @pony_os_sockopt_option(I32(317))
fun ip_recvflowid():I32 => @pony_os_sockopt_option(I32(318))
fun ip_recvif():I32 => @pony_os_sockopt_option(I32(319))
fun ip_recvopts():I32 => @pony_os_sockopt_option(I32(320))
fun ip_recvorigdstaddr():I32 => @pony_os_sockopt_option(I32(321))


[Source]
new val create(
a: val->A,
t: (Cons[A] val | Nil[A] val))
: Cons[A] val^

Parameters¶

a: val->A
t: (Cons[A] val | Nil[A] val)

Returns¶

Cons[A] val^

Public Functions¶
size¶
[Source]
Returns the size of the list.


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

Parameters¶

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

Returns¶

XorShift128Plus ref^

Public Functions¶
next¶


 Debug package

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

`ponyc -d`


new open(from: FilePath) =>
"""
Open for read only.
Set _errno according to result.
"""
path = from
writeable = false
_fd = -1

if
not path.caps(FileRead) or
try
let info' = FileInfo(path)?
info'.directory or info'.pipe
else
true
end
then
_errno = FileError


1752
1753
1754
1755
1756
1757use @memcmp[I32](dst: Pointer[None] tag, src: Pointer[None] tag, len: USize)
use @memset[Pointer[None]](dst: Pointer[None], set: U32, len: USize)
use @memmove[Pointer[None]](dst: Pointer[None], src: Pointer[None], len: USize)
use @strtof[F32](nptr: Pointer[U8] tag, endptr: Pointer[Pointer[U8] box] ref)
use @strtod[F64](nptr: Pointer[U8] tag, endptr: Pointer[Pointer[U8] box] ref)
use @pony_os_clear_errno[None]()
use @pony_os_errno[I32]()

class val String is (Seq[U8] & Comparable[String box] & Stringable)
"""
A String is an ordered collection of bytes.

Strings don't specify an encoding.

Example usage of some common String methods:


Only shrink until given `min` is hit.
"""
var shrink_base = s
let s_len = s.codepoints()
let shrink_iter: Iterator[String^] =
if s_len > min then
Iter[String^].repeat_value(consume shrink_base)
.map_stateful[String^](
object
var len: USize = s_len - 1
fun ref apply(str: String): String =>
Generators._trim_codepoints(str, len = len - 1)
end
).take(s_len - min)
// take_while is buggy in pony < 0.21.0
//.take_while({(t) => t.codepoints() > min})
else
Poperator[String].empty()
end


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


fun box usize_unsafe()
: USize val

Returns¶

USize val

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

Returns¶

F32 val

f64_unsafe¶
[Source]


fun box i16_unsafe()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64_unsafe¶
[Source]


end
else
_logger.log("Action '" + name + "' finished unexpectedly at " + round.string() + ". ignoring.")
end

be dispose_when_done(disposable: DisposableActor, round: _Round) =>
"""
Let us not have older rounds interfere with newer ones,
thus dispose directly.
"""
if round != this._current_round then
_logger.log("Unexpected dispose_when_done for " + round.string() +
". Currently at " + this._current_round.string(), true)
_logger.log("Disposing right now...", true)
disposable.dispose()
return
end
_disposables.push(disposable)

be dispose() =>


fun box rds_rdma_fence()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_rdma_notify_me¶
[Source]


# cannot write to a field in a box function

Suppose you create a class with a mutable field and added a method to change the field:

```pony
class Wombat
var color: String = "brown"
fun dye(new_color: String) =>
color = new_color
```

The error message would be:

```error
Error:
.../a.pony:4:11: cannot write to a field in a box function. If you are trying to change state in a function use fun ref
color = new_color
^
```


gen: GenObj[T] box

Returns¶

Generator[T] ref^

Public Functions¶
generate¶
[Source]
Let this generator generate a value
given a source of Randomness.
Also allow for returning a value and pre-generated shrink results
as a ValueAndShrink[T] instance, a tuple of (T^, Seq[T]).
This helps propagating shrink results through all kinds of Generator
combinators like filter, map and flat_map.
If implementing a custom Generator based on another one,
with a Generator Combinator, you should use shrunken values
returned by generate to also return shrunken values based on them.
If generating an example value is costly, it might be more efficient


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


# Infix Operators

Infix operators take two operands and are written between those operands. Arithmetic and comparison operators are the most common:

```pony
1 + 2
a < b
```

Pony has pretty much the same set of infix operators as other languages.


_spawn(ns)
end

// Queue an accept if we're not at the limit.
if (_limit == 0) or (_count < _limit) then
@pony_os_accept(_event)
else
_paused = true
end
else
if _closed then
return
end

while (_limit == 0) or (_count < _limit) do
var fd = @pony_os_accept(_event)

match fd
| -1 =>


new val create()
: FormatFixLarge val^

Returns¶

FormatFixLarge val^

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

Parameters¶

that: FormatFixLarge val

Returns¶


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


fun box tcp_congestion()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_connection_info¶
[Source]


section: String val)
: Bool val

Parameters¶

section: String val

Returns¶

Bool val

errors¶
[Source]
This is called for each error encountered. Return false to halt processing.
fun ref errors(
line: USize val,
err: (IniIncompleteSection val | IniNoDelimiter val))
: Bool val


that: FileChown val

Returns¶

Bool val

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

Parameters¶

that: FileChown val

Returns¶


Map[K: (Hashable #read & Equatable[K] #read), V: V]¶
[Source]
This is a map that uses structural equality on the key.
type Map[K: (Hashable #read & Equatable[K] #read), V: V] is
HashMap[K, V, HashEq[K] val] ref

Type Alias For¶

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


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

Parameters¶

y: F64 val

Returns¶

Bool val

string¶
fun box string()
: String iso^


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

Parameters¶

y: ISize val

Returns¶

Bool val

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


Property1[T: T]¶
[Source]
A property that consumes 1 argument of type T.
A property is defined by a Generator, returned by
the gen() method, and a
property method that consumes the
generators' output and verifies a custom property with the help of a
PropertyHelper.
A property is verified if no failed assertion on
PropertyHelper has been
reported for all the samples it consumed.
The property execution can be customized by returning a custom
PropertyParams from the


n = n + 1
end

i = i + 1
end

n

fun space(): USize =>
"""
Returns the space available for data, not including the null terminator.
"""
if is_null_terminated() then _alloc - 1 else _alloc end

fun ref reserve(len: USize) =>
"""
Reserve space for len bytes. An additional byte will be reserved for the
null terminator.
"""
if _alloc <= len then


out._size = _size
out

fun slice(
from: USize = 0,
to: USize = -1,
step: USize = 1)
: Array[this->A!]^
=>
"""
Create a new array that is a clone of a portion of this array. The range is
exclusive and saturated.
The new array contains references to the same elements that the old array
contains, the elements themselves are not cloned.
"""
let out = Array[this->A!]
let last = _size.min(to)
let len = last - from

if (last > from) and (step > 0) then


fun box sctp_cmt_on_off()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cmt_rpv2¶
[Source]


## While

Pony `while` loops are very similar to those in other languages. A condition expression is evaluated and if it's true we execute the code inside the loop. When we're done we evaluate the condition again and keep going until it's false.

Here's an example that prints out the numbers 1 to 10:

```pony
var count: U32 = 1

while count <= 10 do
env.out.print(count.string())
count = count + 1
end
```

Just like `if` expressions, `while` is also an expression. The value returned is just the value of the expression inside the loop the last time we go round it. For this example that will be the value given by `count = count + 1` when count is incremented to 11. Since Pony assignments hand back the _old_ value our `while` loop will return 10.

__But what if the condition evaluates to false the first time we try, then we don't go round the loop at all?__ In Pony `while` expressions can also have an `else` block. In general, Pony `else` blocks provide a value when the expression they are attached to doesn't. A `while` doesn't have a value to give if the condition evaluates to false the first time, so the `else` provides it instead.

__So is this like an else block on a while loop in Python?__ No, this is very different. In Python, the `else` is run when the `while` completes. In Pony the `else` is only run when the expression in the `while` isn't.


data.
"""
let alloc_fn =
@{(ctx: Pointer[None], size: USize): Pointer[U8] =>
@pony_alloc(ctx, size)
}
let alloc_final_fn =
@{(ctx: Pointer[None], size: USize): Pointer[U8] =>
@pony_alloc_final(ctx, size)
}
let throw_fn = @{() ? => error }
@pony_deserialise(@pony_ctx(), Pointer[None], _data, alloc_fn,
alloc_final_fn, throw_fn) ?

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


"""
queue(data)
queue(_newline)

_pending_writes()

fun ref printv(data: ByteSeqIter box): Bool =>
"""
Print an iterable collection of ByteSeqs.
"""
for bytes in data.values() do
queue(bytes)
queue(_newline)
end

_pending_writes()

fun ref write(data: ByteSeq box): Bool =>
"""
Returns false if the file wasn't opened with write permission.


fun gt(that: Flags[A, B] box): Bool =>
"""
Returns true if the flags set on this are a struct superset of the flags
set on that. Flags is only partially ordered, so gt is not the opposite of
le.
"""
(_value != that._value) and ((that._value and not _value) == 0)

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


y: USize val

Returns¶

USize val

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

Returns¶

USize val

add¶
[Source]


Bool val


: U64 val

Returns¶

U64 val

f64¶
[Source]
Returns the arg value as an F64, defaulting to 0.0.
fun box f64()
: F64 val

Returns¶

F64 val

string_seq¶
[Source]


# Ephemeral types

In Pony, every expression has a type. So what's the type of `consume a`? It's not the same type as `a`, because it might not be possible to alias `a`. Instead, it's an __ephemeral__ type. That is, it's a type for a value that currently has no name (it might have a name through some other alias, but not the one we just consumed or destructively read).

To show a type is ephemeral, we put a `^` at the end. For example:

```pony
fun test(a: Wombat iso): Wombat iso^ =>
consume a
```

Here, our function takes an isolated Wombat as a parameter and returns an ephemeral isolated Wombat.

This is useful for dealing with `iso` and `trn` types, and for generic types, but it's also important for constructors. A constructor always returns an ephemeral type, because it's a new object.


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

Returns¶

HashEq64[A] val^

Public Functions¶
hash64¶
[Source]
Use the hash function from the type parameter.
fun box hash64(
x: box->A)
: U64 val

Parameters¶

x: box->A


I64 val

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

Returns¶

U64 val

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

Returns¶


fun ref next()
: USize val ?

Returns¶

USize val ?


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


Parameters¶

that: (Less val | Equal val | Greater val)

Returns¶

Bool val


run()
end

fun ref _prepare_next_round() =>
this._current_round = this._current_round.inc()
this._expected_actions.clear()
for disposable in Poperator[DisposableActor](this._disposables) do
disposable.dispose()
end

fun ref _generate_with_retry(max_retries: USize): ValueAndShrink[T] ? =>
var tries: USize = 0
repeat
try
return _gen.generate_and_shrink(_rnd)?
else
tries = tries + 1
end
until (tries > max_retries) end


Returns¶

F32 val

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

Returns¶

F32 val

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


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

Returns¶

(U32 val , U32 val)

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

Parameters¶


I16 val

max_exp2¶
[Source]
fun tag max_exp2()
: I16 val

Returns¶

I16 val

max_exp10¶
[Source]
fun tag max_exp10()
: I16 val

Returns¶


Create a generator for U64 values.
fun box u64(
min: U64 val = call,
max: U64 val = call)
: Generator[U64 val] box

Parameters¶

min: U64 val = call
max: U64 val = call

Returns¶

Generator[U64 val] box

u128¶
[Source]
Create a generator for U128 values.
fun box u128(


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


We can also bind all the arguments:

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

Or even none of the arguments:

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


return
end

if not _closed then
if AsioEvent.readable(flags) then
_readable = true
_complete_reads(arg)
_pending_reads()
end
else
ifdef windows then
if AsioEvent.readable(flags) then
_readable = false
_close()
end
end
end

if AsioEvent.disposable(flags) then
@pony_asio_event_destroy(_event)


# Custom Serialisation and Deserialisation

Pony objects can have `Pointer` fields that store pointers to memory that contains things that are opaque to Pony but that may be useful to code that is called via FFI. Because the objects that `Pointer` fields point to are opaque, Pony cannot serialise and deserialise them by itself. However, Pony's serialisation system provides a way for the programmer to specify how the objects pointed to by these fields should be serialised and deserialised. This system is called custom serialisation.

Since `Pointer` fields are opaque to Pony, it is assumed that the serialisation and deserialisation code will be written in another language that knows how to read the object referenced by the pointers.


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


FormatFloat¶
[Source]
type FormatFloat is
(FormatDefault val | FormatExp val | FormatExpLarge val | FormatFix val | FormatFixLarge val | FormatGeneral val | FormatGeneralLarge val)

Type Alias For¶

(FormatDefault val | FormatExp val | FormatExpLarge val | FormatFix val | FormatFixLarge val | FormatGeneral val | FormatGeneralLarge val)


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


fun box tcp_rxt_conndroptime()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_saved_syn¶
[Source]


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

Parameters¶

y: A

Returns¶

A

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


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

actor Main
new create(env: Env) =>
env.input(recover Notify(env) end, 1024)


Public Functions¶
apply¶
[Source]
Turns an array of strings that look like environment variables, ie.
key=value, into a map of string to string. Can optionally filter for
keys matching a 'prefix', and will squash resulting keys to lowercase
iff 'squash' is true.
So:
<PREFIX><KEY>=<VALUE>
becomes:
{KEY, VALUE} or {key, VALUE}
fun box apply(
envs: (Array[String val] box | None val),
prefix: String val = "",
squash: Bool val = false)
: HashMap[String val, String val, HashEq[String val] val] val

Parameters¶


max: USize val = 100

Returns¶

Generator[String val] box

utf32_codepoint_string¶
[Source]
Create a generator for strings
from a generator of unicode codepoints,
with a minimum length of min codepoints (default: 0)
and a maximum length of max codepoints (default: 100).
Note that the byte length of the generated string can be up to 4 times
the size in code points.
fun box utf32_codepoint_string(
gen: Generator[U32 val] box,
min: USize val = 0,
max: USize val = 100)
: Generator[String val] box


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

Parameters¶

y: ISize val

Returns¶

ISize val ?

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


[Source]
new iso create()
: AsyncOverheadBenchmark iso^

Returns¶

AsyncOverheadBenchmark iso^

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

Returns¶

String val


ProcessMonitor¶
[Source]
Fork+execs / creates a child process and monitors it. Notifies a client about
STDOUT / STDERR events.
actor tag ProcessMonitor is
AsioEventNotify tag

Implements¶

AsioEventNotify tag

Constructors¶


fun box rose_defer()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rose_holdback¶
[Source]


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

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

Our promise `Issue`, is no longer a `Promise[Promise[Issue]]`. By using
`flatten_next`, we have a much more manageable `Promise[Issue]` instead.

Other than unwrapping promises for you, `flatten_next` otherwise acts the
same as `next` so all the same rules apply to fulfillment and rejection.
"""
let outer = Promise[B]

next[None](object iso
var f: Fulfill[A, Promise[B]] = consume fulfill
let p: Promise[B] = outer


fun box sub(
y: F32 val)
: F32 val

Parameters¶

y: F32 val

Returns¶

F32 val

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

Parameters¶


primitive FileWrite
fun value(): U32 => 1 << 14

primitive FileExec
fun value(): U32 => 1 << 15

type FileCaps is Flags[
( FileCreate
| FileChmod
| FileChown
| FileLink
| FileLookup
| FileMkdir
| FileRead
| FileRemove
| FileRename
| FileSeek
| FileStat
| FileSync


error
else
res
end
else
error
end

fun f64(offset: ISize = 0): F64 ? =>
"""
Convert this string starting at the given offset
to a 64-bit floating point number ([F64](builtin-F64.md)).

This method errors if this string cannot be parsed to a float,
if the result would over- or underflow,
the offset exceeds the size of this string or
there are leftover characters in the string after conversion.

Examples:


that: FileStat val

Returns¶

Bool val

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

Parameters¶

that: FileStat val

Returns¶


fun box netrom_idle()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netrom_n2¶
[Source]


```pony
use "collections"

class Foo
fun foo(str: String): Hashable =>
object is Hashable
let s: String = str
fun apply(): String => s
fun hash(): USize => s.hash()
end
```

When we assign to a field in the constructor, we are _capturing_ from the lexical scope the object literal is in. Pretty fun stuff! It lets us have arbitrarily complex __closures__ that can even have multiple entry points (i.e. functions you can call on a closure).

An object literal with fields is returned as a `ref` by default unless an explicit reference capability is declared by specifying the capability after the `object` keyword. For example, an object with sendable captured references can be declared as `iso` if needed:

```pony
use "collections"


Bool val

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

Parameters¶

y: A

Returns¶

A

max¶


Bool val

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

Parameters¶

that: Ini val

Returns¶

Bool val

ne¶


y: I32 val

Returns¶

I32 val

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

Parameters¶

y: I32 val

Returns¶


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


offset: ISize val
len: USize val = 1

Returns¶

None val

substring¶
[Source]
Returns a substring. Index range [from .. to) is half-open.
Returns an empty string if nothing is in the range.
Note that this operation allocates a new string to be returned. For
similar operations that don't allocate a new string, see trim and
trim_in_place.
fun box substring(
from: ISize val,
to: ISize val = call)
: String iso^


"""
match direction
| EraseRight => "\x1B[0K"
| EraseLeft => "\x1B[1K"
| EraseLine => "\x1B[2K"
end

fun reset(): String =>
"""
Resets all colours and text styles to the default.
"""
"\x1B[0m"

fun bold(state: Bool = true): String =>
"""
Bold text. Does nothing on Windows.
"""
if state then "\x1B[1m" else "\x1B[22m" end

fun underline(state: Bool = true): String =>


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

Parameters¶

y: F32 val

Returns¶

(F32 val , F32 val)

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


list.pony

1
2
3
4
5
6
7
8
9
10
11


fun box i16_unsafe()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64_unsafe¶
[Source]


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


## Break

Sometimes you want to stop part-way through a loop and give up altogether. Pony has the `break` keyword for this and it is very similar to its counterpart in languages like C++, C#, and Python.

`break` immediately exits from the innermost loop it's in. Since the loop has to return a value `break` can take an expression. This is optional, and if it's left out, the value from the `else` block is returned.

Let's have an example. Suppose you want to go through a list of names, looking for either "Jack" or "Jill". If neither of those appear, you'll just take the last name you're given, and if you're not given any names at all, you'll use "Herbert".

```pony
var name =
while moreNames() do
var name' = getName()
if name' == "Jack" or name' == "Jill" then
break name'
end
name'
else
"Herbert"
end
```


fun box has_next()
: Bool val

Returns¶

Bool val

next¶
[Source]
Returns the next entry, or raises an error if there isn't one. If entries
are added during iteration, this may not return all entries.
fun ref next()
: (M->K , M->V) ?

Returns¶

(M->K , M->V) ?


y: U8 val

Returns¶

I8 val

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

Parameters¶

y: U8 val

Returns¶


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


572
573
574
575
576
577
578
579
580
581
582type List[A] is (Cons[A] | Nil[A])
"""
A persistent list with functional transformations.


Contiguous, resizable memory to store elements of type A.


Bool val


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


test(_TestAdd)
test(_TestSub)

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

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

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

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

The make() constructor is not needed for this example. However, it allows for
easy aggregation of tests (see below) so it is recommended that all test Mains
provide it.
Main.create() is called only for program invocations on the current package.
Main.make() is called during aggregation. If so desired extra code can be added


y: I64 val

Returns¶

I64 val

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

Returns¶

USize val

addc¶
[Source]


Returns¶

F32 val

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

Returns¶

F32 val

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


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

Parameters¶

y: A

Returns¶

A

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

Returns¶


fun box ipproto_cpnx()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_ddp¶
[Source]


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


HashSet[A: A, H: HashFunction[A!] val]¶
[Source]
A set, built on top of a HashMap. This is implemented as map of an alias of
a type to itself
class ref HashSet[A: A, H: HashFunction[A!] val] is
Comparable[HashSet[A, H] box] ref

Implements¶

Comparable[HashSet[A, H] box] ref

Constructors¶


Format package¶
The Format package provides support for formatting strings. It can be
used to set things like width, padding and alignment, as well as
controlling the way numbers are displayed (decimal, octal,
hexadecimal).
Example program¶
use "format"

actor Main
fun disp(desc: String, v: I32, fmt: FormatInt = FormatDefault): String =>
Format(desc where width = 10)
+ ":"
+ Format.int[I32](v where width = 10, align = AlignRight, fmt = fmt)


When an error happens, do a non-graceful close.
"""
if not _connected then
return
end

_connected = false
_closed = true
_shutdown = true
_shutdown_peer = true

_pending_writev_total = 0
ifdef windows then
_pending_writev_windows.clear()
_pending_sent = 0
else
_pending_writev_posix.clear()
end

// Unsubscribe immediately and drop all pending writes.


Create a generator for strings of ASCII letters,
with a minimum length of `min` (default: 0)
and a maximum length of `max` (default: 100).
"""
ascii(min, max, ASCIILetters)

fun utf32_codepoint_string(
gen: Generator[U32],
min: USize = 0,
max: USize = 100)
: Generator[String]
=>
"""
Create a generator for strings
from a generator of unicode codepoints,
with a minimum length of `min` codepoints (default: 0)
and a maximum length of `max` codepoints (default: 100).

Note that the byte length of the generated string can be up to 4 times
the size in code points.


Returns¶

A

div_unsafe¶
[Source]
Integer division, rounded towards zero.
Unsafe operation.
If y is 0, the result is undefined.
If the operation overflows, the result is undefined.
fun box div_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶


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


reader.pony

1
2
3
4
5
6
7
8
9
10
11


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


array.pony

1
2
3
4
5
6
7
8
9
10
11


## Zero Argument Constructors

```pony
class Hawk
var _hunger_level: U64 = 0

class Owl
var _hunger_level: U64

new create() =>
_hunger_level = 42
```

Here we have two classes, because the `Hawk` class defines no constructors, a default constructor with zero arguments called `create` is generated. The `Owl` defines its own constructor that sets the `_hunger_level`.

When constructing instances of classes that have zero-argument constructors, they can be constructed with just the class name:

```pony
class Forest
let _owl: Owl = Owl


use @"llvm.floor.f64"[F64](x: F64)
use @"llvm.round.f32"[F32](x: F32)
use @"llvm.round.f64"[F64](x: F64)
use @"llvm.trunc.f32"[F32](x: F32)
use @"llvm.trunc.f64"[F64](x: F64)
use @"llvm.log.f32"[F32](x: F32)
use @"llvm.log.f64"[F64](x: F64)
use @"llvm.log2.f32"[F32](x: F32)
use @"llvm.log2.f64"[F64](x: F64)
use @"llvm.log10.f32"[F32](x: F32)
use @"llvm.log10.f64"[F64](x: F64)
use @logbf[F32](x: F32)
use @logb[F64](x: F64)
use @"llvm.pow.f32"[F32](x: F32, y: F32)
use @"llvm.pow.f64"[F64](x: F64, y: F64)
use @"llvm.powi.f32"[F32](x: F32, y: I32) if not windows
use @"llvm.powi.f64"[F64](x: F64, y: I32) if not windows
use @"llvm.sqrt.f32"[F32](x: F32)
use @"llvm.sqrt.f64"[F64](x: F64)
use @cbrtf[F32](x: F32)


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


F32 val

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

Returns¶

F32 val

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

Returns¶


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

Parameters¶

y: USize val

Returns¶

(USize val , USize val)

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

Parameters¶


fun ref collect[B: Seq[A!] ref = Array[A!]](coll: B): B^ =>
"""
Push each value from the iterator into the collection `coll`.


y: A

Returns¶

A ?

divrem_partial¶
[Source]
Divides this number by y and calculates the remainder of the operation.
If y is 0 or the operation overflows, this function errors.
fun box divrem_partial(
y: A)
: (A , A) ?

Parameters¶

y: A

Returns¶


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128_unsafe¶
[Source]


# Callbacks

Some C APIs let the programmer specify functions that should be called to do pieces of work. For example, the SQLite API has a function called `sqlite3_exec` that executes an SQL statement and calls a function given by the programmer on each row returned by that statement. The functions that are supplied by the programmer are known as "callback functions". Some specific Pony functions can be passed as callback functions.


# Array Literals

Array literals are enclosed by square brackets. Array literal elements can be any kind of expressions. They are separated by semicolon or newline:

```pony
let my_literal_array =
[
"first"; "second"
"third one on a new line"
]
```


y: U128 val

Returns¶

U128 val

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

Returns¶

U128 val

op_and¶
[Source]


Parameters¶

that: F32 val

Returns¶

(Less val | Equal val | Greater val)


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


target_clean.find(sep(), target_i)?
else
target_clean.size().isize()
end

if
(to_i != target_i) or
(to_clean.compare_sub(target_clean, target_i.usize()) isnt Equal)
then
break
end

if to_i < to_clean.size().isize() then
to_i = to_i + 1
end

if target_i < target_clean.size().isize() then
target_i = target_i + 1
end


Command¶
[Source]
Command contains all of the information describing a command with its spec
and effective options and arguments, ready to use.
class box Command

Public Functions¶
string¶
[Source]
Returns a representational string for this command.
fun box string()
: String iso^


(Less val | Equal val | Greater val)


fun box u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶
[Source]


A

divrem_unsafe¶
[Source]
Calculates the quotient of this number and y and the remainder.
Unsafe operation.
If y is 0, the result is undefined.
If the operation overflows, the result is undefined.
fun box divrem_unsafe(
y: A)
: (A , A)

Parameters¶

y: A

Returns¶


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

Returns¶

U32 val

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

Parameters¶


fun box i64_unsafe()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong_unsafe¶
[Source]


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

Returns¶

U16 val

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

Returns¶

U32 val


Parameters¶

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

Returns¶

Arg val^

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

Returns¶


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

ifdef linux or bsd then
FileInfo._relative(_fd, path', target)?
else
FileInfo(path')?
end

fun chmodat(target: String, mode: FileMode box): Bool =>
"""
Set the FileMode for some path relative to this directory.
"""
if
not path.caps(FileChmod)
or not path.caps(FileLookup)
or (_fd == -1)
then
return false
end


Logs are printed one test at a time to avoid interleaving log lines from
concurrent tests.
"""
_runner.log(msg, verbose)

fun fail(msg: String = "Test failed") =>
"""
Flag the test as having failed.
"""
_runner.fail(msg)

fun assert_true(actual: Bool, msg: String = "", loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the given expression is true.
"""
if not actual then
fail(_format_loc(loc) + "Assert true failed. " + msg)


host: String,
service: String,
from: String = "",
read_buffer_size: USize = 16384,
yield_after_reading: USize = 16384,
yield_after_writing: USize = 16384)
=>
"""
Connect via IPv6.
"""
_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()


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


trait val SignedInteger[A: SignedInteger[A, B] val,
B: UnsignedInteger[B] val] is Integer[A]
fun abs(): B

fun shl(y: B): A => this << y
fun shr(y: B): A => this >> y

fun shl_unsafe(y: B): A =>
"""
Unsafe operation.
If bits differing from the final sign bit are shifted-out, the result is
undefined.
"""
this <<~ y

fun shr_unsafe(y: B): A =>
"""
Unsafe operation.
If non-zero bits are shifted-out, the result is undefined.
"""


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26primitive CommonPrefix
"""
Creates a string that is the common prefix of the supplied strings, possibly
empty.
"""


Pointer[A: A]¶
[Source]
A Pointer[A] is a raw memory pointer. It has no descriptor and thus can't be
included in a union or intersection, or be a subtype of any interface. Most
functions on a Pointer[A] are private to maintain memory safety.
struct ref Pointer[A: A]

Constructors¶
create¶
[Source]
A null pointer.
new ref create()
: Pointer[A] ref^


new max_value() => 0xFF

fun next_pow2(): U8 =>
let x = (this - 1).clz()
1 << (if x == 0 then 0 else bitwidth() - x end)

fun abs(): U8 => this
fun bit_reverse(): U8 => @"llvm.bitreverse.i8"(this)
fun bswap(): U8 => this
fun popcount(): U8 => @"llvm.ctpop.i8"(this)
fun clz(): U8 => @"llvm.ctlz.i8"(this, false)
fun ctz(): U8 => @"llvm.cttz.i8"(this, false)

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


# Long tests

Simple tests run within a single function. When that function exits, either returning or raising an error, the test is complete. This is not viable for tests that need to use actors.

Long tests allow for delayed completion. Any test can call `long_test()` on its `TestHelper` to indicate that it needs to keep running. When the test is finally complete it calls `complete()` on its `TestHelper`.

The `complete()` function takes a `Bool` parameter to specify whether the test was a success. If any asserts fail then the test will be considered a failure regardless of the value of this parameter. However, `complete()` must still be called.

Since failing tests may hang, a timeout must be specified for each long test. When the test function exits a timer is started with the specified timeout. If this timer fires before `complete()` is called the test is marked as a failure and the timeout is reported.

On a timeout, the `timed_out()` function is called on the unit test object. This should perform whatever test specific tidy up is required to allow the program to exit. There is no need to call `complete()` if a timeout occurs, although it is not an error to do so.

Note that the timeout is only relevant when a test hangs and would otherwise prevent the test program from completing. Setting a very long timeout on tests that should not be able to hang is perfectly acceptable and will not make the test take any longer if successful.

Timeouts should not be used as the standard method of detecting if a test has failed.


* Harvested by recipe given in socket.c
*/

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

// levels
fun ipproto_3pc():I32 => @pony_os_sockopt_level(I32(4000))
fun ipproto_adfs():I32 => @pony_os_sockopt_level(I32(4001))
fun ipproto_ah():I32 => @pony_os_sockopt_level(I32(4002))
fun ipproto_ahip():I32 => @pony_os_sockopt_level(I32(4003))
fun ipproto_apes():I32 => @pony_os_sockopt_level(I32(4004))
fun ipproto_argus():I32 => @pony_os_sockopt_level(I32(4005))
fun ipproto_ax25():I32 => @pony_os_sockopt_level(I32(4006))
fun ipproto_beetph():I32 => @pony_os_sockopt_level(I32(4007))
fun ipproto_bha():I32 => @pony_os_sockopt_level(I32(4008))
fun ipproto_blt():I32 => @pony_os_sockopt_level(I32(4009))
fun ipproto_brsatmon():I32 => @pony_os_sockopt_level(I32(4010))


IniMap¶
[Source]
type IniMap is
HashMap[String val, HashMap[String val, String val, HashEq[String val] val] ref, HashEq[String val] val] ref

Type Alias For¶

HashMap[String val, HashMap[String val, String val, HashEq[String val] val] ref, HashEq[String val] val] ref


fun box sock_cloexec()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sock_maxaddrlen¶
[Source]


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


Adds a byte to the beginning of the string.
"""
if value != 0 then
reserve(_size + 1)
@memmove(_ptr.usize() + 1, _ptr.usize(), _size + 1)
_set(0, value)
_size = _size + 1
else
_set(0, 0)
_size = 0
end

fun ref shift(): U8 ? =>
"""
Removes a byte from the beginning of the string.
"""
if _size > 0 then
let value = _ptr._apply(0)
@memmove(_ptr.usize(), _ptr.usize() + 1, _size)
_size = _size - 1


fun box sol_local()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_netrom¶
[Source]


prompt¶
[Source]
fun ref prompt(
term: ANSITerm ref,
value: String val)
: None val

Parameters¶

term: ANSITerm ref
value: String val

Returns¶

None val

size¶
[Source]


A

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

Returns¶

A

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

Returns¶


y: box->A

Returns¶

Bool val

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

Parameters¶


new_path: FilePath val

Returns¶

Bool val

symlink¶
[Source]
Create a symlink to a file or directory.
Note that on Windows a program must be running with elevated priviledges to
be able to create symlinks.
fun val symlink(
link_name: FilePath val)
: Bool val

Parameters¶

link_name: FilePath val


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

Parameters¶

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

Returns¶

Bool val

assert_eq[A: (Equatable[A] #read & Stringable #read)]¶
[Source]
Assert that the 2 given expressions are equal.
fun box assert_eq[A: (Equatable[A] #read & Stringable #read)](


let c_auth = TCPConnectAuth(env.root)
let bp_auth = ApplyReleaseBackpressureAuth(env.root)
let socket = TCPConnection(c_auth,
recover SlowDown(bp_auth, env.out) end, "", "7669")

```

Or if you want, you could handle backpressure by shedding load, that is,
dropping the extra data rather than carrying out the send. This might look
like:

```pony
use "net"

class ThrowItAway is TCPConnectionNotify
var _throttled: Bool = false

fun ref sent(conn: TCPConnection ref, data: ByteSeq): ByteSeq =>
if not _throttled then
data


var offset = ISize(0)
var occur = USize(0)

try
while true do
offset = find(from, offset)?
cut_in_place(offset, offset + from_len)
insert_in_place(offset, to)
offset = offset + to_len
occur = occur + 1

if (n > 0) and (occur >= n) then
break
end
end
end
occur

fun split_by(
delim: String,


gen3¶
[Source]
The Generator for the third argument to your property3 method.
fun box gen3()
: Generator[T3] box

Returns¶

Generator[T3] box

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

Returns¶

Generator[(T1 , T2 , T3)] box


# Aliasing and deny guarantees

The reason for this is that the `iso` reference capability denies other `iso` variables that point to the same object. That is, you can only have one `iso` variable pointing to any given object. The same goes for `trn`.

```pony
fun test(a: Wombat iso) =>
var b: Wombat iso = a // Not allowed!
```

Here we have some function that gets passed an isolated Wombat. If we try to alias `a` by assigning it to `b`, we'll be breaking reference capability guarantees, so the compiler will stop us. Instead, we can only store aliases that are compatible with the original capability.

__What can I alias an `iso` as?__ Since an `iso` says no other variable can be used by _any_ actor to read from or write to that object, we can only create aliases to an `iso` that can neither read nor write. Fortunately, we have a reference capability that does exactly that: `tag`. So we can do this and the compiler will be happy:

```pony
fun test(a: Wombat iso) =>
var b: Wombat tag = a // Allowed!
```

__What about aliasing `trn`?__ Since a `trn` says no other variable can be used by _any_ actor to write to that object, we need something that doesn't allow writing but also doesn't prevent our `trn` variable from writing. Fortunately, we have a reference capability that does that too: `box`. So we can do this and the compiler will be happy:


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

Parameters¶

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

Returns¶

ListNodes[A, N] ref^

Public Functions¶


"80")
```
"""
fun apply(wrap: TCPConnectionNotify iso): TCPConnectionNotify iso^ => wrap


primitive FormatGeneralLarge is FormatSpec

type FormatFloat is
( FormatDefault
| FormatExp
| FormatExpLarge
| FormatFix
| FormatFixLarge
| FormatGeneral
| FormatGeneralLarge )


: A^ ?

Parameters¶

value: box->A!

Returns¶

A^ ?

union¶
[Source]
Add everything in that to the set.
fun ref union(
that: Iterator[A^] ref)
: None val

Parameters¶


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


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


1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211


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

fun string(): String iso^ =>
_StringifyIntArg(choice, int)

type IntUnitTest is Property1UnitTest[IntPropertySample]

trait IntProperty is Property1[IntPropertySample]
"""
A property implementation for conveniently evaluating properties
for all Pony Integer types at once.

The property needs to be formulated inside the method `int_property`:

```pony
class DivisionByZeroProperty is IntProperty
fun name(): String => "div/0"


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


"""
Use seed x to seed a [SplitMix64](random-SplitMix64.md) and use this to
initialize the 128 bits of state.
"""
let sm = SplitMix64(x)
_x = sm.next()
_y = sm.next()

new create(x: U64 = 5489, y: U64 = 0) =>
"""
Create with the specified seed. Returned values are deterministic for a
given seed.
"""
_x = x
_y = y
next()

fun ref next(): U64 =>
"""
A random integer in [0, 2^64)


Returns¶

String iso^

reverse_in_place¶
[Source]
Reverses the byte order in the string. This needs to be changed to handle
UTF-8 correctly.
fun ref reverse_in_place()
: None val

Returns¶

None val

push¶
[Source]


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

Parameters¶

that: Help val

Returns¶

Bool val

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

Parameters¶


promise.pony

1
2
3
4
5
6
7
8
9
10
11


fun ref property2(arg1: T1, arg2: T2, h: PropertyHelper) ? =>
prop(consume arg1, consume arg2, h)?
end
).apply(_helper)?

class ForAll3[T1, T2, T3]
let _gen1: Generator[T1] val
let _gen2: Generator[T2] val
let _gen3: Generator[T3] val
let _helper: TestHelper

new create(
gen1': Generator[T1] val,
gen2': Generator[T2] val,
gen3': Generator[T3] val,
h: TestHelper)
=>
_gen1 = gen1'
_gen2 = gen2'
_gen3 = gen3'


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


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


ILong val

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

Parameters¶

y: ILong val

Returns¶

ILong val

mul_unsafe¶


Any¶
[Source]
interface tag Any


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

Parameters¶

that: EraseLeft val

Returns¶

Bool val

ne¶
[Source]


| 0 =>
output = value << 2
state = 1
| 1 =>
out.push(output or (value >> 4))
output = (value and 0x0f) << 4
state = 2
| 2 =>
out.push(output or (value >> 2))
output = (value and 0x03) << 6
state = 3
| 3 =>
out.push(output or value)
state = 0
else
error
end
end

if output != 0 then


| `embed`             | embed a class as a field of another class                                                              |
| `end`               | ending of: `if then`, `ifdef`, `while do`, `for in`, `repeat until`, `try`, `object`, `recover`, `match`         |
| `error`             | raises an error                                                                                |
| `for`               | loop statement                                                                                |
| `fun`               | define a function, executed synchronously                                                              |
| `if`                | (1) conditional statement                                                                              |
|                   | (2) to define a guard in a pattern match                                                               |
| `ifdef`             | when defining a build flag at compile time:  ponyc –D "foo"                                            |
| `iftype`            | type conditional statement `iftype A <: B` checks if `A` is a subtype of `B`                           |
| `in`                | used in a for in - loop statement                                                                      |
| `interface`         | used in structural subtyping                                                                           |
| `is`                | (1) used in nominal subtyping                                                                          |
|                   | (2) in type aliasing                                                                                |
|                   | (3) identity comparison                                                                                |
| `isnt`              | negative identity comparison                                                                           |
| `iso`               | reference capability – read and write uniqueness                                                       |
| `let`               | declaration of immutable variable: you can't rebind this name to a new value                           |
| `match`             | pattern matching                                                                                |
| `new`               | constructor                                                                                |
| `not`               | logical negation                                                                                |


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

Parameters¶

y: U16 val

Returns¶

U16 val

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

Returns¶


_history.shift()?
end
end

_history.push(line)
_cur_line = _history.size()

fun ref _load_history() =>
"""
Load the history from a file.
"""
_history.clear()

try
with file = File.open(_path as FilePath) do
for line in file.lines() do
_add_history(consume line)
end
end
end


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

Parameters¶

value: USize val

Returns¶

USize val^

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


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


Returns¶

U16 val ?

update_u32[optional B: (A & Real[B] val & U8 val)]¶
[Source]
Write a U32 at offset. This is only allowed for an array of U8s.
fun ref update_u32[optional B: (A & Real[B] val & U8 val)](
offset: USize val,
value: U32 val)
: U32 val ?

Parameters¶

offset: USize val
value: U32 val

Returns¶


// span>Hello!</span
// b>
```

Adjacent delimiters result in a zero length entry in the array. For
example, `"1CutCut2".split_by("Cut") => ["1", "", "2"]`.

An empty delimiter results in an array that contains a single element equal
to the whole string.

If you want to split the string with each individual character of `delim`,
use [`split`](#split).
"""
let delim_size = ISize.from[USize](delim.size())
let total_size = ISize.from[USize](size())

let result = recover Array[String] end
var current = ISize(0)

while ((result.size() + 1) < n) and (current < total_size) do


fun box eq(
y: U8 val)
: Bool val

Parameters¶

y: U8 val

Returns¶

Bool val

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

Parameters¶


y: I64 val

Returns¶

I64 val

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

Parameters¶

y: I64 val

Returns¶


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


Bool val

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

Parameters¶

that: String box

Returns¶

Bool val


fun box ipproto_sctp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_send¶
[Source]


set_time_at(target, Time.now(), Time.now())

fun set_time_at(
target: String,
atime: (I64, I64),
mtime: (I64, I64))
: Bool
=>
"""
Set the last access and modification times of the directory to the given
values.
"""
if
not path.caps(FileChown)
or not path.caps(FileLookup)
or (_fd == -1)
then
return false
end


: Generator[Map[K, V]]
=>
"""
Create a generator for `Map` from a generator of key-value tuples.
The generated maps will have a size up to `max`,
but tend to have fewer entries depending on the source generator `gen`.

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

let result: Map[K, V] =
Map[K, V].create(size).>concat(
Iter[(K^, V^)](gen.value_iter(rnd))
.take(size)


fun box sctp_initiation()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_initmsg¶
[Source]


usize¶
fun box usize()
: USize val

Returns¶

USize val

f32¶
fun box f32()
: F32 val

Returns¶

F32 val

f64¶


fun box u128_unsafe()
: U128 val

Returns¶

U128 val

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

Returns¶

ULong val

usize_unsafe¶
[Source]


# Comments

Use __docstrings__ first! But if you need to put some comments in the implementation of your methods, perhaps to explain what's happening on various lines, you can use C++ style comments. In Pony, block comments can be nested.

```pony
// This is a line comment.
/* This is a block comment. */
/* This block comment /* has another block comment */ inside of it. */
```


fun ref writev(data: ByteSeqIter) =>
"""
Write ByteSeqs to the buffer.
"""
for chunk in data.values() do
write(chunk)
end

fun ref done(): Array[ByteSeq] iso^ =>
"""
Return an array of buffered ByteSeqs and reset the Writer's buffer.
"""
_append_current()
_size = 0
_chunks = recover Array[ByteSeq] end

fun ref _append_current() =>
if _current.size() > 0 then
_chunks.push(_current = recover Array[U8] end)
end


params() method.
The gen() method is called exactly once to
instantiate the generator.
The generator produces
PropertyParams.num_samples
samples and each is passed to the
property method for verification.
If the property did not verify, the given sample is shrunken if the
generator supports shrinking.
The smallest shrunken sample will then be reported to the user.
A Property1 can be run with
Ponytest.
To that end it needs to be wrapped into a
Property1UnitTest.
trait ref Property1[T: T]

Public Functions¶
name¶
[Source]
The name of the property used for reporting during execution.


Parameters¶

y: ILong val

Returns¶

ILong val

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

Parameters¶

y: ILong val

Returns¶


```

Unfortunately, this doesn't compile. For a generic class to compile it must be compilable for all possible types and reference capabilities that satisfy the constraints in the type parameter. In this case, that's any type with any reference capability. The class works for the specific reference capability of `val` as we saw earlier, but how well does it work for `ref`? Let's expand it and see:

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

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

fun get(): String ref => _c

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

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


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

Parameters¶

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

Returns¶


fun modc(y: I128): (I128, Bool) =>
_SignedCheckedArithmetic.mod_checked[I128, U128](this, y)

fun add_partial(y: I128): I128 ? =>
_SignedPartialArithmetic.add_partial[I128](this, y)?

fun sub_partial(y: I128): I128 ? =>
_SignedPartialArithmetic.sub_partial[I128](this, y)?

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

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

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

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


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


ULong val

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

Parameters¶

y: ULong val

Returns¶

ULong val

shr_unsafe¶
[Source]


I16 val

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

Returns¶

I32 val

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

Returns¶


# Combining Capabilities

When we talked about fields in the [classes](/types/classes.md) and [variables](/expressions/variables.md) chapters, we passed over the detail of field capabilities. Fields, just like variables, have their own capabilities! A `val` field still refers to something permanently immutable. A `tag` field still can't be read from. An `iso` field is still globally unique: it can only be accessed except through this field of a single instance.

Once we have fields with capabilities inside objects with capabilities, now we have two capabilities to keep track of.  When a field of an object is accessed or extracted, its reference capability depends both on the reference capability of the field and the reference capability of the __origin__, that is, the object the __field__ is being read from. We have to pick a capability for the combination that maintains the guarantees for both the __origin__ reference capability, and for the capability of the __field__.


# Whitespace

Whitespace (e.g. spaces, tabs, newlines, etc.) in Pony isn't significant.

Well, it mostly isn't significant.


Info:
.../a.pony:4:5: receiver type: this->Array[String val] ref
colors.push(color)
^
.../ponyc/packages/builtin/array.pony:252:3: target type: Array[String val] ref
fun ref push(value: A): Array[A]^ =>
^
.../a.pony:2:15: Array[String val] box is not a subtype of Array[String val] ref: box is not a subtype of ref
let colors: Array[String] = Array[String]()
^
```

Once again, Pony is trying to be helpful. The first few lines describe the error, in general terms that only a programming language maven would like: an incompatibility between the receiver type and the target type. However, Pony provides more information: the lines immediately after "Info:" tell you what it believes the receiver type to be and the next few lines describe what it believes the target type to be. Finally, the last few lines describe in detail what the problem is.

Unfortunately, this message does not locate the error as clearly as the previous examples.

Breaking it down, the issue seems to be with the call to `push`, with the receiver `colors`. The receiver type is `this->Array[String val] ref`; in other words, the view that this method has of a field whose type is `Array[String val] ref`. In the class `Rainbow`, the field `colors` is indeed declared with the type `Array[String]`, and the default reference capability for `String`s is `val` while the default reference capability for `Array` is `ref`.

The "target type" in this example is the type declaration for the method `push` of the class `Array`, with its type variable `A` replaced by `String` (again, with a default reference capability of `val`). The reference capability for the overall array, as required by the receiver reference capability of `push`, is `ref`. It seems that the receiver type and the target type should be pretty close.


fun box ipv6_flowinfo()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_flowinfo_priority¶
[Source]


ProcessExitStatus¶
[Source]
Representing possible exit states of processes.
A process either exited with an exit code or, only on posix systems,
has been terminated by a signal.
type ProcessExitStatus is
(Exited val | Signaled val)

Type Alias For¶

(Exited val | Signaled val)


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

Parameters¶

array: Array[A] ref

Returns¶

None val


fun sctp_cause_missing_param():I32 => @pony_os_sockopt_option(I32(542))
fun sctp_cause_nat_colliding_state():I32 => @pony_os_sockopt_option(I32(543))
fun sctp_cause_nat_missing_state():I32 => @pony_os_sockopt_option(I32(544))
fun sctp_cause_no_error():I32 => @pony_os_sockopt_option(I32(545))
fun sctp_cause_no_user_data():I32 => @pony_os_sockopt_option(I32(546))
fun sctp_cause_out_of_resc():I32 => @pony_os_sockopt_option(I32(547))
fun sctp_cause_protocol_violation():I32 => @pony_os_sockopt_option(I32(548))
fun sctp_cause_request_refused():I32 => @pony_os_sockopt_option(I32(549))
fun sctp_cause_resource_shortage():I32 => @pony_os_sockopt_option(I32(550))
fun sctp_cause_restart_w_newaddr():I32 => @pony_os_sockopt_option(I32(551))
fun sctp_cause_stale_cookie():I32 => @pony_os_sockopt_option(I32(552))
fun sctp_cause_unrecog_chunk():I32 => @pony_os_sockopt_option(I32(553))
fun sctp_cause_unrecog_param():I32 => @pony_os_sockopt_option(I32(554))
fun sctp_cause_unresolvable_addr():I32 => @pony_os_sockopt_option(I32(555))
fun sctp_cause_unsupported_hmacid():I32 => @pony_os_sockopt_option(I32(556))
fun sctp_cause_user_initiated_abt():I32 => @pony_os_sockopt_option(I32(557))
fun sctp_cc_hstcp():I32 => @pony_os_sockopt_option(I32(558))
fun sctp_cc_htcp():I32 => @pony_os_sockopt_option(I32(559))
fun sctp_cc_option():I32 => @pony_os_sockopt_option(I32(560))
fun sctp_cc_opt_rtcc_setmode():I32 => @pony_os_sockopt_option(I32(561))


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

Implements¶

Equatable[A] ref

Public Functions¶
lt¶
[Source]


AsyncBenchContinue¶
[Source]
class val AsyncBenchContinue

Public Functions¶
complete¶
[Source]
fun box complete()
: None val

Returns¶

None val


ULong val

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

Parameters¶

y: ULong val

Returns¶

ULong val

div_unsafe¶
[Source]


Bool val

merge¶
[Source]
Merge the rights in that into this.
fun ref merge(
that: CapRights0 ref)
: None val

Parameters¶

that: CapRights0 ref

Returns¶

None val

remove¶


let _name: String
let _bench: MicroBenchmark

new create(
ponybench: PonyBench,
benchmark: MicroBenchmark,
overhead: Bool)
=>
_ponybench = ponybench
_aggregator = _Aggregator(_ponybench, this, benchmark.config(), overhead)
_name = benchmark.name()
_bench = consume benchmark
apply()

be apply() =>
try
_bench.before()?
_gc_next_behavior()
_run_iteration()
else


fun ipctl_intrdqmaxlen():I32 => @pony_os_sockopt_option(I32(82))
fun ipctl_intrqdrops():I32 => @pony_os_sockopt_option(I32(83))
fun ipctl_intrqmaxlen():I32 => @pony_os_sockopt_option(I32(84))
fun ipctl_keepfaith():I32 => @pony_os_sockopt_option(I32(85))
fun ipctl_maxid():I32 => @pony_os_sockopt_option(I32(86))
fun ipctl_rtexpire():I32 => @pony_os_sockopt_option(I32(87))
fun ipctl_rtmaxcache():I32 => @pony_os_sockopt_option(I32(88))
fun ipctl_rtminexpire():I32 => @pony_os_sockopt_option(I32(89))
fun ipctl_sendredirects():I32 => @pony_os_sockopt_option(I32(90))
fun ipctl_sourceroute():I32 => @pony_os_sockopt_option(I32(91))
fun ipctl_stats():I32 => @pony_os_sockopt_option(I32(92))
fun ipport_ephemeralfirst():I32 => @pony_os_sockopt_option(I32(93))
fun ipport_ephemerallast():I32 => @pony_os_sockopt_option(I32(94))
fun ipport_hifirstauto():I32 => @pony_os_sockopt_option(I32(95))
fun ipport_hilastauto():I32 => @pony_os_sockopt_option(I32(96))
fun ipport_max():I32 => @pony_os_sockopt_option(I32(97))
fun ipport_reserved():I32 => @pony_os_sockopt_option(I32(98))
fun ipport_reservedstart():I32 => @pony_os_sockopt_option(I32(99))
fun ipport_userreserved():I32 => @pony_os_sockopt_option(I32(100))
fun ipv6_2292dstopts():I32 => @pony_os_sockopt_option(I32(101))


doesn't print an issue title.

`flatten_next` addresses the problem of "we want the `Issue`, not the
intermediate `Promise`". `flatten_next` takes an intermediate promise and
unwraps it into the fulfilled type. You get to write your promise chain
without having to worry about intermediate promises.

Updated to use `flatten_next`, our API example becomes:

```pony
actor Main
new create(env: Env) =>
let repo: Promise[Repository] =
GitHub("my token").get_repo("ponylang/ponyc")

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

issue.next[None](PrintIssueTitle~apply(env.out))


nth: USize = 0,
predicate: {(box->A!, box->A!): Bool} val =
{(l: box->A!, r: box->A!): Bool => l is r })
: USize ?
=>
"""
Find the `nth` appearance of `value` from the end of the array, starting at
`offset` and examining lower indices, and using the supplied `predicate` for
comparisons. Returns the index of the value, or raise an error if the value
isn't present.

By default, the search starts at the last element of the array, returns the
first instance of `value` found, and uses object identity for comparison.
"""
if _size > 0 then
var i = if offset >= _size then _size - 1 else offset end
var n = USize(0)

repeat
if predicate(_ptr._apply(i), value) then


fun box op_not()
: I64 val

Returns¶

I64 val

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

Parameters¶

y: I64 val

Returns¶


## Structural subtyping in Pony

Pony has structural subtyping using __interfaces__. Interfaces look like traits, but they use the keyword `interface`.

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

Here, `HasName` looks a lot like `Named`, except it's an interface instead of a trait. This means both `Bob` and `Larry` provide `HasName`! The programmers that wrote `Bob` and `Larry` don't even have to be aware that `HasName` exists.


fun box mul(
y: I128 val)
: I128 val

Parameters¶

y: I128 val

Returns¶

I128 val

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

Parameters¶


fun box sol_ax25()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_ipx¶
[Source]


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


that: ASCIIPrintable val

Returns¶

Bool val

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

Parameters¶

that: ASCIIPrintable val

Returns¶


IntPairPropertySample¶
[Source]
class ref IntPairPropertySample is
Stringable box

Implements¶

Stringable box

Constructors¶
create¶
[Source]


# And, long-running actors

Might cause unexpected out of memory errors, since the GC is not yet triggered on an out-of-memory segfault or stack exhaustion.

...


This method errors if this string cannot be parsed to a float,
if the result would over- or underflow,
the offset exceeds the size of this string or
there are leftover characters in the string after conversion.
Examples:
"1.5".f64()? == F64(1.5)
"1.19208e-07".f64()? == F64(1.19208e-07)
"Inf".f64()?.infinite() == true

fun box f64(
offset: ISize val = 0)
: F64 val ?

Parameters¶

offset: ISize val = 0

Returns¶

F64 val ?


fun box i16_unsafe()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64_unsafe¶
[Source]


152
153
154
155
156
157use "pony_test"

class iso Property1UnitTest[T] is UnitTest
"""
Provides plumbing for integration of PonyCheck
[Properties](pony_check-Property1.md) into [PonyTest](pony_test--index.md).

Wrap your properties into this class and use it in a
[TestList](pony_test-TestList.md):

```pony
use "pony_test"
use "pony_check"

class MyProperty is Property1[String]


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


fun box div_partial(
y: U32 val)
: U32 val ?

Parameters¶

y: U32 val

Returns¶

U32 val ?

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

Parameters¶


: T^ ?

Parameters¶

rnd: Randomness ref

Returns¶

T^ ?

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

Parameters¶

rnd: Randomness ref


Bool val

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

Parameters¶

y: box->A

Returns¶

Bool val

gt¶


y: I32 val

Returns¶

I32 val ?

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

Parameters¶

y: I32 val

Returns¶


PrefixSign¶
[Source]
primitive val PrefixSign is
PrefixSpec val

Implements¶

PrefixSpec val

Constructors¶
create¶
[Source]


fun box ctz_unsafe()
: U16 val

Returns¶

U16 val

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

Returns¶

U16 val

bytewidth¶
[Source]


cap: U64 val)
: None val

Parameters¶

cap: U64 val

Returns¶

None val

unset¶
[Source]
fun ref unset(
cap: U64 val)
: None val

Parameters¶


Constructors¶
from_u64¶
[Source]
Use seed x to seed a SplitMix64 and use this to
initialize the 128 bits of state.
new ref from_u64(
x: U64 val = 5489)
: XorOshiro128Plus ref^

Parameters¶

x: U64 val = 5489

Returns¶

XorOshiro128Plus ref^

create¶
[Source]


I64 val

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

Returns¶

I128 val

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

Returns¶


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


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


fun acl_delete(): U64 => _id(1, 1 << 17)
fun acl_get(): U64 => _id(1, 1 << 18)
fun acl_set(): U64 => _id(1, 1 << 19)

fun kqueue_change(): U64 => _id(1, 1 << 20)
fun kqueue(): U64 => kqueue_event() or kqueue_change()

fun _id(idx: U64, bit: U64): U64 =>
"""
Build a Capsicum ID from an index and a bit position.
"""
(1 << (57 + idx)) or bit


Parameters¶

that: Flags[A, B] box

Returns¶

Bool val

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

Parameters¶


I64 val^

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

Returns¶

I64 val^

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

Returns¶


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

Parameters¶

value: A

Returns¶

Real[A] val^

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


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


fun box so_netsvc_marking_level()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_nke¶
[Source]


ITest¶
[Source]
interface ref ITest

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

Returns¶

None val ?


"""
ifdef not windows then
// TODO: Make writev_batch_size user configurable
let writev_batch_size: USize = @pony_os_writev_max().usize()
var num_to_send: USize = 0
var bytes_to_send: USize = 0
var bytes_sent: USize = 0
while _writeable and (_pending_writev_total > 0) do
if bytes_sent >= _yield_after_writing then
// We've written _yield_after_writing bytes.
// Yield and write again later.
_write_again()
return false
end
try
// Determine number of bytes and buffers to send.
if _pending_writev_posix.size() < writev_batch_size then
num_to_send = _pending_writev_posix.size()
bytes_to_send = _pending_writev_total
else


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


USize val

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

Returns¶

USize val

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

Returns¶


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


try
_contains[B](head()?, a)
else
false
end

fun _contains[B: (A & HasEq[A!] #read) = A](
ln: this->ListNode[A],
a: box->B)
: Bool
=>
"""
Private helper for `contains`, recursively working with `ListNode`s.
"""
try
if a == ln()? then
true
else
_contains[B](ln.next() as this->ListNode[A], a)
end


fun box powi(
y: I32 val)
: F32 val

Parameters¶

y: I32 val

Returns¶

F32 val

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

Returns¶


Backward delete.
"""
if _cur_pos == 0 then
return
end

try
var c = U8(0)

repeat
_cur_pos = _cur_pos - 1
c = _edit.at_offset(_cur_pos)?
_edit.delete(_cur_pos, 1)
until
(_cur_pos == 0) or ((c and 0xC0) != 0x80)
end

_refresh_line()
end


y: F64 val

Returns¶

F64 val

mul_unsafe¶
fun box mul_unsafe(
y: F64 val)
: F64 val

Parameters¶

y: F64 val

Returns¶

F64 val


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

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

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

primitive ULong is UnsignedInteger[ULong]
new create(value: ULong) => value
new from[A: (Number & Real[A] val)](a: A) => a.ulong()

new min_value() => 0

new max_value() =>
ifdef ilp32 or llp64 then
0xFFFF_FFFF
else


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

Parameters¶

y: U8 val

Returns¶

Bool val

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

Parameters¶


- `for`
- `match`
- `|` (only as a case in a `match` expression)
- `recover`
- `object`
- `{` (only as a lambda)
- `with`
- `try`
- `then` (only when part of a `try` block)