// we have a sample that did not fail and thus can stop shrinking
fail(failed_repr, shrink_round.round())

else
// we have a failing shrink sample, recurse
_prepare_next_round()
do_shrink(last_repr)
end

be do_shrink(failed_repr: String) =>

// shrink iters can be infinite, so we need to limit
// the examples we consider during shrinking
let round_num = this._current_round.round()
if round_num == _params.max_shrink_rounds then
fail(failed_repr, round_num)
return
end

(let shrink, let current_repr) =


fun box ipproto_chaos()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_comp¶
[Source]


U8 val

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

Returns¶

U8 val

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

Returns¶


ISize val

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

Parameters¶

y: USize val

Returns¶

ISize val

shl_unsafe¶


[(F32(3.14159), "Hopper"); (F32(-83.83), "Jones")]]
for items in messages.values() do
wb.i32_be((items.size() / 2).i32())
for (f, s) in items.values() do
wb.f32_be(f)
wb.i32_be(s.size().i32())
wb.write(s.array())
end
let wb_msg = Writer
wb_msg.i32_be(wb.size().i32())
wb_msg.writev(wb.done())
env.out.writev(wb_msg.done())
end

class ref Writer

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


RejectAlways[A: Any #share]¶
[Source]
A reject that always raises an error.
class iso RejectAlways[A: Any #share]

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

Returns¶


fun box dir(
path: String val)
: String val

Parameters¶

path: String val

Returns¶

String val

ext¶
[Source]
Return the file extension, i.e. the part after the last dot as long as that
dot is after all separators. Return an empty string for no extension.
fun box ext(
path: String val)
: String val


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


The Generator for the second argument to your `property4` method.
"""

fun gen3(): Generator[T3]
"""
The Generator for the third argument to your `property4` method.
"""

fun gen4(): Generator[T4]
"""
The Generator for the fourth argument to your `property4` method.
"""

fun gen(): Generator[(T1, T2, T3, T4)] =>
Generators.zip4[T1, T2, T3, T4](
gen1(),
gen2(),
gen3(),
gen4())


## Working with Structs: from C to Pony

A common pattern in C is to pass a struct pointer to a function, and that function will fill in various values in the struct. To do this in Pony, you make a `struct` and then use a `NullablePointer`, which denotes a possibly-null type:

```pony
use @ioctl[I32](fd: I32, req: U32, ...)

struct Winsize
var height: U16 = 0
var width: U16 = 0

new create() => None

let size = Winsize

@ioctl(0, 21523, NullablePointer[Winsize](size))

env.out.print(size.height.string())
```


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


fun box ip_fw_table_flush()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_fw_table_list¶
[Source]


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


fun box u128()
: U128 val

Returns¶

U128 val

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

Returns¶

ULong val

usize¶
[Source]


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

Parameters¶

y: ISize val

Returns¶

ISize val

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


max_exp2¶
[Source]
Maximum exponent value such that (2^exponent) - 1 is representable.
fun tag max_exp2()
: I16 val

Returns¶

I16 val

max_exp10¶
[Source]
Maximum exponent value such that (10^exponent) - 1 is representable.
fun tag max_exp10()
: I16 val

Returns¶


Close the file. Future operations will do nothing.
"""
if _fd != -1 then
if (_pending_writev_total > 0) and (_errno is FileOK) then
flush()
end
if _unsynced_data or _unsynced_metadata then
sync()
end
let r = ifdef windows then
@_close(_fd)
else
@close(_fd)
end
if r < 0 then
_errno = _get_error()
end
_fd = -1

_pending_writev_total = 0


Bool val

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

Returns¶

USize val

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

Returns¶


fun box tipc_critical_importance()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_dest_droppable¶
[Source]


PropertyLogger¶
[Source]
interface val PropertyLogger

Public Functions¶
log¶
[Source]
fun box log(
msg: String val,
verbose: Bool val = false)
: None val

Parameters¶


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

Parameters¶

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

Returns¶

None val

concat¶
[Source]


Returns¶

String val

red¶
[Source]
Red text.
fun box red()
: String val

Returns¶

String val

green¶
[Source]
Green text.
fun box green()


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


IntPairProperty¶
[Source]
A property implementation for conveniently evaluating properties
for pairs of integers of all Pony integer types at once.
The property needs to be formulated inside the method int_property:
class CommutativeMultiplicationProperty is IntPairProperty
fun name(): String => "commutativity/mul"

fun int_property[T: (Int & Integer[T] val)](x: T, y: T, h: PropertyHelper)? =>
h.assert_eq[T](x * y, y * x)

trait ref IntPairProperty is
Property1[IntPairPropertySample ref] ref


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


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


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


Returns¶

None val

fail_action¶
[Source]
Call to fail an action, which will also cause the entire test to fail
immediately, without waiting the rest of the outstanding actions.
The name of the failed action will be included in the failure output.
Usually the action name should be an expected action set up by a call to
expect_action, but failing unexpected actions will also fail the test.
fun box fail_action(
name: String val)
: None val

Parameters¶

name: String val


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

Parameters¶

a: A

Returns¶

ULong val^

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

Returns¶


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


Return the last value of the iterator.
Example¶
Iter[I64]([1; 2; 3].values())
.last()

3
fun ref last()
: A ?

Returns¶

A ?

map[B: B]¶
[Source]
Return an iterator where each item's value is the application of the given
function to the value in the original iterator.
Example¶
Iter[I64]([1; 2; 3].values())


[Source]
No more input is available.
fun ref closed()
: None val

Returns¶

None val

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

Parameters¶


U32 val ?

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

Parameters¶

offset: USize val
value: U64 val

Returns¶

U64 val ?


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


FormatFix¶
[Source]
primitive val FormatFix is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


data: Array[U8 val] iso

Returns¶

None val

failed¶
[Source]
ProcessMonitor calls this if we run into errors communicating with the
forked process.
fun ref failed(
process: ProcessMonitor ref,
err: ProcessError val)
: None val

Parameters¶

process: ProcessMonitor ref
err: ProcessError val


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

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

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

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

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

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

primitive U32 is UnsignedInteger[U32]


32
33
34
35primitive Less is Equatable[Compare]
fun string(): String iso^ =>
"Less".string()

primitive Equal is Equatable[Compare]
fun string(): String iso^ =>
"Equal".string()

primitive Greater is Equatable[Compare]
fun string(): String iso^ =>
"Greater".string()

type Compare is (Less | Equal | Greater)

interface HasEq[A]
fun eq(that: box->A): Bool


num_to_send).isize()
end

if len < bytes_to_send.isize() then error end

// We've sent all the data we requested in this batch.
pending_total = pending_total - bytes_to_send
num_sent = num_sent + num_to_send.usize()
end

(true, num_sent, pending_total)

fun ref position(): USize =>
"""
Return the current cursor position in the file.
"""
if _fd != -1 then
let o: I64 = 0
let b: I32 = 1
let r = ifdef windows then


Bool val

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

Returns¶

Bool val

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

Returns¶


y: I32 val

Returns¶

I32 val ?

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

Parameters¶

y: I32 val

Returns¶


else
false
end

if same and ((steps = steps - 1) == 1) then
return true
end

i = i + 1
end
false

fun count(s: String box, offset: ISize = 0): USize =>
"""
Counts the non-overlapping occurrences of s in the string.
"""
let j: ISize = (_size - s.size()).isize()
var i: USize = 0
var k = offset


## Triple quoted Strings

For embedding multi-line text in string literals, there are triple quoted strings.

```pony
let triple_quoted_string_docs =
"""
Triple quoted strings are the way to go for long multi-line text.
They are extensively used as docstrings which are turned into api documentation.

They get some special treatment, in order to keep Pony code readable:

* The string literal starts on the line after the opening triple quote.
* Common indentation is removed from the string literal
so it can be conveniently aligned with the enclosing indentation
e.g. each line of this literal will get its first two whitespaces removed
* Whitespace after the opening and before the closing triple quote will be
removed as well. The first line will be completely removed if it only
contains whitespace. e.g. this strings first character is `T` not `\n`.
"""


Send any pending data. If any data can't be sent, keep it in _pending.
Once _pending is non-empty, direct writes will get queued there,
and they can only be written here. If the _done_writing flag is set, close
the pipe once we've processed pending writes.
"""
while (not _closed) and not _stdin.is_closed() and (_pending.size() > 0) do
try
let node = _pending.head()?
(let data, let offset) = node()?

// Write as much data as possible.
(let len, let errno) = _stdin.write(data, offset)

if len == -1 then // OS signals write error
if errno == _EAGAIN() then
// Resource temporarily unavailable, send data later.
return
else
// Close pipe and bail out.
_notifier.failed(this, ProcessError(WriteError))


match _parent
| let p: CommandParser box => p._root_spec()
else
_spec
end

fun _parse_command(
tokens: Array[String] ref,
options: Map[String,Option] ref,
args: Map[String,Arg] ref,
envsmap: Map[String, String] box,
ostop: Bool)
: (Command | CommandHelp | SyntaxError)
=>
"""
Parses all of the command line tokens and env vars into the given options
and args maps. Returns the first SyntaxError, or the Command when OK.
"""
var opt_stop = ostop
var arg_pos: USize = 0


Generators¶
[Source]
Convenience combinators and factories for common types and kind of Generators.
primitive val Generators

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

Returns¶


fun box so_protocol_info()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_proxyusr¶
[Source]


In either case, execution will then carry on with whatever code comes after the `try end`.

__Do I have to provide an error handler?__ No. The `try` block will handle any errors regardless. If you don't provide an error handler then no error handling action will be taken - execution will simply continue after the `try` expression.

If you want to do something that might raise an error, but you don't care if it does you can just put it in a `try` block without an `else`.

```pony
try
// Do something that may raise an error
end
```

__Is there anything my error handler has to do?__ No. If you provide an error handler then it must contain some code, but it is entirely up to you what it does.

__What's the resulting value of a try block?__ The result of a `try` block is the value of the last statement in the `try` block, or the value of the last statement in the `else` clause if an error was raised. If an error was raised and there was no `else` clause provided, the result value will be `None`.


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


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

Parameters¶

offset: USize val = 0

Returns¶

I128 val ?

peek_i128_le¶
[Source]


fun box ipproto_swipe()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_tcp¶
[Source]


fun ref truncate(len: USize)
"""
Truncate the sequence to the given length, discarding excess elements.
If the sequence is already smaller than len, do nothing.
"""

fun values(): Iterator[this->A]^
"""
Returns an iterator over the elements of the sequence.
"""


Returns an empty iterator over the elements of the empty list.
fun box values()
: Iterator[val->A] ref^

Returns¶

Iterator[val->A] ref^

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

Returns¶

Bool val


that: FileLookup val

Returns¶

Bool val

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

Parameters¶

that: FileLookup val

Returns¶


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


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

Parameters¶

y: U8 val

Returns¶

U8 val

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

Parameters¶


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


_list = list
this


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

Returns¶

Bool val


y: A)
: A

Parameters¶

y: A

Returns¶

A

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

Parameters¶


_size <= that._size

fun offset_to_index(i: ISize): USize =>
if i < 0 then i.usize() + _size else i.usize() end

fun bool(): Bool ? =>
match lower()
| "true" => true
| "false" => false
else
error
end

fun i8(base: U8 = 0): I8 ? => _to_int[I8](base)?
fun i16(base: U8 = 0): I16 ? => _to_int[I16](base)?
fun i32(base: U8 = 0): I32 ? => _to_int[I32](base)?
fun i64(base: U8 = 0): I64 ? => _to_int[I64](base)?
fun i128(base: U8 = 0): I128 ? => _to_int[I128](base)?
fun ilong(base: U8 = 0): ILong ? => _to_int[ILong](base)?
fun isize(base: U8 = 0): ISize ? => _to_int[ISize](base)?


FileSync¶
[Source]
primitive val FileSync

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

Returns¶

FileSync val^


Constructors¶
create¶
[Source]
Create am Iterator that counts down according to the specified arguments.
from is exclusive, to is inclusive.
new ref create(
from: T,
to: T = call)
: CountdownIter[T] ref^

Parameters¶

from: T
to: T = call

Returns¶

CountdownIter[T] ref^


+ " Expected (" + _print_array[A](expect) + ") == ("
+ _print_array[A](actual) + "):"
+ "\nMissing: " + _print_array[box->A](missing)
+ "\nExtra: " + _print_array[box->A](extra))
return false
end
log(
_format_loc(loc) + "Assert EQ_UNORDERED passed. " + msg + " Got ("
+ _print_array[A](expect) + ") == (" + _print_array[A](actual) + ")",
true)
true
else
fail("Assert EQ_UNORDERED failed from an internal error.")
false
end

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

fun _print_array[A: Stringable #read](array: ReadSeq[A]): String =>


if not _closed then
@pony_os_multicast_interface(_fd, from.cstring())
end

be set_multicast_loopback(loopback: Bool) =>
"""
By default, packets sent to a multicast address will be received by the
sending system if it has subscribed to that address. Disabling loopback
prevents this.
"""
if not _closed then
set_ip_multicast_loop(loopback)
end

be set_multicast_ttl(ttl: U8) =>
"""
Set the TTL for multicast sends. Defaults to 1.
"""
if not _closed then
set_ip_multicast_ttl(ttl)


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.
fun box rfind(
value: A!,
offset: USize val = call,
nth: USize val = 0,
predicate: {(box->A!, box->A!): Bool}[A] val = lambda)
: USize val ?

Parameters¶

value: A!
offset: USize val = call
nth: USize val = 0
predicate: {(box->A!, box->A!): Bool}[A] val = lambda


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

Parameters¶

y: U16 val

Returns¶

(U16 val , Bool val)

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

Parameters¶


ByteSeqIter¶
[Source]
Accept an iterable collection of String or Array[U8] val.
interface val ByteSeqIter

Public Functions¶
values¶
[Source]
fun box values()
: Iterator[(this->String box | this->Array[U8 val] box)] ref

Returns¶


**Explicit type**: An actor, class or primitive.

**Member**: Method or field.

**Method**: Something callable on a concrete type/object. Function, behaviour or constructor.

**Override**: When a concrete type has its own body for a method with a default body provided by a trait.

**Parentheses**: ( ). Synonymous with round brackets.

**Provide**: An entity's usage of traits and the methods they contain. Equivalent to implements or inherits from.

**Round brackets**: ( ). Synonymous with parentheses.

**Single type**: Any type which is not defined as a collection of other types. Actors, classes, primitives, traits and structural types are all single types. Opposite of a compound type.

**Square brackets**: [ ]

**Trait clash**: A trait clashes with another type if it contains a method with the same name, but incompatible signature as a method in the other type. A clashing trait is incompatible with the other type. Traits can clash with actors, classes, primitives, intersections, structural types and other traits.


elseif event is _event then
_advance()
end

fun ref _advance() =>
"""
Update the current time, process all the timing wheels, and set the event
for the next time we need to advance.
"""
let elapsed = _set_time()

try
for i in Range(0, _wheels()) do
if not _wheel(i)?.advance(_pending, _current, elapsed) then
break
end
end

for timer in _pending.values() do
_fire(timer)


frexp¶
[Source]
fun box frexp()
: (A , U32 val)

Returns¶

(A , U32 val)

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

Returns¶

A


+ "start with the given prefix.")
_env.out.print("  --verbose         - Show all test output.")
_env.out.print("  --sequential      - Run tests sequentially.")
_env.out.print("  --noprog          - Do not print progress messages.")
_env.out.print("  --list            - List but do not run tests.")
_env.out.print("  --label=label     - Only run tests with given label")
_do_nothing = true
return
end
end

fun _print_report() =>
"""
The tests are all complete, print out the results.
"""
var pass_count: USize = 0
var fail_count: USize = 0

// First we print the result summary for each test, in the order that they
// were given to us.


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


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


Parameters¶

s: String box
offset: ISize val = 0

Returns¶

Bool val

delete¶
[Source]
Delete len bytes at the supplied offset, compacting the string in place.
fun ref delete(
offset: ISize val,
len: USize val = 1)
: None val

Parameters¶


tcp_connection.pony

1
2
3
4
5
6
7
8
9
10
11


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


fun box rds_rdma_silent()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_rdma_use_once¶
[Source]


that: ASCIIDigits val

Returns¶

Bool val

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

Parameters¶

that: ASCIIDigits val

Returns¶


descr': String = "",
default': (I64 | None) = None)
=>
"""
Creates an Arg with an I64 typed value that can be used like
`<cmd> 42`
to yield an arg value like
`cmd.arg("count").i64() == I64(42)`.
"""
_name = name'
_descr = descr'
(_typ, _default, _required) = _init(_I64Type, default')

new val u64(name': String,
descr': String = "",
default': (U64 | None) = None)
=>
"""
Creates an Arg with an U64 typed value that can be used like
`<cmd> 47`


### `likely` and `unlikely`

Recognised on a conditional expression (`if`, `while`, `until` and `|` (as a pattern matching case)). Gives optimisation hints to the compiler on the likelihood of a given conditional expression.

```pony
if \likely\ cond then
foo
end

while \unlikely\ cond then
bar
end

repeat
baz
until \likely\ cond end

match obj
| \likely\ expr => foo
| \unlikely\ let capt: T => bar


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


n = n + 1
end
end

_size = _size + n
else
try
while n < len do
if iter.has_next() then
push(iter.next()?)
else
break
end

n = n + 1
end
end
end


fun box sctp_data_middle_frag()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_data_sack_immediately¶
[Source]


fun box ip_rsvp_on()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_rsvp_vif_on¶
[Source]


u8_unsafe¶
fun box u8_unsafe()
: U8 val

Returns¶

U8 val

u16_unsafe¶
fun box u16_unsafe()
: U16 val

Returns¶

U16 val


"""
try _value as U64 else U64(0) end

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

fun string_seq(): ReadSeq[String] val =>
"""
Returns the arg value as a ReadSeq[String], defaulting to empty.
"""
try
_value as _StringSeq val
else
recover val Array[String]() end
end

fun deb_string(): String =>


fun box ipctl_intrdqmaxlen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipctl_intrqmaxlen¶
[Source]


file_info.pony

1
2
3
4
5
6
7
8
9
10
11


| 0 =>
// System call was successful
| let errno: U32 =>
// System call failed
end
```
"""
_OSSocket.setsockopt(_fd, level, option_name, option)

fun ref setsockopt_u32(level: I32, option_name: I32, option: U32): U32 =>
"""
Wrapper for UDP sockets to the `setsockopt(2)` system call where
the kernel expects an option value of a C `uint32_t` type / Pony
type `U32`.

This function returns `0` on success, else the value of `errno` on
failure.
"""
_OSSocket.setsockopt_u32(_fd, level, option_name, option)


y: U16 val

Returns¶

(U16 val , Bool val)

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

Parameters¶

y: U16 val

Returns¶


fun pow(y: A): A
fun powi(y: I32): A

fun sqrt(): A

fun sqrt_unsafe(): A
"""
Unsafe operation.
If this is negative, the result is undefined.
"""

fun cbrt(): A
fun exp(): A
fun exp2(): A

fun cos(): A
fun sin(): A
fun tan(): A

fun cosh(): A


object is GenObj[Array[T]]
let _gen: GenObj[Array[T]] = gen
fun generate(rnd: Randomness): GenerateResult[Array[T]] ? =>
(let arr, let source_shrink_iter) = _gen.generate_and_shrink(rnd)?
rnd.shuffle[T](arr)
let shrink_iter =
Iter[Array[T]](source_shrink_iter)
.map_stateful[Array[T]^]({
(shrink_arr: Array[T]): Array[T]^ =>
rnd.shuffle[T](shrink_arr)
consume shrink_arr
})
(consume arr, shrink_iter)
end
)

fun shuffled_iter[T](array: Array[T]): Generator[Iterator[this->T!]] =>
Generator[Iterator[this->T!]](
object is GenObj[Iterator[this->T!]]
fun generate(rnd: Randomness): GenerateResult[Iterator[this->T!]] =>


float.pony

1
2
3
4
5
6
7
8
9
10
11


U8 val

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

Returns¶

I8 val

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

Returns¶


ULong val

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

Returns¶

ULong val

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

Parameters¶


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

Parameters¶

y: ISize val

Returns¶

(ISize val , Bool val)

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


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


U8 val^

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

Returns¶

U8 val^

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

Returns¶


let l = List[String]
l.>push("hello").push("world")
var count = U32(0)
for_each(l, {ref(s:String) =>
env.out.print(s)
count = count + 1
})
// Displays '0' as the count
env.out.print("Count: " + count.string())

fun for_each(l: List[String], f: {ref(String)} ref) =>
try
f(l.shift()?)
for_each(l, f)
end
```

This example declares the type of the apply function that is generated by the lambda expression as being `ref`. The lambda type declaration for the `f` parameter in the `for_each` method also declares it as `ref`. The reference capability of the lambda type must also be `ref` so that the method can be called. The lambda object does not need to declare an explicit reference capability because `ref` is the default for a lambda that has captures.

The above example also notes a subtle reality of captured references. At first glance one might expect `count` to have been incremented by the application of `f`. However, reassigning a reference, `count = count + 1`, inside a lambda or object literal can never cause a reassignment in the outer scope. If `count` were an object with reference capabilities permitting mutation, the captured reference could be modified with for example `count.increment()`. The resulting mutation would be visible to any location holding a reference to the same object as `count`.


(size() > that.size()) and (that <= this)

fun ge(that: HashSet[A, H] box): Bool =>
"""
Returns true if every element in that is also in this.
"""
that <= this

fun next_index(prev: USize = -1): USize ? =>
"""
Given an index, return the next index that has a populated value. Raise an
error if there is no next populated index.
"""
_map.next_index(prev)?

fun index(i: USize): this->A ? =>
"""
Returns the value at a given index. Raise an error if the index is not
populated.
"""


HashFunction64[A: A]¶
[Source]
A pluggable hash function with 64-bit hashes.
interface val HashFunction64[A: A]

Constructors¶
create¶
[Source]
Data structures create instances internally. Use a primitive if possible.
new val create()
: HashFunction64[A] val^

Returns¶


fun observe() =>
"""
Prevent the compiler from optimising out writes to an object marked by
the apply function.
"""
compile_intrinsic


a: B

Returns¶

F64 val^

min_value¶
[Source]
Minimum negative value representable.
new val min_value()
: F64 val^

Returns¶

F64 val^

max_value¶


SetIs[A: A]¶
[Source]
type SetIs[A: A] is
HashSet[A, HashIs[A!] val] ref

Type Alias For¶

HashSet[A, HashIs[A!] val] ref


fun box udp_nocksum()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

udp_no_check6_tx¶
[Source]


If you want to exit a function early then use the `return` command. If the function has a return type then you need to provide a value to return. If the function does not have a return type then `return` should appear on its own, without a value.

__Can I overload functions by argument type?__ No, you cannot have multiple methods with the same name in the same type.


In the above example, within `pet` our current view of `animal` is via the type union `Animal`. To treat `animal` as a cat, we need to do a runtime check that the concrete type of the object instance is `Cat`. If it is, then we can pet it. This example is a little contrived, but hopefully elucidates how `as` can be used to take a type that is a union and get a specific concrete type from it.

Note that the type requested as the `as` argument must exist as a type of the object instance, unlike C casting where one type can be forced to become another type. Coercion from one concrete type to another is not possible using `as`, so one can not do `let value:F64 = F32(1.0) as F64`. `F32` and `F64` are both concrete types and each object can only have a single concrete type. Many concrete types do provide methods that allow you to convert them to another concrete type, for example, `F32(1.0).f64()` to convert an `F32` to an `F64` or `F32(1.0).string()` to convert to a string.

In addition to using `as` with a union of disjoint types, we can also express an intersected type of the object, meaning the object has a type that the alias we have for the object is not directly related to the type we want to express. For example:

```pony
trait Alive

trait Well

class Person is (Alive & Well)

class LifeSigns
fun is_all_good(alive: Alive)? =>
// if the instance 'alive' is also of type 'Well' (such as a Person instance). raises error if not possible
let well: Well = alive as Well
```


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

Returns¶

I32 val ?

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

Returns¶


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

Parameters¶

y: I32 val

Returns¶

I32 val

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

Parameters¶


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

Parameters¶

that: DebugOut val

Returns¶

Bool val


Unset flags that are set in that.
"""
_value = this._value and not that._value

fun add(flag: A): Flags[A, B] iso^ =>
"""
This with the flag set.
"""
let f = recover Flags[A, B] end
f._value = this._value or flag.value()
f

fun sub(flag: A): Flags[A, B] iso^ =>
"""
This with the flag unset.
"""
let f = recover Flags[A, B] end
f._value = this._value and not flag.value()
f


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

fun ref apply(prop: {(T1, T2, T3, T4, PropertyHelper) ?} val) ? =>
Property4UnitTest[T1, T2, T3, T4](
object iso is Property4[T1, T2, T3, T4]
fun name(): String => ""
fun gen1(): Generator[T1] => _gen1
fun gen2(): Generator[T2] => _gen2


[Source]
fun box eq(
that: (Less val | Equal val | Greater val))
: Bool val

Parameters¶

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

Returns¶

Bool val

ne¶
[Source]
fun box ne(
that: (Less val | Equal val | Greater val))
: Bool val


U128 val^

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

Returns¶

U128 val^

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

Returns¶


y: F32 val)
: Bool val

Parameters¶

y: F32 val

Returns¶

Bool val

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

Parameters¶

y: F32 val


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

Type Alias For¶

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


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


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


that: String box

Returns¶

String iso^

join¶
[Source]
Return a string that is a concatenation of the strings in data, using this
as a separator.
fun box join(
data: Iterator[Stringable box] ref)
: String iso^

Parameters¶

data: Iterator[Stringable box] ref

Returns¶


shift¶
[Source]
Removes a byte from the beginning of the string.
fun ref shift()
: U8 val ?

Returns¶

U8 val ?

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


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

Parameters¶

y: U128 val

Returns¶

U128 val

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

Parameters¶


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


(U32 val , Bool val)

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

Parameters¶

y: U32 val

Returns¶

(U32 val , Bool val)

remc¶
[Source]


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


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


that: NetAddress val

Returns¶

Bool val


fun box ip_fw_del()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_fw_get¶
[Source]


fun box tipc_subscr_timeout()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_sub_ports¶
[Source]


fun pairs(): ArrayPairs[A, this->Array[A]]^ =>
"""
Return an iterator over the (index, value) pairs in the array.
"""
ArrayPairs[A, this->Array[A]](this)

class ArrayKeys[A, B: Array[A] #read] is Iterator[USize]
let _array: B
var _i: USize

new create(array: B) =>
_array = array
_i = 0

fun has_next(): Bool =>
_i < _array.size()

fun ref next(): USize =>
if _i < _array.size() then
_i = _i + 1


fun box ipproto_ddp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_divert¶
[Source]


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

Parameters¶

y: I64 val

Returns¶

(I64 val , Bool val)

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

Parameters¶


new val min_normalised()
: FloatingPoint[A] val^

Returns¶

FloatingPoint[A] val^

epsilon¶
[Source]
new val epsilon()
: FloatingPoint[A] val^

Returns¶

FloatingPoint[A] val^

create¶
[Source]


or @ponyint_o_cloexec())
_relative(path', fd')
else
recover create(path')? end
end

fun mkdir(target: String): Bool =>
"""
Creates a directory relative to this one. Returns false if the path is
not within this directory hierarchy or if FileMkdir permission is missing.
"""
if
not path.caps(FileMkdir) or
not path.caps(FileLookup) or
(_fd == -1)
then
return false
end

try


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


value: box->this->A!

Returns¶

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

op_or[optional K: HashFunction[this->A!] val]¶
[Source]
Create a set with the elements of both this and that.
fun box op_or[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¶


: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

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


_write_final(data)
_write_final("\n")
end

be write(data: ByteSeq) =>
"""
Write to STDIN of the child process.
"""
if not _done_writing then
_write_final(data)
end

be printv(data: ByteSeqIter) =>
"""
Print an iterable collection of ByteSeqs.
"""
for bytes in data.values() do
_write_final(bytes)
_write_final("\n")
end


iterator.pony

1
2
3
4
5
6
7
8
9
10
11


Real[A] val^

max_value¶
[Source]
new val max_value()
: Real[A] val^

Returns¶

Real[A] val^

Public Functions¶
radix¶
[Source]
fun tag radix()
: U8 val

Returns¶


_Run.create(this._round + 1)

fun eq(other: box->_Round): Bool =>
match other
| let s: _Run => s._round == this._round
else
false
end

fun string(): String iso^ =>
("run(" + this._round.string() + ")").string()

type _Round is (_Shrink | _Run)
"""Represents a single execution of a property."""

interface val PropertyLogger
fun log(msg: String, verbose: Bool = false)

interface val PropertyResultNotify


(Less val | Equal val | Greater val)


.>append("Signaled(")
.>append(_signal.string())
.>append(")")
end

fun eq(other: ProcessExitStatus): Bool =>
match other
| let s: Signaled =>
s._signal == _signal
else
false
end

type ProcessExitStatus is (Exited | Signaled)
"""
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.
"""


+ (digestof actual).string() + ")"))
return false
end

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

fun assert_isnt[A](
not_expect: A,
actual: A,
msg: String = "",
loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the 2 given expressions resolve to different instances.


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

Returns¶

None val ?

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

Returns¶

None val ?

after¶


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


"""
_i = _map.next_index(_i)?
_count = _count + 1
_map.index(_i)?._1

class MapValues[K, V, H: HashFunction[K] val, M: HashMap[K, V, H] #read] is
Iterator[M->V]
"""
An iterator over the values in a map.
"""
let _map: M
var _i: USize = -1
var _count: USize = 0

new create(map: M) =>
"""
Creates an iterator for the given map.
"""
_map = map


Parameters¶

y: F32 val

Returns¶

F32 val

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

Returns¶

F32 val


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


ISize val

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

Returns¶

ISize val

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


acc: List[this->A!]): List[this->A!]
=>
"""
Private helper for `filter`, recursively working with `ListNode`s.
"""
try
let cur = ln()?
if f(cur) then acc.push(cur) end
end

try
_filter(ln.next() as this->ListNode[A], f, acc)
else
acc
end

fun fold[B](f: {(B!, this->A!): B^} box, acc: B): B =>
"""
Folds the elements of the `List` using the supplied function.


function on_error will be called if the iterator's has_next method
returns true but its next method throws an error.
Example¶
Iter[I64]([1; 2; 3].values())
.map[None]({(x) => env.out.print(x.string()) })
.run()

1
2
3

fun ref run(
on_error: {ref()}[A] ref = lambda)
: None val

Parameters¶

on_error: {ref()}[A] ref = lambda

Returns¶


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


end

fun _final() =>
"""
Close the file.
"""
if _fd != -1 then
if (_pending_writev_total > 0) and (_errno is FileOK) then
// attempt to write any buffered data
try
_write_to_disk()?
end
end
if _unsynced_data or _unsynced_metadata then
// attempt to sync any un-synced data
if (path.caps.value() and FileSync.value()) > 0 then
ifdef windows then
@FlushFileBuffers(@_get_osfhandle(_fd))
else
@fsync(_fd)


fun box tcpolen_eol()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpolen_fast_open_empty¶
[Source]


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


U128 val

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

Returns¶

ULong val

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

Returns¶


fun box i64_unsafe()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong_unsafe¶
[Source]


fun box f64_unsafe()
: F64 val

Returns¶

F64 val

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

Parameters¶

that: I32 val

Returns¶


data: U32 val

Returns¶

None val

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

Parameters¶

data: U32 val

Returns¶


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

Returns¶

I16 val

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

Returns¶

I32 val


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


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

Parameters¶

y: F32 val

Returns¶

F32 val

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

Parameters¶


Public Functions¶
for_all[T: T]¶
[Source]
Convenience method for running 1 to many properties as part of
one PonyTest UnitTest.
Example:
class MyTestWithSomeProperties is UnitTest
fun name(): String => "mytest/withMultipleProperties"

fun apply(h: TestHelper) =>
PonyCheck.for_all[U8](recover Generators.unit[U8](0) end, h)(
{(u, h) =>
h.assert_eq(u, 0)
consume u
})

fun box for_all[T: T](
gen: Generator[T] val,


ULong val

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

Returns¶

USize val

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

Returns¶


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


fun box i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]


U32 val

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

Parameters¶

y: U32 val

Returns¶

U32 val

divrem¶
[Source]


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


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


F32¶
[Source]
primitive val F32 is
FloatingPoint[F32 val] val

Implements¶

FloatingPoint[F32 val] val

Constructors¶
create¶
[Source]


| (let s1: ReadSeq[Stringable], let s2: ReadSeq[Stringable]) =>
"([" + " ".join(s1.values()) + "], [" + " ".join(s2.values()) + "])"
| (let s1: Stringable, let s2: Stringable, let s3: Stringable) =>
"(" + s1.string() + ", " + s2.string() + ", " + s3.string() + ")"
| ((let s1: Stringable, let s2: Stringable), let s3: Stringable) =>
"((" + s1.string() + ", " + s2.string() + "), " + s3.string() + ")"
| (let s1: Stringable, (let s2: Stringable, let s3: Stringable)) =>
"(" + s1.string() + ", (" + s2.string() + ", " + s3.string() + "))"
else
"<identity:" + digest.string() + ">"
end
(consume t, consume s)


// array.space() >= 10

Accessing elements can be done via the apply(i: USize): this->A ? method.
The provided index might be out of bounds so apply is partial and has to be
called within a try-catch block or inside another partial method:
let array: Array[String] = ["dog"; "cat"; "wombat"]
let is_second_element_wobat = try
// indexes start from 0, so 1 is the second element
array(1)? == "wombat"
else
false
end

Adding and removing elements to and from the end of the Array can be done via
push and pop methods. You could treat the array as a LIFO stack using
those methods:
while (array.size() > 0) do
let elem = array.pop()?
// do something with element
end


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


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

Parameters¶

y: U32 val

Returns¶

U32 val

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

Parameters¶


fun tag precision2(): U8 =>
"""
Mantissa precision in bits.
"""
24

fun tag precision10(): U8 =>
"""
Mantissa precision in decimal digits.
"""
6

fun tag min_exp2(): I16 =>
"""
Minimum exponent value such that (2^exponent) - 1 is representable at full
precision (ie a normalised number).
"""
-125

fun tag min_exp10(): I16 =>


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


Bool val


y: U32 val

Returns¶

I32 val

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

Parameters¶

y: U32 val

Returns¶


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


String val

type_name¶
[Source]
Name of nearest class, actor, primitive, struct, interface, or trait.
fun box type_name()
: String val

Returns¶

String val

method_name¶
[Source]
Name of containing method.
fun box method_name()
: String val


fun box i16()
: I16 val

Returns¶

I16 val

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

Returns¶

I32 val

i64¶
[Source]


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


_spec = spec'
_fullname = fullname'
_options = options'
_args = args'

fun string(): String iso^ =>
"""
Returns a representational string for this command.
"""
let s: String iso = fullname().clone()
for o in _options.values() do
s.append(" ")
s.append(o.deb_string())
end
for a in _args.values() do
s.append(" ")
s.append(a.deb_string())
end
s


fun box so_np_extensions()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_numrcvpkt¶
[Source]


h: TestHelper val)
: ForAll[T] ref

Parameters¶

gen: Generator[T] val
h: TestHelper val

Returns¶

ForAll[T] ref

for_all2[T1: T1, T2: T2]¶
[Source]
fun box for_all2[T1: T1, T2: T2](
gen1: Generator[T1] val,
gen2: Generator[T2] val,
h: TestHelper val)
: ForAll2[T1, T2] ref


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


Returns¶

U128 val

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

Parameters¶

y: U128 val

Returns¶


class Option
class OptionSpec
class SyntaxError


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

Returns¶

F64 val

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

Parameters¶


# What's this look like, then?

It basically looks like any other type definition, but with some small differences. Here's a simple one:

```pony
object
fun apply(): String => "hi"
end
```

Ok, that's pretty trivial. Let's extend it so that it explicitly provides an interface so that the compiler will make sure the anonymous type fulfills that interface. You can use the same notation to provide traits as well.

```pony
object is Hashable
fun apply(): String => "hi"
fun hash(): USize => this().hash()
end
```

What we can't do is specify constructors in an object literal, because the literal _is_ the constructor. So how do we assign to fields? Well, we just assign to them. For example:


y: U8 val

Returns¶

U8 val ?

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

Parameters¶

y: U8 val

Returns¶


lt¶
[Source]
Return true if this address is less than that address.
fun tag lt(
that: Pointer[A] tag)
: Bool val

Parameters¶

that: Pointer[A] tag

Returns¶

Bool val

ne¶
[Source]
fun tag ne(


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


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


# Structural equality

Structural equality checking in Pony is done via the infix operator `==`. It verifies that two items have the same value. If the identity of the items being compared is the same, then by definition they have the same value.

You can define how structural equality is checked on your object by implementing `fun eq(that: box->Foo): Bool`. Remember, since `==` is an infix operator, `eq` must be defined on the left operand, and the right operand must be of type `Foo`.

```pony
class Foo
let _a: String

new create(a: String) =>
_a = a

fun eq(that: box->Foo): Bool =>
this._a == that._a

actor Main
new create(e: Env) =>
let a = Foo("hi")
let b = Foo("bye")


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

Parameters¶

value: ULong val

Returns¶

ULong 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 |


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

Parameters¶

offset: USize val = 0

Returns¶

F64 val ?


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


fun box icmp_redir_hosttos()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_redir_nettos¶
[Source]


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

Returns¶

A

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

Returns¶

A


"""
Creates a UDP socket that can be used for sending and receiving UDP messages.

The following examples create:

* an echo server that listens for connections and returns whatever message it
receives
* a client that connects to the server, sends a message, and prints the
message it receives in response

The server is implemented like this:

```pony
use "net"

class MyUDPNotify is UDPNotify
fun ref received(
sock: UDPSocket ref,
data: Array[U8] iso,
from: NetAddress)


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

Returns¶

String iso^

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

Parameters¶


fun box tipc_node_recvq_depth()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_ok¶
[Source]


fun box dccp_sockopt_tx_ccid()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dso_conaccept¶
[Source]


Represents a location in a Pony source file, as reported by `__loc`.
"""
fun file(): String
"""
Name and path of source file.
"""

fun type_name(): String
"""
Name of nearest class, actor, primitive, struct, interface, or trait.
"""

fun method_name(): String
"""
Name of containing method.
"""

fun line(): USize
"""
Line number within file.


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


offset = offset + num_bytes
_available = _available - num_bytes

if offset < data.size() then
node()? = (data, offset)
else
_chunks.shift()?
end
r
else
// single array did not have all the bytes needed
u8()?.u32() or (u8()?.u32() << 8) or
(u8()?.u32() << 16) or (u8()?.u32() << 24)
end
else
error
end

fun ref i32_be(): I32 ? =>


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

Returns¶

F64 val

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

Returns¶

F64 val


U32 val

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

Returns¶

U64 val

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

Returns¶


(Less val | Equal val | Greater val)


SignalRaise¶
[Source]
Raise a signal.
primitive val SignalRaise

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

Returns¶


```pony
"1.5".f64()? == F64(1.5)
"1.19208e-07".f64()? == F64(1.19208e-07)
"Inf".f64()?.infinite() == true
```
"""
let index = offset_to_index(offset)
if index < _size then
let ptr = this.cstring()
var endp: Pointer[U8] box = Pointer[U8]
@pony_os_clear_errno()
let res = @strtod(ptr.offset(index), addressof endp)
let errno: I32 = @pony_os_errno()
if (errno != 0) or (endp != ptr.offset(_size)) then
error
else
res
end
else
error


until counter > 7 end
```

Just like `while` loops, the value given by a `repeat` loop is the value of the expression within the loop on the last iteration, and `break` and `continue` can be used.

__Since you always go round a repeat loop at least once, do you ever need to give it an else expression?__ Yes, you may need to. A `continue` in the last iteration of a `repeat` loop needs to get a value from somewhere, and an `else` expression is used for that.


132
133
134
135
136
137
138
139
140
141
142
143
144
145primitive _StringifyIntArg
fun apply(choice: U8, int: U128): String iso ^ =>
let num =
match choice % 14
| 0 => "U8(" + int.u8().string() + ")"
| 1 => "U16(" + int.u16().string() + ")"
| 2 => "U32(" + int.u32().string() + ")"


_UnsignedPartialArithmetic.add_partial[USize](this, y)?

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

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

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

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

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

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


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


`and` is the same as `&&` in C and `and` in python, and `or` is the same as `||` in C and `or` in python.

__Can I use integers and pointers for the condition like I can in C?__ No. In Pony `if` conditions must have type `Bool`, i.e. they are always true or false. If you want to test whether a number `a` is not 0, then you need to explicitly say `a != 0`. This restriction removes a whole category of potential bugs from Pony programs.

If you want some alternative code for when the condition fails just add an `else`:

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

Often you want to test more than one condition in one go, giving you more than two possible outcomes. You can nest `if` statements, but this quickly gets ugly:

```pony
if a == b then
env.out.print("they are the same")
else


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

fun val exists(f: {(val->A): Bool} box): Bool =>
"""
Returns true if at least one element satisfies the provided predicate,


Array[A] ref^

init¶
[Source]
Create an array of len elements, all initialised to the given value.
new ref init(
from: A^,
len: USize val)
: Array[A] ref^

Parameters¶

from: A^
len: USize val

Returns¶

Array[A] ref^


# Operators


fun box ipx_primary()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipx_receive_broadcast¶
[Source]


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


fun op_or(that: Flags[A, B] box): Flags[A, B] iso^ =>
"""
The union of this and that.
"""
let f = recover Flags[A, B] end
f._value = this._value or that._value
f

fun op_and(that: Flags[A, B] box): Flags[A, B] iso^ =>
"""
The intersection of this and that.
"""
let f = recover Flags[A, B] end
f._value = this._value and that._value
f

fun op_xor(that: Flags[A, B] box): Flags[A, B] iso^ =>
"""
The symmetric difference of this and that.
"""


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

Returns¶

(U32 val , U32 val)

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

Returns¶

(U32 val , U32 val)


command_parser.pony

1
2
3
4
5
6
7
8
9
10
11


end

if _closed then
return
end

// Hand back read data
let size = _packet_size
let data = _read_buf = recover Array[U8] .> undefined(size) end
let from = _read_from = recover NetAddress end
data.truncate(len.usize())
_notify.received(this, consume data, consume from)

_start_next_read()
end

fun ref _start_next_read() =>
"""
Start our next receive.
This is used only with IOCP on Windows.


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.
"""
let range_1 = u32(0x0, 0xD7FF)
let range_1_size: USize = 0xD7FF
// excluding surrogate pairs
// this might be duplicate work but increases efficiency
let range_2 = u32(0xE000, 0x10FFFF)
let range_2_size = U32(0x10FFFF - 0xE000).usize()

let code_point_gen =
frequency[U32]([
(range_1_size, range_1)
(range_2_size, range_2)
])
utf32_codepoint_string(code_point_gen, min, max)

fun unicode_bmp(


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

Parameters¶

y: F64 val

Returns¶

F64 val

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

Parameters¶


FormatExpLarge¶
[Source]
primitive val FormatExpLarge is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


# Constructors

Pony constructors are used to initialise newly created objects, as in many languages. However, unlike many languages, Pony constructors are named so you can have as many as you like, taking whatever parameters you like. By convention, the main constructor of each type (if there is such a thing for any given type) is called `create`.

```pony
class Foo
var _x: U32

new create() =>
_x = 0

new from_int(x: U32) =>
_x = x
```

The purpose of a constructor is to set up the internal state of the object being created. To ensure this is done constructors must initialise all the fields in the object being constructed.

__Can I exit a constructor early?__ Yes. Just then use the `return` command without a value. The object must already be in a legal state to do this.


return path.trim(0, offset.usize() + 2)
end

try
if
is_sep(path.at_offset(offset)?) and
is_sep(path.at_offset(offset + 1)?)
then
return _network_share(path, offset + 3)
end
end
end
""

fun _drive_letter(path: String, offset: ISize = 0): Bool =>
"""
Look for a drive letter followed by a ':', returning true if we find it.
"""
try
let c = path.at_offset(offset)?


fun box sol_netrom()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_rfcomm¶
[Source]


# Aggregation

Often it is desirable to run a collection of unit tests from multiple different source files. For example, if several packages within a bundle each have their own unit tests it may be useful to run all tests for the bundle together.

This can be achieved by writing an aggregate test list class, which calls the list function for each package. The following is an example that aggregates the tests from packages `foo` and `bar`.

```pony
use "pony_test"
use foo = "foo"
use bar = "bar"

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

new make() =>
None

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


Return an iterator on the values in the List in reverse order.
let my_list = List[String].from(["a"; "b"; "c"])
let rvalues = my_list.rvalues()  // value "c" is before value "a"

fun box rvalues()
: ListValues[A, this->ListNode[A] ref] ref^

Returns¶

ListValues[A, this->ListNode[A] ref] ref^


fun box ip_dummynet_flush()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_faith¶
[Source]


fun box ipv6_join_anycast()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_minhopcount¶
[Source]


arg1: T
h: PropertyHelper val

Returns¶

None val ?


"""
u128().i128()

fun ref ilong(): ILong =>
"""
A random integer in [ILong.min_value(), ILong.max_value()]
"""
ulong().ilong()

fun ref isize(): ISize =>
"""
A random integer in [ISize.min_value(), ISize.max_value()]
"""
usize().isize()

fun ref int_fp_mult[N: (Unsigned val & Real[N] val) = U64](n: N): N =>
"""
A random integer in [0, n)
"""
N.from[F64](real() * n.f64())


received¶
[Source]
Called when new data is received on the connection. Return true if you
want to continue receiving messages without yielding until you read
max_size on the TCPConnection. Return false to cause the TCPConnection
to yield now.
Includes the number of times during the current behavior, that received has
been called. This allows the notifier to end reads on a regular basis.
fun ref received(
conn: TCPConnection ref,
data: Array[U8 val] iso,
times: USize val)
: Bool val

Parameters¶

conn: TCPConnection ref
data: Array[U8 val] iso
times: USize val


fun box tcp_cookie_transactions()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_defer_accept¶
[Source]


Bool val

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

Parameters¶

that: FormatHexSmall val

Returns¶

Bool val


end
size = size + 1 // last \0
var environ = Array[U8](size)
for varr in vars.values() do
environ.append(varr)
environ.push(0)
end
environ.push(0)
environ

fun kill() =>
if h_process != 0 then
@ponyint_win_process_kill(h_process)
end

fun ref wait(): _WaitResult =>
match final_wait_result
| let wr: _WaitResult =>
wr
else


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


Property1UnitTest[T: T]¶
[Source]
Provides plumbing for integration of PonyCheck
Properties into PonyTest.
Wrap your properties into this class and use it in a
TestList:
use "pony_test"
use "pony_check"

class MyProperty is Property1[String]
fun name(): String => "my_property"

fun gen(): Generator[String] =>


fun box sctp_pcb_flags_explicit_eor()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_frag_interleave¶
[Source]


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


y: U128 val

Returns¶

U128 val ?

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

Parameters¶

y: U128 val

Returns¶


U64 val

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

Returns¶

U64 val

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


None val

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

Parameters¶

ctrl: Bool val
alt: Bool val
shift: Bool val

Returns¶


fun box ipv6_pathmtu()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_pmtudisc_do¶
[Source]


Bool val

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

Parameters¶

that: PrefixDefault val

Returns¶

Bool val


fun box so_passcred()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_peek_off¶
[Source]


end

// Fill in option values from env or from coded defaults.
for os in _spec.options().values() do
if not options.contains(os.name()) then
// Lookup and use env vars before code defaults
if envsmap.contains(os.name()) then
let vs =
try
envsmap(os.name())?
else  // TODO(cq) why is else needed? we just checked
""
end
let v: _Value =
match _ValueParser.parse(os._typ_p(), vs)
| let v: _Value => v
| let se: SyntaxError => return se
end
options.update(os.name(), Option(os, v))
else


fun box so_rds_transport()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_reuseport¶
[Source]


path: String val

Returns¶

String val

normcase¶
[Source]
Normalizes the case of path for the runtime platform.
fun box normcase(
path: String val)
: String val

Parameters¶

path: String val

Returns¶


Parameters¶

value: U8 val

Returns¶

None val

push_u16[optional B: (A & Real[B] val & U8 val)]¶
[Source]
Add a U16 to the end of the array. This is only allowed for an array of U8s.
fun ref push_u16[optional B: (A & Real[B] val & U8 val)](
value: U16 val)
: None val

Parameters¶

value: U16 val


try
_prop1.property(consume shrink, helper)?
else
fail(current_repr, round_num where err=true)
return
end
// dispatch to another behaviour
// to ensure _complete_shrink has been called already
_shrink_finished(failed_repr, current_repr, this._current_round)

be _shrink_finished(
failed_repr: String,
current_repr: String,
shrink_round: _Round)
=>
if not _params.async and _pass then
// directly complete the shrink run
complete_shrink(failed_repr, current_repr, shrink_round, true)
end


Complete the Property execution
while signalling failure to the `PropertyResultNotify`.
"""
if err then
_report_error(repr, rounds)
else
_report_failed(repr, rounds)
end
_notify.complete(false)

fun _report_error(sample_repr: String,
shrink_rounds: USize = 0,
loc: SourceLoc = __loc) =>
"""
Report an error that happened during property evaluation
and signal failure to the `PropertyResultNotify`.
"""
_notify.fail(
"Property errored for sample "
+ sample_repr


y: I16 val

Returns¶

I16 val

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

Parameters¶

y: I16 val

Returns¶


fun box sctp_asconf_supported()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_authentication¶
[Source]


let int1: U128 val¶
[Source]

let int2: U128 val¶
[Source]

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

Returns¶

String iso^


Returns¶

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

filter¶
[Source]
Apply predicate to the values generated by this Generator
and only yields values for which predicate returns true.
Example:
let even_i32s =
Generators.i32()
.filter(
{(t) => (t, ((t % 2) == 0)) })

fun box filter(
predicate: {(T): (T^, Bool)}[T] box)
: Generator[T] box


String iso^

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

Parameters¶

y: U32 val

Returns¶

U32 val

sub_unsafe¶
[Source]


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


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


fun box mcast_msfilter()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mcast_undefined¶
[Source]


let cap = copy_len + offset
var i = offset

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

fun ref concat(iter: Iterator[A^], offset: USize = 0, len: USize = -1) =>
"""
Add len iterated elements to the tail of the list, starting from the given
offset.

When len is -1, all elements of iterator are pushed.

Does not remove elements from iterator.


I128 val^

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

Returns¶

I128 val^

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

Returns¶


fun box rds_cmsg_rdma_status()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_cong_monitor_size¶
[Source]


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


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


Return the amount of key-value pairs in the Map.
fun val size()
: USize val

Returns¶

USize val

update¶
[Source]
Update the value associated with the provided key.
fun val update(
key: K,
value: val->V)
: HashMap[K, V, H] val

Parameters¶

key: K


y: F64 val

Returns¶

F64 val

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

Parameters¶

y: F64 val

Returns¶


String val

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

Parameters¶

path: String val

Returns¶

String val

canonical¶


// Write as much data as possible.
// Returns how many we sent or 0 if we are experiencing backpressure
let len =
@pony_os_writev(_event,
_pending_writev_windows.cpointer(_pending_sent),
num_to_send)?

if len == 0 then
_apply_backpressure()
else
_pending_sent = _pending_sent + len
end
end
else
for bytes in _notify.sentv(this, data).values() do
// don't sent 0 byte payloads; it's wasteful
if bytes.size() == 0 then
continue
end


y: U128 val

Returns¶

I128 val

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

Parameters¶

y: U128 val

Returns¶


m.upsert("test", 4, {(current, provided) => current + provided })
This changes the value associated with "test" to 6.
If we have not yet added the key "new-key" to the map and we call
m.upsert("new-key", 4, {(current, provided) => current + provided })
then "new-key" is added to the map with a value of 4.
Returns the value that we set the key to
fun ref upsert(
key: K,
value: V,
f: {(V, V): V^}[K, V, H] box)
: V!

Parameters¶

key: K
value: V
f: {(V, V): V^}[K, V, H] box

Returns¶


# How to write a reference capability

A reference capability comes at the end of a type. So, for example:

```pony
String iso // An isolated string
String trn // A transition string
String ref // A string reference
String val // A string value
String box // A string box
String tag // A string tag
```

__What does it mean when a type doesn't specify a reference capability?__ It means you are using the _default_ reference capability for that type, which is defined along with the type. Here’s an example from the standard library:

```pony
class val String
```

When we use a String we usually mean an immutable string value, so we make `val` the default reference capability for `String` (but not necessarily for `String` constructors, see below). For example, when we don't specify the capability in the following code, the compiler understands that we are using the default reference capability `val` specified in the type definition:


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

Parameters¶

y: ILong val

Returns¶

ILong val ?

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


Public Types¶

primitive ApplyReleaseBackpressureAuth
primitive Backpressure


U64 val

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

Returns¶

U64 val

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

Returns¶


USize val^

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

Returns¶

USize val^

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

Returns¶


fun read_u32[B: (A & Real[B] val & U8) = A](offset: USize): U32 ? =>
"""
Reads a U32 from offset. This is only allowed for an array of U8s.
"""
let u32_bytes = U32(0).bytewidth()
if (offset + u32_bytes) <= _size then
_ptr._offset(offset)._convert[U32]()._apply(0)
else
error
end

fun read_u64[B: (A & Real[B] val & U8) = A](offset: USize): U64 ? =>
"""
Reads a U64 from offset. This is only allowed for an array of U8s.
"""
let u64_bytes = U64(0).bytewidth()
if (offset + u64_bytes) <= _size then
_ptr._offset(offset)._convert[U64]()._apply(0)
else
error


fun cpointer(offset: USize = 0): Pointer[A] tag =>
"""
Return the underlying C-style pointer.
"""
_ptr._offset(offset)

fun size(): USize =>
"""
The number of elements in the array.
"""
_size

fun space(): USize =>
"""
The available space in the array.
"""
_alloc

fun ref reserve(len: USize) =>
"""


(this >> 32).u32() xor
this.u32()).hash()
else
((this >> 64).u64() xor this.u64()).hash()
end

fun hash64(): U64 =>
((this >> 64).u64() xor this.u64()).hash64()

fun string(): String iso^ =>
_ToString._u128(this, false)

fun mul(y: U128): U128 =>
ifdef native128 then
this * y
else
let x_hi = (this >> 64).u64()
let x_lo = this.u64()
let y_hi = (y >> 64).u64()
let y_lo = y.u64()


fun netlink_tx_ring():I32 => @pony_os_sockopt_option(I32(422))
fun netlink_unused():I32 => @pony_os_sockopt_option(I32(423))
fun netlink_usersock():I32 => @pony_os_sockopt_option(I32(424))
fun netlink_xfrm():I32 => @pony_os_sockopt_option(I32(425))
fun netrom_idle():I32 => @pony_os_sockopt_option(I32(426))
fun netrom_kill():I32 => @pony_os_sockopt_option(I32(427))
fun netrom_n2():I32 => @pony_os_sockopt_option(I32(428))
fun netrom_neigh():I32 => @pony_os_sockopt_option(I32(429))
fun netrom_node():I32 => @pony_os_sockopt_option(I32(430))
fun netrom_paclen():I32 => @pony_os_sockopt_option(I32(431))
fun netrom_t1():I32 => @pony_os_sockopt_option(I32(432))
fun netrom_t2():I32 => @pony_os_sockopt_option(I32(433))
fun netrom_t4():I32 => @pony_os_sockopt_option(I32(434))
fun nrdv_multicast_addrs_per_sock():I32 => @pony_os_sockopt_option(I32(435))
fun pvd_config():I32 => @pony_os_sockopt_option(I32(436))
fun rds_cancel_sent_to():I32 => @pony_os_sockopt_option(I32(437))
fun rds_cmsg_atomic_cswp():I32 => @pony_os_sockopt_option(I32(438))
fun rds_cmsg_atomic_fadd():I32 => @pony_os_sockopt_option(I32(439))
fun rds_cmsg_cong_update():I32 => @pony_os_sockopt_option(I32(440))
fun rds_cmsg_masked_atomic_cswp():I32 => @pony_os_sockopt_option(I32(441))


new val create() =>
_root = None
_tail = recover Array[A] end
_size = 0
_depth = -1

new val _create(
root': (_VecNode[A] | None),
tail': Array[A] val,
size': USize,
depth': USize)
=>
_root = root'
_tail = tail'
_size = size'
_depth = depth'

fun size(): USize =>
"""
Return the amount of values in the vector.


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.


signal_notify.pony

1
2
3
4
5
6
7
8
9
10
11


Bool val

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

Parameters¶

y: ISize val

Returns¶

Bool val

le¶


U8 val

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

Parameters¶

y: U8 val

Returns¶

(U8 val , U8 val)

rem_unsafe¶
[Source]


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


fun icmp_echoreply():I32 => @pony_os_sockopt_option(I32(42))
fun icmp_exc_fragtime():I32 => @pony_os_sockopt_option(I32(43))
fun icmp_exc_ttl():I32 => @pony_os_sockopt_option(I32(44))
fun icmp_filter():I32 => @pony_os_sockopt_option(I32(45))
fun icmp_frag_needed():I32 => @pony_os_sockopt_option(I32(46))
fun icmp_host_ano():I32 => @pony_os_sockopt_option(I32(47))
fun icmp_host_isolated():I32 => @pony_os_sockopt_option(I32(48))
fun icmp_host_unknown():I32 => @pony_os_sockopt_option(I32(49))
fun icmp_host_unreach():I32 => @pony_os_sockopt_option(I32(50))
fun icmp_host_unr_tos():I32 => @pony_os_sockopt_option(I32(51))
fun icmp_info_reply():I32 => @pony_os_sockopt_option(I32(52))
fun icmp_info_request():I32 => @pony_os_sockopt_option(I32(53))
fun icmp_net_ano():I32 => @pony_os_sockopt_option(I32(54))
fun icmp_net_unknown():I32 => @pony_os_sockopt_option(I32(55))
fun icmp_net_unreach():I32 => @pony_os_sockopt_option(I32(56))
fun icmp_net_unr_tos():I32 => @pony_os_sockopt_option(I32(57))
fun icmp_parameterprob():I32 => @pony_os_sockopt_option(I32(58))
fun icmp_pkt_filtered():I32 => @pony_os_sockopt_option(I32(59))
fun icmp_port_unreach():I32 => @pony_os_sockopt_option(I32(60))
fun icmp_prec_cutoff():I32 => @pony_os_sockopt_option(I32(61))


...
```

Focusing on the callback-related parts, the callback function is passed using `addressof this.method_callback` (resp. by directly passing the bare lambda) as the third argument to `sqlite3_exec`. The fourth argument is `this`, which will end up being the first argument when the callback function is called. The callback function is called in `sqlite3_exec` by the call to `xCallback`.


value: A

Returns¶

None val ?

delete¶
[Source]
Delete an element from the array. Elements after this are moved down by one
index, compacting the array.
An out of bounds index raises an error.
The deleted element is returned.
fun ref delete(
i: USize val)
: A^ ?

Parameters¶

i: USize val


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


fun box tipc_addr_id()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_addr_name¶
[Source]


Real[A: Real[A] val]¶
[Source]
trait val Real[A: Real[A] val] is
Stringable box,
_ArithmeticConvertible val,
Comparable[A] ref

Implements¶

Stringable box
_ArithmeticConvertible val
Comparable[A] ref


fun ref next()
: K ?

Returns¶

K ?


Public Functions¶
local_address¶
[Source]
Return the local IP address. If this TCPConnection is closed then the
address returned is invalid.
fun box local_address()
: NetAddress val

Returns¶

NetAddress val

remote_address¶
[Source]
Return the remote IP address. If this TCPConnection is closed then the
address returned is invalid.
fun box remote_address()


_ptr._update(i, from)
i = i + 1
end
else
_alloc = 0
_ptr = Pointer[A]
end

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


_helper = h

fun ref apply(prop: {(T1, T2, T3, PropertyHelper) ?} val) ? =>
Property3UnitTest[T1, T2, T3](
object iso is Property3[T1, T2, T3]
fun name(): String => ""
fun gen1(): Generator[T1] => _gen1
fun gen2(): Generator[T2] => _gen2
fun gen3(): Generator[T3] => _gen3
fun ref property3(arg1: T1, arg2: T2, arg3: T3, h: PropertyHelper) ? =>
prop(consume arg1, consume arg2, consume arg3, h)?
end
).apply(_helper)?

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


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


end
""

fun volume(path: String): String =>
"""
On Windows, this returns the drive letter or UNC base at the beginning of
the path, if there is one. Otherwise, this returns an empty string.
"""
ifdef windows then
var offset = ISize(0)

if path.compare_sub("""\\?\""", 4) is Equal then
offset = 4

if path.compare_sub("""UNC\""", 4, offset) is Equal then
return _network_share(path, offset + 4)
end
end

if _drive_letter(path, offset) then


fun box ipport_hilastauto()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipport_reserved¶
[Source]


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


ULong val

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

Parameters¶

y: ULong val

Returns¶

ULong val

op_not¶
[Source]


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


Below are two classic list reverse properties from the QuickCheck paper adapted to Pony arrays:

```pony
use "pony_check"
use "collections"

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

fun gen(): Generator[Array[USize]] =>
Generators.seq_of[USize, Array[USize]](Generators.usize())

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

class _ListReverseOneProperty is Property1[Array[USize]]
fun name(): String => "list/reverse/one"

fun gen(): Generator[Array[USize]] =>
Generators.seq_of[USize, Array[USize]](Generators.usize() where min=1,max=1)


fun box ttcp_client_snd_wnd()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

udp_encap¶
[Source]


fun box ipproto_tp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_trunk1¶
[Source]


String iso^

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

Parameters¶

y: I8 val

Returns¶

I8 val

sub_unsafe¶
[Source]


U32 val

set_tcp_nodelay¶
[Source]
Wrapper for the FFI call setsockopt(fd, SOL_SOCKET, TCP_NODELAY, ...)
fun ref set_tcp_nodelay(
state: Bool val)
: U32 val

Parameters¶

state: Bool val

Returns¶

U32 val


var privilege_count: U32 = 1
embed privileges_0: _LuidAndAttributes = _LuidAndAttributes

struct ref _LuidAndAttributes
var luid: U64 = 0
var attributes: U32 = 0


If 1 action fails, the property is considered failing.
"""
_runner.fail_action(name, _run, this)

fun complete(success: Bool) =>
"""
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`.
"""
_run_notify.apply(_run, success)

fun dispose_when_done(disposable: DisposableActor) =>
"""


@"llvm.ctlz.i128"(this, true)

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

fun bitwidth(): U128 => 128

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

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

fun hash(): USize =>
ifdef ilp32 then
((this >> 96).u32() xor
(this >> 64).u32() xor


fun box ip_max_sock_mute_filter()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_max_source_filter¶
[Source]


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

Returns¶

String val


_size = 1

class ListNodes[A, N: ListNode[A] #read] is Iterator[N]
"""
Iterate over the nodes in a `List`.
"""
var _next: (N | None)
let _reverse: Bool

new create(head: (N | None), reverse: Bool = false) =>
"""
Build the iterator over nodes.

`reverse` of `false` iterates forward, while
`reverse` of `true` iterates in reverse.
"""
_next = head
_reverse = reverse

fun has_next(): Bool =>


n: USize val

Returns¶

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

take_while¶
[Source]
Builds a list of elements satisfying the provided predicate until one does
not.
fun val take_while(
f: {(val->A): Bool}[A] box)
: (Cons[A] val | Nil[A] val)

Parameters¶

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

Returns¶


ctz_unsafe¶
[Source]
Count trailing zeroes.
Unsafe operation.
If this is 0, the result is undefined.
fun box ctz_unsafe()
: A

Returns¶

A

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

Returns¶


descr': String val = "",
short': (U8 val | None val) = reference,
default': (U64 val | None val) = reference)
: OptionSpec val^

Parameters¶

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

Returns¶

OptionSpec val^

f64¶
[Source]
Creates an Option with a F64 typed value that can be used like


"""
"\x1B[106m"

fun bright_grey_bg(): String =>
"""
Bright grey background.
"""
"\x1B[47m"

primitive EraseLeft
primitive EraseLine
primitive EraseRight

type _EraseDirection is (EraseLeft | EraseLine | EraseRight)


that: Flags[A, B] box

Returns¶

Bool val

gt¶
[Source]
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.
fun box gt(
that: Flags[A, B] box)
: Bool val

Parameters¶

that: Flags[A, B] box


y: A

Returns¶

A

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

Parameters¶

y: A

Returns¶


```pony
fun ref connect_failed(conn: TCPConnection ref) =>
None
```
"""

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

fun ref sent(conn: TCPConnection ref, data: ByteSeq): ByteSeq =>
"""
Called when data is sent on the connection. This gives the notifier an
opportunity to modify sent data before it is written. To swallow data,
return an empty string.


112
113
114
115
116
117
118
119
120
121struct RuntimeOptions
"""
Pony struct for the Pony runtime options C struct that can be used to
override the Pony runtime defaults via code compiled into the program.

The way this is done is by adding the following function to your `Main` actor:

```
fun @runtime_override_defaults(rto: RuntimeOptions) =>
```


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


Seq[A] ref

Constructors¶
create¶
[Source]
Always creates an empty list with 0 nodes, len is ignored.
Required method for List to satisfy the Seq interface.
let my_list = List[String]

new ref create(
len: USize val = 0)
: List[A] ref^

Parameters¶

len: USize val = 0

Returns¶


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


value': B = 0

Returns¶

Flags[A, B] iso^

Public Functions¶
value¶
[Source]
Returns the bit encoding of the set flags.
fun box value()
: B

Returns¶

B

apply¶


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


U32 val

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

Returns¶

U64 val

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

Returns¶


heap.pony

1
2
3
4
5
6
7
8
9
10
11


92
93
94
95
96
97type Benchmark is (MicroBenchmark | AsyncMicroBenchmark)

// interface iso _IBenchmark
//   fun name(): String
//   fun config(): BenchConfig
//   fun overhead(): _IBenchmark^

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


end

// Update the item contained in the ListNode
try
my_list_node.update("My updated Node item")?
env.out.print("My node has the updated item value: "
+ my_list_node.apply()?) // My updated Node item
end
// Pop the item from the ListNode
try
my_list_node.pop()?
env.out.print("Popped the item from the ListNode")
my_list_node.apply()? // This will error as the item is now None
else
env.out.print("The ListNode has no (None) item.")
end

class ref ListNode[A: A]

Constructors¶


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


fun box mrt_api_config()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mrt_api_support¶
[Source]


Builds a new `List` by applying a function to every element of the `List`.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.map[String]( {(s: String): String => "m: " + s } )  // other_list is ["m: a"; "m: b"; "m: c"]
```
"""
try
_map[B](head()?, f, List[B])
else
List[B]
end

fun _map[B](
ln: this->ListNode[A],
f: {(this->A!): B^} box,
acc: List[B])
: List[B]^
=>
"""


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

Returns¶

MicroBenchmark iso^

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

Returns¶

None val ?


fun divrem(y: U128): (U128, U128) =>
ifdef native128 then
(this / y, this % y)
else
if y == 0 then
return (0, 0)
end

var quot: U128 = 0
var qbit: U128 = 1
var num = this
var den = y

while den.i128() >= 0 do
den = den << 1
qbit = qbit << 1
end

while qbit != 0 do


fun box sctp_timeouts()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_vrf_id¶
[Source]


fun int_property[T: (Int & Integer[T] val)](x: T, h: PropertyHelper)? =>
h.assert_eq[T](T.from[U8](0), x / T.from[U8](0))
```
"""
fun gen(): Generator[IntPropertySample] =>
Generators.map2[U8, U128, IntPropertySample](
Generators.u8(),
Generators.u128(),
{(choice, int) => IntPropertySample(choice, int) })

fun ref property(sample: IntPropertySample, h: PropertyHelper) ? =>
let x = sample.int
match sample.choice % 14
| 0 => int_property[U8](x.u8(), h)?
| 1 => int_property[U16](x.u16(), h)?
| 2 => int_property[U32](x.u32(), h)?
| 3 => int_property[U64](x.u64(), h)?
| 4 => int_property[ULong](x.ulong(), h)?
| 5 => int_property[USize](x.usize(), h)?
| 6 => int_property[U128](x, h)?


fun box rds_rdma_dontwait()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_rdma_fence¶
[Source]


Parameters¶

offset: USize val = 0

Returns¶

I32 val ?

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

Parameters¶

offset: USize val = 0


else
current.find(":")?
end

let value = current.substring(delim + 1)
value.strip()

current.delete(delim, -1)
current.strip()

try
let comment = try
value.find(";")?
else
value.find("#")?
end

match value(comment.usize() - 1)?
| ' ' | '\t' =>
value.delete(comment, -1)


that: CapError val

Returns¶

Bool val

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

Parameters¶

that: CapError val

Returns¶


y: I8 val

Returns¶

I8 val

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

Parameters¶

y: I8 val

Returns¶


value: A!,
offset: USize val = 0,
nth: USize val = 0,
predicate: {(box->A!, box->A!): Bool}[A] val = lambda)
: USize val ?

Parameters¶

value: A!
offset: USize val = 0
nth: USize val = 0
predicate: {(box->A!, box->A!): Bool}[A] val = lambda

Returns¶

USize val ?

contains¶
[Source]


# Global variables

Some programming languages have __global variables__ that can be accessed from anywhere in the code. What a bad idea! Pony doesn't have global variables at all.


let other_list = my_list.drop(1)  // ["b"; "c"]
```
"""
let l = List[this->A!]

if size() > n then
try
var node = index(n)?

for i in Range(n, size()) do
l.push(node()?)
node = node.next() as this->ListNode[A]
end
end
end
l

fun take(n: USize): List[this->A!] =>
"""
Builds a `List` by keeping the first `n` elements.


list.pony

1
2
3
4
5
6
7
8
9
10
11


fun box i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]


if _do_nothing then
return
end

if not _any_found then
// No tests left after applying our filters
_env.out.print("No tests found")
return
end

if _list_only then
// No tests to run
return
end

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


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


B

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

Parameters¶

y: B

Returns¶

A

shr¶


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

result.truncate(r.usize())
result
else
recover Array[U8] end
end

fun ref read_string(len: USize): String iso^ =>
"""
Returns up to len bytes. The resulting string may have internal null
characters.
"""
if _fd != -1 then
let result = recover String(len) end


chop[optional B: (A & Any #send)]¶
[Source]
Chops the array in half at the split point requested and returns both
the left and right portions. The original array is trimmed in place and
returned as the left portion. If the split point is larger than the
array, the left portion is the original array and the right portion
is a new empty array.
The operation does not allocate a new array pointer nor copy elements.
The entry type must be sendable so that the two halves can be isolated.
Otherwise, two entries may have shared references to mutable data,
or even to each other, such as in the code below:
class Example
var other: (Example | None) = None

let arr: Array[Example] iso = recover
let obj1 = Example
let obj2 = Example
obj1.other = obj2


will prevent instructions from before this call leaking into the block and
instructions after this call being executed earlier.
"""
ifdef x86 then
@"internal.x86.cpuid"(I32(0))
@"llvm.x86.rdtsc"()
else
compile_error "perf_begin only supported on x86"
end

fun perf_end(): U64 =>
"""
Get a cycle count for ending a performance testing block. This will
will prevent instructions from after this call leaking into the block and
instructions before this call being executed later.
"""
ifdef x86 then
var aux: I32 = 0
var ts = @"internal.x86.rdtscp"(addressof aux)
@"internal.x86.cpuid"(I32(0))


Returns¶

U64 val

perf_end¶
[Source]
Get a cycle count for ending a performance testing block. This will
will prevent instructions from after this call leaking into the block and
instructions before this call being executed later.
fun box perf_end()
: U64 val

Returns¶

U64 val

eq¶
[Source]


Generators val^

Public Functions¶
unit[T: T]¶
[Source]
Generate a reference to the same value over and over again.
This reference will be of type box->T and not just T
as this generator will need to keep a reference to the given value.
fun box unit[T: T](
t: T,
do_shrink: Bool val = false)
: Generator[box->T] box

Parameters¶

t: T
do_shrink: Bool val = false

Returns¶


_FormatInt.u64(abs.u64(), neg, fmt, prefix, prec, width, align, fill)
end
else
_FormatInt.u128(x.u128(), false, fmt, prefix, prec, width, align, fill)
end

fun float[A: (Float & FloatingPoint[A])](
x: A,
fmt: FormatFloat = FormatDefault,
prefix: PrefixNumber = PrefixDefault,
prec: USize = 6,
width: USize = 0,
align: Align = AlignRight,
fill: U32 = ' ')
: String iso^
=>
_FormatFloat.f64(x.f64(), fmt, prefix, prec, width, align, fill)


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


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


Parameters¶

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

write¶
[Source]
Print some bytes without inserting a newline afterwards.
be write(
data: (String val | Array[U8 val] val))

Parameters¶

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

printv¶
[Source]
Print an iterable collection of ByteSeqs.
be printv(


[Source]
fun box fld_unsafe(
y: ILong val)
: ILong val

Parameters¶

y: ILong val

Returns¶

ILong val

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


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


(I64 val , I64 val)

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

Parameters¶

y: I64 val

Returns¶

I64 val

neg¶
[Source]


fun box ndrv_protocol_desc_vers()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_add_membership¶
[Source]


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

Parameters¶

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

Returns¶

None val


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


fun fail(msg: String)
"""
Called when a Property has failed (did not hold for a sample)
or when execution raised an error.

Does not necessarily denote completeness of the property execution,
see `complete(success: Bool)` for that purpose.
"""

fun complete(success: Bool)
"""
Called when the Property execution is complete
signalling whether it was successful or not.
"""

actor PropertyRunner[T]
"""
Actor executing a Property1 implementation
in a way that allows garbage collection between single
property executions, because it uses recursive behaviours


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


success: Bool val)
: None val

Parameters¶

success: Bool val

Returns¶

None val

dispose_when_done¶
[Source]
Dispose the actor after a property run / a shrink is done.
fun box dispose_when_done(
disposable: DisposableActor tag)
: None val

Parameters¶


y: F64 val)
: Bool val

Parameters¶

y: F64 val

Returns¶

Bool val

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

Parameters¶

y: F64 val


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


fun box neg()
: I64 val

Returns¶

I64 val

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

Parameters¶

y: I64 val

Returns¶


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

Parameters¶

value: I8 val

Returns¶

I8 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 |


fun box sctp_get_nonce_values()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_get_peer_addresses¶
[Source]


U8 val

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

Returns¶

U16 val

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

Returns¶


if n <= 32 then
32 + n.u32()
else
error
end
else
compile_error "no SIGRT"
end


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


# Equality in Pony

Pony features two forms of equality: by structure and by identity.


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


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


fun box u32()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128¶
[Source]


HashEq[A: (Hashable #read & Equatable[A] #read)]¶
[Source]
primitive val HashEq[A: (Hashable #read & Equatable[A] #read)] is
HashFunction[A] val

Implements¶

HashFunction[A] val

Constructors¶
create¶
[Source]


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)
: XorShift128Plus ref^

Parameters¶

x: U64 val = 5489

Returns¶

XorShift128Plus ref^

create¶


Do not send block messages to the cycle detector.
"""

var ponypin: Bool = false
"""
Pin scheduler threads to CPU cores. The ASIO thread can also be pinned if
`--ponypinasio` is set.
"""

var ponypinasio: Bool = false
"""
Pin the ASIO thread to a CPU the way scheduler threads are pinned to CPUs.
Requires `--ponypin` to be set to have any effect.
"""

var ponyprintstatsinterval: U32 = -1
"""
Print actor stats before an actor is destroyed and print scheduler stats
every X seconds. Defaults to -1 (never).
"""


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

Parameters¶

that: OSSockOpt val

Returns¶

Bool val

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

Parameters¶


continue
| '[' =>
try
current.delete(current.find("]", 1)?, -1)
current.delete(0)
section = consume current
if not f.add_section(section) then
return ok
end
else
ok = false

if not f.errors(lineno, IniIncompleteSection) then
return false
end
end
else
try
let delim = try
current.find("=")?


that: ASCIIPunctuation val

Returns¶

Bool val

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

Parameters¶

that: ASCIIPunctuation val

Returns¶


USize val ?

size¶
[Source]
The number of elements that have been added to the ring.
fun box size()
: USize val

Returns¶

USize val

space¶
[Source]
The available space in the ring.
fun box space()
: USize val


Iter[T^](sub_iter).skip(1)
min_iter
].values())
(consume t, shrunken_iter)

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

fun shrink(u: U8): ValueAndShrink[U8] =>


file_stream.pony

1
2
3
4
5
6
7
8
9
10
11


from: (AmbientAuth val | NetAuth val)

Returns¶

DNSAuth val^

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

Parameters¶

that: DNSAuth val

Returns¶


Nil[A: A]¶
[Source]
The empty list of As.
primitive val Nil[A: A] is
ReadSeq[val->A] box

Implements¶

ReadSeq[val->A] box

Constructors¶
create¶


Bool val