U128 val

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

Parameters¶

y: U128 val

Returns¶

U128 val

hash¶
[Source]


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


Report the test exclusion group, returning an empty string for none.
The default body returns an empty string.
"""
""

fun ref apply(h: TestHelper) ?
"""
Run the test.
Raising an error is interpreted as a test failure.
"""

fun ref timed_out(h: TestHelper) =>
"""
Tear down a possibly hanging test.
Called when the timeout specified by to long_test() expires.
There is no need for this function to call complete(false).
tear_down() will still be called after this completes.
The default is to do nothing.
"""
None


fun box le(
y: U128 val)
: Bool val

Parameters¶

y: U128 val

Returns¶

Bool val

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

Parameters¶


fun box tcpolen_window()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpopt_ccecho¶
[Source]


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


_notify.right(ctrl, alt, shift)
_esc_clear()

fun ref _delete() =>
"""
Delete key.
"""
(let ctrl, let alt, let shift) = _mod()
_notify.delete(ctrl, alt, shift)
_esc_clear()

fun ref _insert() =>
"""
Insert key.
"""
(let ctrl, let alt, let shift) = _mod()
_notify.insert(ctrl, alt, shift)
_esc_clear()

fun ref _home() =>


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


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


Create a new array with the elements permuted.
Permute to an arbitrary order that may include duplicates. An out of bounds
index raises an error.
The new array contains references to the same elements that the old array
contains, the elements themselves are not copied.
"""
let out = Array[this->A!]
for i in indices do
out.push(this(i)?)
end
out

fun reverse(): Array[this->A!]^ =>
"""
Create a new array with the elements in reverse order.
The new array contains references to the same elements that the old array
contains, the elements themselves are not copied.
"""
clone() .> reverse_in_place()


Operations on a file.
"""
let path: FilePath
"""
This is the filesystem path locating this file on the file system
and an object capability granting access to operate on this file.
"""

let writeable: Bool
"""
`true` if the underlying file descriptor has been opened as writeable.
"""

let _newline: String = "\n"
var _unsynced_data: Bool = false
var _unsynced_metadata: Bool = false
var _fd: I32
var _errno: FileErrNo = FileOK
embed _pending_writev: Array[(Pointer[U8] tag, USize)] = _pending_writev.create()
var _pending_writev_total: USize = 0


primitive Fact
"""
This is an assertion that is always enabled. If the test is false, it will
print any supplied error message to stderr and raise an error.
"""
fun apply(test: Bool, msg: String = "") ? =>
if not test then
if msg.size() > 0 then
@fprintf(@pony_os_stderr(), "%s\n".cstring(), msg.cstring())
end
error
end


set_notify¶
[Source]
Change the notifier.
be set_notify(
notify: UDPNotify iso)

Parameters¶

notify: UDPNotify iso

set_broadcast¶
[Source]
Enable or disable broadcasting from this socket.
be set_broadcast(
state: Bool val)

Parameters¶


"""
_next isnt None

fun prev(): (this->ListNode[A] | None) =>
"""
Return the previous node.
"""
_prev

fun next(): (this->ListNode[A] | None) =>
"""
Return the next node.
"""
_next

fun ref _set_list(list: List[A]): ListNode[A]^ =>
"""
Make this node the only node on the given list.
"""
remove()


fun box ipproto_visa()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_wbexpak¶
[Source]


permute¶
[Source]
Create a new array with the elements permuted.
Permute to an arbitrary order that may include duplicates. An out of bounds
index raises an error.
The new array contains references to the same elements that the old array
contains, the elements themselves are not copied.
fun box permute(
indices: Iterator[USize val] ref)
: Array[this->A!] ref^ ?

Parameters¶

indices: Iterator[USize val] ref

Returns¶

Array[this->A!] ref^ ?


fun ref shift(): A^ ?
"""
Removes an element from the beginning of the sequence.
"""

fun ref append(
seq: (ReadSeq[A] & ReadElement[A^]),
offset: USize = 0,
len: USize = -1)
"""
Add len elements to the end of the list, starting from the given
offset.
"""

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


192
193
194use "collections"

class box Command
"""
Command contains all of the information describing a command with its spec
and effective options and arguments, ready to use.
"""
let _spec: CommandSpec box
let _fullname: String
let _options: Map[String, Option] box
let _args: Map[String, Arg] box

new _create(
spec': CommandSpec box,
fullname': String,
options': Map[String, Option] box,
args': Map[String, Arg] box)
=>


# Using `this->` as a viewpoint

A function with a `box` receiver can be called with a `ref` receiver or a `val` receiver as well since those are both subtypes of `box`. Sometimes, we want to be able to talk about a type to take this into account. For example:

```pony
class Wombat
var _friend: Wombat

fun friend(): this->Wombat => _friend
```

Here, we have a `Wombat`, and every `Wombat` has a friend that's also a `Wombat` (lucky `Wombat`). In fact, it's a `Wombat ref`, since `ref` is the default reference capability for a `Wombat` (since we didn't specify one). We also have a function that returns that friend. It's got a `box` receiver (because `box` is the default receiver reference capability for a function if we don't specify it).

So the return type would normally be a `Wombat box`. Why's that? Because, as we saw earlier, when we read a `ref` field from a `box` origin, we get a `box`. In this case, the origin is the receiver, which is a `box`.

But wait! What if we want a function that can return a `Wombat ref` when the receiver is a `ref`, a `Wombat val` when the receiver is a `val`, and a `Wombat box` when the receiver is a `box`? We don't want to have to write the function three times.

We use `this->`! In this case, `this->Wombat`. It means "a `Wombat ref` as seen by the receiver".

We know at the _call site_ what the real reference capability of the receiver is. So when the function is called, the compiler knows everything it needs to know to get this right.


Parameters¶

value: A

Returns¶

None val

pop¶
[Source]
Remove an element from the end of the array.
The removed element is returned.
fun ref pop()
: A^ ?

Returns¶

A^ ?


error
end

fun ref i64_be(): I64 ? =>
"""
Get a big-endian I64.
"""
u64_be()?.i64()

fun ref i64_le(): I64 ? =>
"""
Get a little-endian I64.
"""
u64_le()?.i64()

fun ref u128_be(): U128 ? =>
"""
Get a big-endian U128.
"""
let num_bytes = U128(0).bytewidth()


mt.pony

1
2
3
4
5
6
7
8
9
10
11


that: String box

Returns¶

Bool val

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

Parameters¶

that: String box


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


# C ABI

The FFI support in Pony uses the C application binary interface (ABI) to interface with native code. The C ABI is a calling convention, one of many, that allow objects from different programming languages to be used together.


WARNING: The values returned by the original iterator are cached, so
the input iterator should be finite.
Example¶
Iter[I64]([1; 2; 3].values())
.cycle()

1 2 3 1 2 3 1 2 3 ...
fun ref cycle()
: Iter[A!] ref^

Returns¶

Iter[A!] ref^

dedup[optional H: HashFunction[A] val]¶
[Source]
Return an iterator that removes duplicates from consecutive identical
elements. Equality is determined by the HashFunction H.
Example¶


String iso^

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

Parameters¶

y: I32 val

Returns¶

I32 val

sub_unsafe¶
[Source]


# Usage

Given the rules for using Iterators mentioned above, basic usage
of an iterator looks like this:

```pony
while iterator.has_next() do
let elem = iterator.next()?
// do something with elem
end
```

The `For`-loop provides a more concise way of iteration:

```pony
for elem in iterator do
// do something with elem
end
```


[Source]
Returns the value at a given index. Raise an error if the index is not
populated.
fun box index(
i: USize val)
: this->A ?

Parameters¶

i: USize val

Returns¶

this->A ?

values¶
[Source]
Return an iterator over the values.
fun box values()


Returns¶

U32 val

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

Returns¶

U32 val

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


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


Once the child process is detected to be closed, the process exit status is
retrieved and ProcessNotify.dispose is
called.
The process exit status can be either an instance of
Exited containing the process exit code in case the
program exited on its own, or (only on posix systems like linux, osx or bsd) an
instance of Signaled containing the signal number that
terminated the process.
Public Types¶

primitive CapError
primitive ChdirError
primitive ExecveError
class Exited
primitive ForkError
primitive KillError
primitive PipeError
class ProcessError
type ProcessErrorType
type ProcessExitStatus


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

Returns¶

I32 val

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

Returns¶

I64 val


# Example program

To use PonyTest simply write a class for each test and a TestList type that
tells the PonyTest object about the tests. Typically the TestList will be Main
for the package.

The following is a complete program with 2 trivial tests.

```pony
use "pony_test"

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

new make() =>
None

fun tag tests(test: PonyTest) =>
test(_TestAdd)


StringBytes ref^

runes¶
[Source]
Return an iterator over the codepoints in the string.
fun box runes()
: StringRunes ref^

Returns¶

StringRunes ref^

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


fun acos(): F64 => @acos(this)
fun asin(): F64 => @asin(this)
fun atan(): F64 => @atan(this)
fun atan2(y: F64): F64 => @atan2(this, y)

fun acosh(): F64 => @acosh(this)
fun asinh(): F64 => @asinh(this)
fun atanh(): F64 => @atanh(this)

fun copysign(sign: F64): F64 => @"llvm.copysign.f64"(this, sign)

fun hash(): USize => bits().hash()
fun hash64(): U64 => bits().hash64()

fun i128(): I128 =>
if this > I128.max_value().f64() then
return I128.max_value()
elseif this < I128.min_value().f64() then
return I128.min_value()
end


data: I64 val)
: None val

Parameters¶

data: I64 val

Returns¶

None val

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

Parameters¶


argv: Array[String val] box
envs: (Array[String val] box | None val) = reference

Returns¶

(Command box | CommandHelp box | SyntaxError val)


U128 val

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

Returns¶

I128 val

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

Returns¶


Check whether the set contains the value.
"""
_map.contains(value)

fun val add(value: val->A): HashSet[A, H] =>
"""
Return a set with the value added.
"""
_create(_map(value) = value)

fun val sub(value: val->A): HashSet[A, H] =>
"""
Return a set with the value removed.
"""
try _create(_map.remove(value)?) else this end

fun val op_or(that: (HashSet[A, H] | Iterator[A])): HashSet[A, H] =>
"""
Return a set with the elements of both this and that.
"""


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


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

Parameters¶

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


fun box local_connwait()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

local_peercred¶
[Source]


fun box rds_rdma_use_once()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_trans_count¶
[Source]


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


fun ipproto_tp():I32 => @pony_os_sockopt_level(I32(4111))
fun ipproto_tpxx():I32 => @pony_os_sockopt_level(I32(4112))
fun ipproto_trunk1():I32 => @pony_os_sockopt_level(I32(4113))
fun ipproto_trunk2():I32 => @pony_os_sockopt_level(I32(4114))
fun ipproto_ttp():I32 => @pony_os_sockopt_level(I32(4115))
fun ipproto_udp():I32 => @pony_os_sockopt_level(I32(4116))
fun ipproto_udplite():I32 => @pony_os_sockopt_level(I32(4117))
fun ipproto_vines():I32 => @pony_os_sockopt_level(I32(4118))
fun ipproto_visa():I32 => @pony_os_sockopt_level(I32(4119))
fun ipproto_vmtp():I32 => @pony_os_sockopt_level(I32(4120))
fun ipproto_wbexpak():I32 => @pony_os_sockopt_level(I32(4121))
fun ipproto_wbmon():I32 => @pony_os_sockopt_level(I32(4122))
fun ipproto_wsn():I32 => @pony_os_sockopt_level(I32(4123))
fun ipproto_xnet():I32 => @pony_os_sockopt_level(I32(4124))
fun ipproto_xtp():I32 => @pony_os_sockopt_level(I32(4125))
fun sol_atalk():I32 => @pony_os_sockopt_level(I32(4126))
fun sol_ax25():I32 => @pony_os_sockopt_level(I32(4127))
fun sol_hci_raw():I32 => @pony_os_sockopt_level(I32(4128))
fun sol_ipx():I32 => @pony_os_sockopt_level(I32(4129))
fun sol_l2cap():I32 => @pony_os_sockopt_level(I32(4130))


let _out: OutStream
let _destination: NetAddress

new create(
out: OutStream,
destination: NetAddress)
=>
_out = out
_destination = destination

fun ref listening(sock: UDPSocket ref) =>
sock.write("hello world", _destination)

fun ref received(
sock: UDPSocket ref,
data: Array[U8] iso,
from: NetAddress)
=>
_out.print("GOT:" + String.from_array(consume data))
sock.dispose()


Parameters¶

that: OutputSerialisedAuth val

Returns¶

Bool val

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

Parameters¶

that: OutputSerialisedAuth val

Returns¶


initial prompt on the ANSITerm to begin processing.
"""
_notify = consume notify
_out = out
_path = path
_history = Array[String](maxlen)
_maxlen = maxlen

_load_history()

fun ref apply(term: ANSITerm ref, input: U8) =>
"""
Receives input.
"""
match input
| 0x01 => home() // ctrl-a
| 0x02 => left() // ctrl-b
| 0x04 =>
// ctrl-d
if _edit.size() == 0 then


Returns¶

Cons[A] val

concat¶
[Source]
Builds a new list that is the concatenation of this list and the provided
list.
fun val concat(
l: (Cons[A] val | Nil[A] val))
: (Cons[A] val | Nil[A] val)

Parameters¶

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

Returns¶


1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551


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


I128 val

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

Parameters¶

y: I128 val

Returns¶

I128 val

mod¶
[Source]


else
""
end

fun from_slash(path: String): String =>
"""
Changes each / in the path to the OS specific separator.
"""
ifdef windows then
let s = path.clone()
let len = s.size()
var i = USize(0)

try
while i < len do
if s(i)? == '/' then
s(i)? = '\\'
end

i = i + 1


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


"""
(this /~ y, this %~ y)

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

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


fun help_string(): String =>
"""
Renders the help message as a String.
"""
let w: Writer = Writer
_write_help(w)
let str = recover trn String(w.size()) end
for bytes in w.done().values() do str.append(bytes) end
str

fun print_help(os: OutStream) =>
"""
Prints the help message to an OutStream.
"""
let w: Writer = Writer
_write_help(w)
os.writev(w.done())

fun _write_help(w: Writer) =>
_write_usage(w)


fun box bitwidth()
: U16 val

Returns¶

U16 val

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

Returns¶

USize val

min¶
[Source]


that: FileSeek val

Returns¶

Bool val

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

Parameters¶

that: FileSeek val

Returns¶


Parameters¶

y: ILong val

Returns¶

ILong val

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

Parameters¶

y: ILong val

Returns¶


fun box sol_rfcomm()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_sco¶
[Source]


fun box ip_fw3()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_fw_del¶
[Source]


are not in this.
"""
for value in that do
try
extract(value)?
else
set(consume value)
end
end

fun ref remove(that: Iterator[box->A!]) =>
"""
Remove everything that is in that.
"""
for value in that do
unset(value)
end

fun add[K: HashFunction[this->A!] val = H](
value: this->A!)


primitive Debug
"""
This is a debug only print utility.
"""
fun apply(
msg: (Stringable | ReadSeq[Stringable]),
sep: String = ", ",
stream: DebugStream = DebugOut)
=>
"""
If platform is debug configured, print either a single stringable or a
sequence of stringables. The default separator is ", ", and the default
output stream is stdout.
"""
ifdef debug then
match msg
| let m: Stringable =>
_print(m.string(), stream)
| let m: ReadSeq[Stringable] =>
_print(sep.join(m.values()), stream)


fun box u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶
[Source]


fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8_unsafe¶
[Source]


### Example

```pony
Iter[USize](Range(0, 4))
.interleave(Range(4, 6))
```
`0 4 1 5 2 3`
"""
Iter[A!](
object is Iterator[A!]
var _use_original: Bool = true

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

fun ref next(): A! ? =>
// Oscillate between iterators
if _use_original then
_use_original = not _use_original


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


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


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


yield_after_writing: USize val = 16384

Returns¶

TCPConnection tag^

Public Behaviours¶
write¶
[Source]
Write a single sequence of bytes. Data will be silently discarded if the
connection has not yet been established though.
be write(
data: (String val | Array[U8 val] val))

Parameters¶

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


fun box sctp_flight_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_fragment_interleave¶
[Source]


_head = None
_tail = None
_size = 0

fun head(): this->ListNode[A] ? =>
"""
Show the head of the list, raising an error if the head is empty.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
try my_list.head()? end // Returns a ListNode[String] containing "a"
```
"""
_head as this->ListNode[A]

fun tail(): this->ListNode[A] ? =>
"""
Show the tail of the list, raising an error if the tail is empty.

```pony


Modifying the Array can be done via `update`, `insert` and `delete` methods
which alter the Array at an arbitrary index, moving elements left (when
deleting) or right (when inserting) as necessary.

Iterating over the elements of an Array can be done using the `values` method:
```pony
for element in array.values() do
// do something with element
end
```


# Partial constructors and behaviours

Class constructors may also be marked as partial. If a class constructor raises an error then the construction is considered to have failed and the object under construction is discarded without ever being returned to the caller.

When an actor constructor is called the actor is created and a reference to it is returned immediately. However, the constructor code is executed asynchronously at some later time. If an actor constructor were to raise an error it would already be too late to report this to the caller. For this reason, constructors for actors may not be partial.

Behaviours are also executed asynchronously and so cannot be partial for the same reason.


s' = s' - v
else
s' = s' + v
end
end
s'

fun val without(that: (HashSet[A, H] | Iterator[A])): HashSet[A, H] =>
"""
Return a set with the elements of this that are not in that.
"""
let iter =
match that
| let s: HashSet[A, H] => s.values()
| let i: Iterator[A] => i
end
var s' = this
for v in iter do
if contains(v) then
s' = s' - v


fun tcpi_opt_syn_data():I32 => @pony_os_sockopt_option(I32(942))
fun tcpi_opt_timestamps():I32 => @pony_os_sockopt_option(I32(943))
fun tcpi_opt_toe():I32 => @pony_os_sockopt_option(I32(944))
fun tcpi_opt_wscale():I32 => @pony_os_sockopt_option(I32(945))
fun tcpolen_cc():I32 => @pony_os_sockopt_option(I32(946))
fun tcpolen_cc_appa():I32 => @pony_os_sockopt_option(I32(947))
fun tcpolen_eol():I32 => @pony_os_sockopt_option(I32(948))
fun tcpolen_fastopen_req():I32 => @pony_os_sockopt_option(I32(949))
fun tcpolen_fast_open_empty():I32 => @pony_os_sockopt_option(I32(950))
fun tcpolen_fast_open_max():I32 => @pony_os_sockopt_option(I32(951))
fun tcpolen_fast_open_min():I32 => @pony_os_sockopt_option(I32(952))
fun tcpolen_maxseg():I32 => @pony_os_sockopt_option(I32(953))
fun tcpolen_nop():I32 => @pony_os_sockopt_option(I32(954))
fun tcpolen_pad():I32 => @pony_os_sockopt_option(I32(955))
fun tcpolen_sack():I32 => @pony_os_sockopt_option(I32(956))
fun tcpolen_sackhdr():I32 => @pony_os_sockopt_option(I32(957))
fun tcpolen_sack_permitted():I32 => @pony_os_sockopt_option(I32(958))
fun tcpolen_signature():I32 => @pony_os_sockopt_option(I32(959))
fun tcpolen_timestamp():I32 => @pony_os_sockopt_option(I32(960))
fun tcpolen_tstamp_appa():I32 => @pony_os_sockopt_option(I32(961))


U16 val

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

Returns¶

U32 val

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

Returns¶


fun box netrom_t1()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netrom_t4¶
[Source]


env.out.print(consume substr)
end

class val String is
Seq[U8 val] ref,
Comparable[String box] ref,
Stringable box

Implements¶

Seq[U8 val] ref
Comparable[String box] ref
Stringable box

Constructors¶
create¶
[Source]
An empty string. Enough space for len bytes is reserved.
new ref create(


"""
Do nothing

Required method for `List` to satisfy the `Seq` interface.
"""
None

fun size(): USize =>
"""
Returns the number of items in the list.

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

fun apply(i: USize = 0): this->A ? =>
"""


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


name constants (arguments #2 and #3) for the
`getsockopt(2)` and `setsockopt(2)` operating system calls.

The values of the option level and option name constants are
typically C preprocessor macros, e.g., `#define SOMETHING 42`.
These macro names are upper case and may contain multiple
consecutive underscore characters (though this is rare, for
example, `IP_NAT__XXX`).  The function names in this primitive
are derived by the C macro name and then:

* converted to lower case
* any double underscore (`__`) is converted to a
single underscore (`_`).

These constants are _not_ stable between Pony releases.
Values returned by this function may be held by long-lived variables
by the calling process: values cannot change while the process runs.
Programmers must not cache any of these values for purposes of
sharing them for use by any other Pony program (for example,
sharing via serialization & deserialization or via direct


U32 val^

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

Returns¶

U32 val^

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

Returns¶


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


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


_runner.pony

1
2
3
4
5
6
7
8
9
10
11


fun box ipproto_divert()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_dstopts¶
[Source]


eq¶
[Source]
fun box eq(
x: (String box | Array[U8 val] box),
y: (String box | Array[U8 val] box))
: Bool val

Parameters¶

x: (String box | Array[U8 val] box)
y: (String box | Array[U8 val] box)

Returns¶

Bool val

ne¶


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

Parameters¶

y: A

Returns¶

A

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


try
_flat_map[B](head()?, f, List[B])
else
List[B]
end

fun _flat_map[B](
ln: this->ListNode[A],
f: {(this->A!): List[B]} box,
acc: List[B]): List[B]^
=>
"""
Private helper for `flat_map`, recursively working with `ListNode`s.
"""
try acc.append_list(f(ln()?)) end

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


Bool val

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

Parameters¶

that: FormatHex val

Returns¶

Bool val


@"llvm.bitreverse.i64"(this.u64()).usize()
end

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

fun popcount(): USize =>
ifdef ilp32 then
@"llvm.ctpop.i32"(this.u32()).usize()
else
@"llvm.ctpop.i64"(this.u64()).usize()
end

fun clz(): USize =>
ifdef ilp32 then
@"llvm.ctlz.i32"(this.u32(), false).usize()


# Chaining

Method chaining allows you to chain calls on an object without requiring the method to return its receiver. The syntax to call a method and chain the receiver is `object.>method()`, which is roughly equivalent to `(object.method() ; object)`. Chaining a method discards its normal return value.

```pony
primitive Printer
fun print_two_strings(out: StdStream, s1: String, s2: String) =>
out.>print(s1).>print(s2)
// Equivalent to:
out.print(s1)
out.print(s2)
out
```

Note that the last `.>` in a chain can be a `.` if the return value of the last call matters.

```pony
interface Factory
fun add_option(o: Option)
fun make_object(): Object


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

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

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

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

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

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

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


None¶
[Source]
primitive val None is
Stringable box

Implements¶

Stringable box

Constructors¶
create¶
[Source]


none.pony

1
2
3primitive None is Stringable
fun string(): String iso^ =>
"None".string()


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


Compare¶
[Source]
type Compare is
(Less val | Equal val | Greater val)

Type Alias For¶

(Less val | Equal val | Greater val)


ILong val ?

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

Parameters¶

y: ILong val

Returns¶

ILong val ?

rem_partial¶


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

Parameters¶

y: U16 val

Returns¶

U16 val

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

Parameters¶


F64 val

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

Parameters¶

y: U128 val

Returns¶

(U128 val , Bool val)

subc¶
[Source]


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26interface TimerNotify
"""
Notifications for timer.
"""
fun ref apply(timer: Timer, count: U64): Bool =>
"""


"""
if _available >= 1 then
_byte()?
else
error
end

fun ref i8(): I8 ? =>
"""
Get an I8.
"""
u8()?.i8()

fun ref u16_be(): U16 ? =>
"""
Get a big-endian U16.
"""
let num_bytes = U16(0).bytewidth()
if _available >= num_bytes then
let node = _chunks.head()?


"""
A random integer in [0, 2^64)
"""
var y = _x
let x = _y
let r = x + y
_x = x
y = y xor (y << 23)
_y = y xor x xor (y >> 18) xor (x >> 5)
r


(default: [min_value, max_value]).

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

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

Behavior is undefined if `min` > `max`.
"""
if (min == U32.min_value()) and (max == U32.max_value()) then
_random.u32()
else


fun box f64()
: F64 val

Returns¶

F64 val

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

Returns¶

I8 val

i16_unsafe¶
[Source]


end

primitive Nil[A] is ReadSeq[val->A]
"""
The empty list of As.
"""

fun size(): USize =>
"""
Returns the size of the list.
"""
0

fun apply(i: USize): val->A ? =>
"""
Returns the i-th element of the sequence. For the empty list this call will
always error because any index will be out of bounds.
"""
error


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

Returns¶

String val

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

Parameters¶


# Reference Capability Guarantees

Since types are guarantees, it's useful to talk about what guarantees a reference capability makes.


None val

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

Parameters¶

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

Returns¶

None val


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


Returns¶

F64 val ?

peek_u8¶
[Source]
Peek at a U8 at the given offset. Raise an error if there isn't enough
data.
fun box peek_u8(
offset: USize val = 0)
: U8 val ?

Parameters¶

offset: USize val = 0

Returns¶

U8 val ?


// Check for leading minus
let minus = (index < _size) and (_ptr._apply(index) == '-')
if minus then
if A(-1) > A(0) then
// We're reading an unsigned type, negative not allowed, int not found
return (0, 0)
end

index = index + 1
end

(let base', let base_chars) = _read_int_base[A](base, index)
index = index + base_chars

// Process characters
while index < _size do
let char: A = A(0).from[U8](_ptr._apply(index))
if char == '_' then
index = index + 1
continue


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

Parameters¶

that: SignalRaise val

Returns¶

Bool val

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


# Combining type expressions

Type expressions can be combined into more complex types. Here's another example from the standard library:

```pony
var _array: Array[((K, V) | _MapEmpty | _MapDeleted)]
```

Here we have an array where each element is either a tuple of `(K, V)` or a `_MapEmpty` or a `_MapDeleted`.

Because every type expression has parentheses around it, they are actually easy to read once you get the hang of it. However, if you use a complex type expression often, it can be nice to provide a type alias for it.

```pony
type Number is (Signed | Unsigned | Float)

type Signed is (I8 | I16 | I32 | I64 | I128)

type Unsigned is (U8 | U16 | U32 | U64 | U128)

type Float is (F32 | F64)


new create(from: Random) =>
"""
Initialise with a random number generator.
"""
r = from

fun ref apply(count: U64, sides: U64): U64 =>
"""
Return the sum of `count` rolls of a die with the given number of `sides`.
The die is numbered from 1 to `sides`. For example, count = 2 and
sides = 6 will return a value between 2 and 12.
"""
var sum = count
var i: U64 = 0

while i < count do
sum = sum + r.int(sides)
i = i + 1
end
sum


stringable.pony

1
2
3
4
5
6
7
8interface box Stringable
"""
Things that can be turned into a String.
"""


seed1: U64 val = 42,
seed2: U64 val = 0)
: Randomness ref^

Parameters¶

seed1: U64 val = 42
seed2: U64 val = 0

Returns¶

Randomness ref^

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


match name'
| None => p2.name()
| let s: String => s
end
_prop2 = consume p2

fun name(): String => _name

fun ref apply(h: TestHelper) ? =>
let prop = ((_prop2 = None) as Property2[T1, T2] iso^)
let params = prop.params()
h.long_test(params.timeout)
let property_runner =
PropertyRunner[(T1, T2)](
consume prop,
params,
h, // PropertyResultNotify
h, // PropertyLogger
h.env
)


472
473
474
475
476
477
478
479primitive _MapEmpty
primitive _MapDeleted

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

type MapIs[K, V] is HashMap[K, V, HashIs[K]]
"""
This is a map that uses identity comparison on the key.
"""


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

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

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

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

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

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

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


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


Returns¶

None val


Returns¶

USize val

closed¶
[Source]
Called when the connection is closed.
fun ref closed(
conn: TCPConnection ref)
: None val

Parameters¶

conn: TCPConnection ref

Returns¶

None val


"""
compile_intrinsic
```

Here we have two constructors. One that creates a new null Pointer, and another creates a Pointer with space for many instances of the type the Pointer is pointing at. Don't worry if you don't follow everything you are seeing in the above example. The important part is, it should basically look like the class constructor example [we saw earlier](/types/classes.md#what-goes-in-a-class).


y: U32 val

Returns¶

(U32 val , Bool val)

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

Parameters¶

y: U32 val

Returns¶


udp_notify.pony

1
2
3
4
5
6
7
8
9
10
11


y: U64 val

Returns¶

U64 val

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

Parameters¶

y: U64 val

Returns¶


ChdirError¶
[Source]
primitive val ChdirError

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

Returns¶

ChdirError val^


Parameters¶

arg1: (T1 , T2 , T3 ,
T4)
h: PropertyHelper val

Returns¶

None val ?

property4¶
[Source]
A method verifying that a certain property holds for all given
arg1, arg2, arg3, and arg4
with the help of PropertyHelper h.
fun ref property4(
arg1: T1,
arg2: T2,
arg3: T3,


U128 val

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

Returns¶

ULong val

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

Returns¶


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28primitive _Pending
primitive _Reject

interface iso Fulfill[A: Any #share, B: Any #share]


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


fun box listen()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

recv¶
[Source]


fun _filter(l: List[A], f: {(val->A): Bool} box, acc: List[A]): List[A] =>
"""
Private helper for filter, recursively working on elements, keeping those
that match the predicate and discarding those that don't.
"""
match l
| let cons: Cons[A] =>
if (f(cons.head())) then
_filter(cons.tail(), f, acc.prepend(cons.head()))
else
_filter(cons.tail(), f, acc)
end
else
acc.reverse()
end

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


Returns¶

String val

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

Parameters¶

h: TestHelper val

Returns¶

None val ?


i4: Iterator[D] ref
i5: Iterator[E] ref

Returns¶

Iter[(A , B , C , D , E)] ref^


let symlink: Bool val¶
[Source]
true if filepath points to a symbolic link.

let broken: Bool val¶
[Source]
true if filepath points to a broken symlink.


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


else
_current.push_u64(data.bswap())
end
_size = _size + num_bytes

fun ref u64_be(data: U64) =>
"""
Write a U64 to the buffer in big-endian byte order.
"""
let num_bytes = U64(0).bytewidth()
ifdef bigendian then
_current.push_u64(data)
else
_current.push_u64(data.bswap())
end
_size = _size + num_bytes

fun ref i64_le(data: I64) =>
"""
Write an I64 to the buffer in little-endian byte order.


```pony
use "math"

actor Main
new create(env: Env) =>
try
let lcm = LeastCommonMultiple[U64](10, 20)?
env.out.print(lcm.string())
else
env.out.print("No LCM")
end
```
"""
fun apply[A: (Integer[A] val & Unsigned)](x: A, y: A): A ? =>
(x / GreatestCommonDivisor[A](x, y)?) *? y


// push value into tail
_create(_root, tail, size', _depth)
elseif _tail_offset() == _Bits.next_pow32(_depth) then
// create new root
// push tail into root
let depth' = _depth + 1
let root' =
match _root
| let r: _VecNode[A] =>
try r.grow_root().push(depth', _tail_offset(), tail)?
else r
end
| None => _VecNode[A](tail)
end
_create(root', recover Array[A] end, size', depth')
else
// push tail into root
let root' =
try (_root as _VecNode[A]).push(_depth, _tail_offset(), tail)?
else _root


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

Parameters¶

that: ANSI val

Returns¶

Bool val


value
else
error
end

fun ref append(seq: ReadSeq[U8], offset: USize = 0, len: USize = -1) =>
"""
Append the elements from a sequence, starting from the given offset.
"""
if offset >= seq.size() then
return
end

let copy_len = len.min(seq.size() - offset)
reserve(_size + copy_len)

match seq
| let s: (String box | Array[U8] box) =>
s._copy_to(_ptr, copy_len, offset, _size)
_size = _size + copy_len


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

Returns¶

I32 val

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

Returns¶

I64 val


if s.is_null_terminated() then
s._copy_to(_ptr._unsafe(), s._size + 1, 0, _size)
else
s._copy_to(_ptr._unsafe(), s._size, 0, _size)
end
_size = len
consume this

fun add(that: String box): String iso^ =>
"""
Return a string that is a concatenation of this and that.
"""
let len = _size + that._size
let s = recover String(len) end
(consume s)._append(this)._append(that)

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


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


disposable_actor.pony

1
2
3
4
5interface tag DisposableActor
"""
An interface used to asynchronously dispose of an actor.
"""
be dispose()


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


that: this->HashSet[A, H] ref)
: HashSet[this->A!, K] ref^

Parameters¶

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

Returns¶

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

clone[optional K: HashFunction[this->A!] val]¶
[Source]
Create a clone. The element type may be different due to aliasing and
viewpoint adaptation.
fun box clone[optional K: HashFunction[this->A!] val]()
: HashSet[this->A!, K] ref^

Returns¶


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

Returns¶

String val

params¶
[Source]
fun box params()
: PropertyParams val

Returns¶

PropertyParams val


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


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

Parameters¶

value: I64 val

Returns¶

I64 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 ipproto_eon()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_etherip¶
[Source]


fun box hash64()
: U64 val

Returns¶

U64 val

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

Returns¶

I8 val

i16¶
[Source]


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

actor Timers is AsioEventNotify
"""
A hierarchical set of timing wheels.
"""
var _current: U64 = 0
let _slop: USize
embed _map: MapIs[Timer tag, Timer] = MapIs[Timer tag, Timer]
embed _wheel: Array[_TimingWheel] = Array[_TimingWheel](_wheels())
embed _pending: List[Timer] = List[Timer]
var _event: AsioEventID = AsioEvent.none()


fun bswap(): ILong =>
ifdef ilp32 or llp64 then
@"llvm.bswap.i32"(this.u32()).ilong()
else
@"llvm.bswap.i64"(this.u64()).ilong()
end

fun popcount(): ULong =>
ifdef ilp32 or llp64 then
@"llvm.ctpop.i32"(this.u32()).ulong()
else
@"llvm.ctpop.i64"(this.u64()).ulong()
end

fun clz(): ULong =>
ifdef ilp32 or llp64 then
@"llvm.ctlz.i32"(this.u32(), false).ulong()
else
@"llvm.ctlz.i64"(this.u64(), false).ulong()


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


fun box sctp_mobility_fasthandoff()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_nagle_logging_enable¶
[Source]


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

Returns¶

A^ ?

unshift¶
[Source]
Adds an element to the beginning of the sequence.
fun ref unshift(
value: A)
: None val

Parameters¶


(ILong val , Bool val)

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

Parameters¶

y: ILong val

Returns¶

(ILong val , Bool val)

add_partial¶


fun box icmp_address()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_dest_unreach¶
[Source]


fun box tcpf_ca_recovery()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpi_opt_ecn_seen¶
[Source]


Parameters¶

i: USize val

Returns¶

U8 val ?

update¶
[Source]
Change the i-th byte. Raise an error if the index is out of bounds.
fun ref update(
i: USize val,
value: U8 val)
: U8 val ?

Parameters¶


y: A)
: A

Parameters¶

y: A

Returns¶

A

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

Returns¶

USize val


U8 val

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

Returns¶

U8 val

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


USize val

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

Returns¶

USize val

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

Returns¶


### Example
```pony
let xs = [as I64: 1; 2].values()
let ys = [as I64: 3; 4].values()

Iter[I64].chain([xs; ys].values())
```
`1 2 3 4`
"""
_iter =
object
var inner_iterator: (Iterator[A] | None) = None

fun ref has_next(): Bool =>
if inner_iterator isnt None then
try
let iter = inner_iterator as Iterator[A]
if iter.has_next() then
return true
end


[Source]
fun box dispose()
: U32 val

Returns¶

U32 val

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

Returns¶

U32 val

write¶


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


There is no need for this function to call complete(false).
tear_down() will still be called after this completes.
The default is to do nothing.
fun ref timed_out(
h: TestHelper val)
: None val

Parameters¶

h: TestHelper val

Returns¶

None val

set_up¶
[Source]
Set up the testing environment before a test method is called.
Default is to do nothing.


=>
conn.write(String.from_array(consume data))
true

fun ref connect_failed(conn: TCPConnection ref) =>
None

class MyTCPListenNotify is TCPListenNotify
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ =>
MyTCPConnectionNotify

fun ref not_listening(listen: TCPListener ref) =>
None

actor Main
new create(env: Env) =>
TCPListener(TCPListenAuth(env.root),
recover MyTCPListenNotify end, "", "8989")

actor tag TCPListener is


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


fun box ip_onesbcast()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_origdstaddr¶
[Source]


U32 val

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

Returns¶

U64 val

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

Returns¶


USize val

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

Returns¶

USize val

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

Returns¶


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


s.append("..")
end
s.push(c)
state = _PathOther
end

i = i + 1
end
end

match state
| _PathDot2 =>
if backtrack == -1 then
s.append("..")
else
s.delete(backtrack, -1)
end
end

try


"""
Listens for new network connections.

The following program creates an echo server that listens for
connections on port 8989 and echoes back any data it receives.

```pony
use "net"

class MyTCPConnectionNotify is TCPConnectionNotify
fun ref received(
conn: TCPConnection ref,
data: Array[U8] iso,
times: USize)
: Bool
=>
conn.write(String.from_array(consume data))
true

fun ref connect_failed(conn: TCPConnection ref) =>


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

Parameters¶

that: DebugErr val

Returns¶

Bool val

ne¶
[Source]


Iter[USize]([as USize: 1; 1; 2; 3; 3; 2; 2].values())
.dedup()

1 2 3 2
fun ref dedup[optional H: HashFunction[A] val]()
: Iter[A!] ref^

Returns¶

Iter[A!] ref^

enum[optional B: (Real[B] val & (I8 val | I16 val | I32 val | I64 val | I128 val | ILong val | ISize val | U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val | F32 val | F64 val))]¶
[Source]
An iterator which yields the current iteration count as well as the next
value from the iterator.
Example¶
Iter[I64]([1; 2; 3].values())
.enum()


A

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

Parameters¶

y: A

Returns¶

A

mod_unsafe¶
[Source]


fun _serialise_space(): USize =>
@serialise_space(_cstr)

fun _serialise(bytes: Pointer[U8] tag) =>
@serialise(bytes, _cstr)

fun ref _deserialise(bytes: Pointer[U8] tag) =>
_cstr = @deserialise(bytes)

fun print() =>
@printf(_cstr)

actor Main
new create(env: Env) =>
let csw = CStringWrapper(@get_string())
csw.print()
try
let serialise = SerialiseAuth(env.root)
let deserialise = DeserialiseAuth(env.root)


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

Parameters¶

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

Returns¶

Bool val

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


m: HashMap[K, V, H] val

Returns¶

MapPairs[K, V, H] ref^

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

Returns¶

Bool val

next¶
[Source]


Return true if the string is null-terminated and safe to pass to an FFI
function that doesn't accept a size argument, expecting a null-terminator.
This method checks that there is a null byte just after the final position
of populated bytes in the string, but does not check for other null bytes
which may be present earlier in the content of the string.
If you need a null-terminated copy of this string, use the clone method.
fun box is_null_terminated()
: Bool val

Returns¶

Bool val

utf32¶
[Source]
Return a UTF32 representation of the character at the given offset and the
number of bytes needed to encode that character. If the offset does not
point to the beginning of a valid UTF8 encoding, return 0xFFFD (the unicode
replacement character) and a length of one. Raise an error if the offset is


(I32 val , I32 val) ?

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

Parameters¶

y: I32 val

Returns¶

I32 val ?

mod_partial¶
[Source]


List[this->A!] ref^

fold[B: B]¶
[Source]
Folds the elements of the List using the supplied function.
On the first iteration, the B argument in f is the value acc,
on the second iteration B is the result of the first iteration,
on the third iteration B is the result of the second iteration, and so on.
let my_list = List[String].from(["a"; "b"; "c"])
let folded = my_list.fold[String]( {(str: String, s: String): String => str + s }, "z")  // "zabc"

fun box fold[B: B](
f: {(B!, this->A!): B^}[A, B] box,
acc: B)
: B

Parameters¶

f: {(B!, this->A!): B^}[A, B] box


fun ref i32(
min: I32 val = call,
max: I32 val = call)
: I32 val

Parameters¶

min: I32 val = call
max: I32 val = call

Returns¶

I32 val

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


Builtin package¶
The builtin package is home to the following standard library members:

Types the compiler needs to know exist, such as None.
Types with "magic" internal workings that must be supplied directly by the
compiler, such as U32.
Any types needed by others in builtin.

The public types that are defined in this package will always be in scope for
every Pony source file. For details on specific packages, see their individual
entity entries.
Public Types¶


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

Returns¶

Bool val

rename¶
[Source]
Rename a file or directory.
fun box rename(
new_path: FilePath val)
: Bool val

Parameters¶


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

fun ref connected(conn: TCPConnection ref) =>
_out.print("connected")
conn.close()

fun ref connect_failed(conn: TCPConnection ref) =>
_out.print("connect_failed")

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

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

The `Main` actor authorizes the `Connect` actor by passing a `TCPConnectAuth` token created from the ambient authority token in `env.root`. The ambient authority token is unforgeable since the `AmbientAuth` constructor is private and the only existing instance is provided by the runtime itself.


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


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


fun box so_setfib()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_sndbufforce¶
[Source]


from: (AmbientAuth val | NetAuth val | TCPAuth val)

Returns¶

TCPListenAuth val^

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

Parameters¶

that: TCPListenAuth val

Returns¶


BinaryHeap[A: Comparable[A] #read, P: (_BinaryHeapPriority[A] val & (MinHeapPriority[A] val | MaxHeapPriority[A] val))]¶
[Source]
A priority queue implemented as a binary heap. The BinaryHeapPriority type
parameter determines whether this is max-heap or a min-heap.
class ref BinaryHeap[A: Comparable[A] #read, P: (_BinaryHeapPriority[A] val & (MinHeapPriority[A] val | MaxHeapPriority[A] val))]

Constructors¶
create¶
[Source]
Create an empty heap with space for len elements.
new ref create(
len: USize val)
: BinaryHeap[A, P] ref^


## Partial and Checked Arithmetic

If overflow or division by zero are cases that need to be avoided and performance is no critical priority, partial or checked arithmetic offer great safety during runtime. Partial arithmetic operators error on overflow/underflow and division by zero. Checked arithmetic methods return a tuple of the result of the operation and a `Boolean` indicating overflow or other exceptional behaviour.

```pony
// partial arithmetic
let result =
try
USize.max_value() +? env.args.size()
else
env.out.print("overflow detected")
end

// checked arithmetic
let result =
match USize.max_value().addc(env.args.size())
| (let result: USize, false) =>
// use result
...
| (_, true) =>


Returns¶

(List[this->A!] ref^ , List[this->A!] ref^)

drop¶
[Source]
Builds a List by dropping the first n elements.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.drop(1)  // ["b"; "c"]

fun box drop(
n: USize val)
: List[this->A!] ref^

Parameters¶

n: USize val


ASCIIRange¶
[Source]
type ASCIIRange is
(ASCIINUL val | ASCIIDigits val | ASCIIWhiteSpace val | ASCIIPunctuation val | ASCIILettersLower val | ASCIILettersUpper val | ASCIILetters val | ASCIIPrintable val | ASCIINonPrintable val | ASCIIAll val | ASCIIAllWithNUL val)

Type Alias For¶

(ASCIINUL val | ASCIIDigits val | ASCIIWhiteSpace val | ASCIIPunctuation val | ASCIILettersLower val | ASCIILettersUpper val | ASCIILetters val | ASCIIPrintable val | ASCIINonPrintable val | ASCIIAll val | ASCIIAllWithNUL val)


promise.next[Array[String] val](recover Computation~string_to_strings() end)
.next[Array[USize] val](recover Computation~strings_to_sizes() end)
.next[USize](recover Computation~sizes_to_avg() end)
.next[None](recover Computation~output(env) end)
promise(" ".join(env.args.slice(1).values()))

Public Types¶

interface Fulfill
class FulfillIdentity
actor Promise
primitive Promises
interface Reject
class RejectAlways


The Generator for the first argument to your property2.
fun box gen1()
: Generator[T1] box

Returns¶

Generator[T1] box

gen2¶
[Source]
The Generator for the second argument to your property2.
fun box gen2()
: Generator[T2] box

Returns¶

Generator[T2] box


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


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

Parameters¶

a: B

Returns¶

Real[A] val^

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

Returns¶


Returns¶

String val

i64¶
[Source]
Returns the arg value as an I64, defaulting to 0.
fun box i64()
: I64 val

Returns¶

I64 val

u64¶
[Source]
Returns the arg value as an U64, defaulting to 0.
fun box u64()


```pony
primitive Red    fun apply(): U32 => 0xFF0000FF
primitive Green  fun apply(): U32 => 0x00FF00FF
primitive Blue   fun apply(): U32 => 0x0000FFFF

type Colour is (Red | Blue | Green)
```

or namespace them like this

```pony
primitive Colours
fun red(): U32 => 0xFF0000FF
fun green(): U32 => 0x00FF00FF
```

You might also want to iterate over the enumeration items like this to print their value for debugging purposes

```pony


fun box creat()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

fsync¶
[Source]


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

Parameters¶

y: A

Returns¶

A

max¶
[Source]
fun box max(


None val

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

Parameters¶

h: TestHelper val

Returns¶

None val ?

tear_down¶
fun ref tear_down(


fun head(): val->A ? =>
"""
Returns an error, since Nil has no head.
"""
error

fun tail(): List[A] ? =>
"""
Returns an error, since Nil has no tail.
"""
error

fun reverse(): Nil[A] =>
"""
The reverse of the empty list is the empty list.
"""
this

fun prepend(a: val->A!): Cons[A] =>


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

ifdef linux or bsd then
var offset: ISize = 0

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

@mkdirat(_fd, element.cstring(), U32(0x1FF))
until offset < 0 end

FileInfo(path')?.directory
else
path'.mkdir()


"""
_chunks.clear()
_available = 0

fun ref append(data: ByteSeq) =>
"""
Add a chunk of data.
"""
let data_array =
match data
| let data': Array[U8] val => data'
| let data': String => data'.array()
end

_available = _available + data_array.size()
_chunks.push((data_array, 0))

fun ref skip(n: USize) ? =>
"""
Skip n bytes.


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


U16 val

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

Returns¶

U16 val

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


fun box icmp_net_unreach()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_parameterprob¶
[Source]


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


U32 val

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

Returns¶

U64 val

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

Returns¶


Vec[A] val

pop¶
[Source]
Return a vector with the value at the end removed.
fun val pop()
: Vec[A] val ?

Returns¶

Vec[A] val ?

concat¶
[Source]
Return a vector with the values of the given iterator added to the end.
fun val concat(
iter: Iterator[val->A] ref)
: Vec[A] val


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 divc(
y: I128 val)
: (I128 val , Bool val)

Parameters¶

y: I128 val

Returns¶

(I128 val , Bool val)

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

Parameters¶


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

Parameters¶

that: HashByteSeq val

Returns¶

Bool val


end

class val Signaled is (Stringable & Equatable[ProcessExitStatus])
"""
Process exit status: Process was terminated by a signal.
"""
let _signal: U32

new val create(sig: U32) =>
_signal = sig

fun signal(): U32 =>
"""
Retrieve the signal number that exited the process.
"""
_signal

fun string(): String iso^ =>
recover iso
String(12)


_pending_writev_posix
.> push((bytes.cpointer(), bytes.size()))
_pending_writev_total = _pending_writev_total + bytes.size()
end

_pending_writes()
end

_in_sent = false
end

be mute() =>
"""
Temporarily suspend reading off this TCPConnection until such time as
`unmute` is called.
"""
_muted = true

be unmute() =>
"""


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


fun box sol_sco()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_tipc¶
[Source]


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

Parameters¶

value: I32 val

Returns¶

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


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


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

Returns¶

U32 val

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

Parameters¶


# Type qualifiers

If you've used C/C++, you may be familiar with `const`, which is a _type qualifier_ that tells the compiler not to allow the programmer to _mutate_ something.

A reference capability is a form of _type qualifier_ and provides a lot more guarantees than `const` does!

In Pony, every use of a type has a reference capability. These capabilities apply to variables, rather than to the type as a whole. In other words, when you define a class `Wombat`, you don't pick a reference capability for all instances of the class. Instead, `Wombat` variables each have their own reference capability.

As an example, in some languages, you have to define a type that represents a mutable `String` and another type that represents an immutable `String`. For example, in Java, there is a `String` and a `StringBuilder`. In Pony, you can define a single class `String` and have some variables that are `String ref` (which are mutable) and other variables that are `String val` (which are immutable).


fun box rds_cmsg_cong_update()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

rds_cmsg_masked_atomic_fadd¶
[Source]


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


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

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

class ThrowItAway is TCPConnectionNotify
var _throttled: Bool = false

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


Bool val

next¶
[Source]
fun ref next()
: (USize val , B->A) ?

Returns¶

(USize val , B->A) ?


# Usage

```pony
use "collections/persistent"

actor Main
new create(env: Env) =>
try
let l1 = Lists[U32]([2; 4; 6; 8]) // List(2, 4, 6, 8)

let empty = Lists[U32].empty() // List()

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


fun getsockopt(): U64 => _id(0, 1 << 34)
fun listen(): U64 => _id(0, 1 << 35)
fun peeloff(): U64 => _id(0, 1 << 36)
fun recv(): U64 => read()
fun send(): U64 => write()
fun setsockopt(): U64 => _id(0, 1 << 37)
fun shutdown(): U64 => _id(0, 1 << 38)
fun bindat(): U64 => _id(0, 1 << 39) or lookup()
fun connectat(): U64 => _id(0, 1 << 40) or lookup()

fun sock_client(): U64 =>
connect() or getpeername() or getsockname() or getsockopt() or peeloff() or
recv() or send() or setsockopt() or shutdown()

fun sock_server(): U64 =>
accept() or bind() or getpeername() or getsockname() or getsockopt() or
listen() or peeloff() or recv() or send() or setsockopt() or shutdown()

fun mac_get(): U64 => _id(1, 1 << 0)
fun mac_set(): U64 => _id(1, 1 << 1)


U32 val

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

Returns¶

U64 val

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

Returns¶


fun box tcpci_opt_ecn()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpci_opt_timestamps¶
[Source]


fun box fsync()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

lookup¶
[Source]


Parameters¶

line: USize val
err: (IniIncompleteSection val | IniNoDelimiter val)

Returns¶

Bool val


I32 val

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

Parameters¶

y: I32 val

Returns¶

I32 val

divrem¶
[Source]


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


y: I128 val

Returns¶

(I128 val , Bool val)

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

Parameters¶

y: I128 val

Returns¶


fun box tipc_addr_name()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tipc_cfg_srv¶
[Source]


fun box ipv6_priority_reserved2()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_priority_uncharacterized¶
[Source]


f(value)
end

_list.clear()

be reject() =>
"""
Reject the promise.
"""
if _value isnt _Pending then
return
end

_value = _Reject

for f in _list.values() do
f.reject()
end

_list.clear()


functions on a Pointer[A] are private to maintain memory safety.
"""
new create() =>
"""
A null pointer.
"""
compile_intrinsic

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

fun ref _realloc(len: USize, copy: USize): Pointer[A] =>
"""
Keep the contents, but reserve space for len instances of A.
"""
compile_intrinsic


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


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


end
end

ifdef windows then
// do a trim in place instead of many shifts for efficiency
_pending_writev_windows.trim_in_place(num_sent)
_pending_sent = _pending_sent - num_sent
else
// do a trim in place instead of many shifts for efficiency
_pending_writev_posix.trim_in_place(num_sent)
end

ifdef not windows then
_apply_backpressure()
end
else
// sent all data we requested in this batch
_pending_writev_total = _pending_writev_total - bytes_to_send
if _pending_writev_total == 0 then
ifdef windows then


path
end

fun ext(path: String): String =>
"""
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.
"""
try
let i = path.rfind(".")?

let j = try
path.rfind(sep())?
else
i
end

if i >= j then
return path.trim(i.usize() + 1)
end


fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8_unsafe¶
[Source]


| `>=~`    | `ge_unsafe()`  |
| `=~`     | `eq_unsafe()`  |
| `!=~`    | `ne_unsafe()`  |

---

Additionally `sqrt_unsafe()` is undefined for negative values.


that: String box,
n: USize,
offset: ISize = 0,
that_offset: ISize = 0,
ignore_case: Bool = false)
: Compare
=>
"""
Lexically compare at most `n` bytes of the substring of `this` starting at
`offset` with the substring of `that` starting at `that_offset`. The
comparison is case sensitive unless `ignore_case` is `true`.

If the substring of `this` is a proper prefix of the substring of `that`,
then `this` is `Less` than `that`. Likewise, if `that` is a proper prefix of
`this`, then `this` is `Greater` than `that`.

Both `offset` and `that_offset` can be negative, in which case the offsets
are computed from the end of the string.

If `n + offset` is greater than the length of `this`, or `n + that_offset`


fun box sctp_sat_network_min()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_selective_ack¶
[Source]


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


fun box max_tcpoptlen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mcast_exclude¶
[Source]


fun box op_not()
: ULong val

Returns¶

ULong val

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

Parameters¶

y: ULong val

Returns¶


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


```

If `inc` is nonzero, but cannot produce progress towards `max` because of its sign, the `Range` is considered empty and will not produce any iterations. The `Range` is also empty if either `min` equals `max`, independent of the value of `inc`, or if `inc` is zero.

```pony
let empty_range1 = Range(0, 10, -1)
let empty_range2 = Range(0, 10, 0)
let empty_range3 = Range(10, 10)
empty_range1.is_empty() == true
empty_range2.is_empty() == true
empty_range3.is_empty() == true
```

Note that when using unsigned integers, a negative literal wraps around so while `Range[ISize](0, 10, -1)` is empty as above, `Range[USize](0, 10, -1)` produces a single value of `min` or `[0]` here.

When using `Range` with floating point types (`F32` and `F64`) `inc` steps < 1.0 are possible. If any arguments contains NaN, the `Range` is considered empty. It is also empty if the lower bound `min` or the step `inc` are +Inf or -Inf. However, if only the upper bound `max` is +Inf or -Inf and the step parameter `inc` has the same sign, then the `Range` is considered infinite and will iterate indefinitely.

```pony
let p_inf: F64 = F64.max_value() + F64.max_value()
let n_inf: F64 = -p_inf


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

Parameters¶

a: A

Returns¶

I8 val^

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

Returns¶


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


Returns¶

U32 val

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

Returns¶

U32 val

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


: Bool val

Parameters¶

that: Path val

Returns¶

Bool val

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

Parameters¶

that: Path val


: (Less val | Equal val | Greater val)

Parameters¶

that: String box
n: USize val
offset: ISize val = 0
that_offset: ISize val = 0
ignore_case: Bool val = false

Returns¶

(Less val | Equal val | Greater val)

eq¶
[Source]
Returns true if the two strings have the same contents.
fun box eq(
that: String box)


FileRead¶
[Source]
primitive val FileRead

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

Returns¶

FileRead val^


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


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


## Reading from a `box` variable

A `box` variable is locally immutable. This means it's possible that it may be mutated through some other variable (a `trn` or a `ref`), but it's also possible that our `box` variable is an alias of some `val` variable.

When we read a field, we need to return a reference capability that is compatible with the field but is also locally immutable.

An `iso` field is returned as a `tag` because no locally immutable reference capability can maintain its isolation guarantees. A `val` field is returned as a `val` because global immutability is a stronger guarantee than local immutability. A `box` field makes the same local immutability guarantee as its origin, so that's also fine.

For `trn` and `ref` we need to return a locally immutable reference capability that doesn't violate any guarantees the field makes. In both cases, we can return `box`.


y: U8 val

Returns¶

Bool val

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

Returns¶

USize val

hash64¶
[Source]


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

Returns¶

OverheadBenchmark iso^

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

Returns¶

String val


UnknownError¶
[Source]
primitive val UnknownError

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

Returns¶

UnknownError 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))] is
Iterator[A] ref

Implements¶

Iterator[A] ref

Constructors¶
create¶
[Source]
new ref create(
min: A,
max: A,
inc: A = 1)
: Range[A] ref^


// Something other than EWOULDBLOCK, try again.
None
| 0 =>
// EWOULDBLOCK, don't try again.
return
else
_spawn(fd)
end
end

_paused = true
end

fun ref _spawn(ns: U32) =>
"""
Spawn a new connection.
"""
try
TCPConnection._accept(this, _notify.connected(this)?, ns,
_read_buffer_size, _yield_after_reading, _yield_after_writing)


# left side must be something that can be assigned to

Suppose you wrote:

```pony
actor Main
let x: I64 = 0
new create(env: Env) =>
x = 12
```

The error message would be:

```error
Error:
.../a.pony:6:5: can't assign to a let or embed definition more than once
x = 12
^
Error:
.../a.pony:6:7: left side must be something that can be assigned to


fun box ipproto_wbexpak()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_wsn¶
[Source]


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


h: PropertyHelper val

Returns¶

None val ?

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

Parameters¶


fun box tcp_fastopen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_function_name_len_max¶
[Source]


fun box ipv6_fl_f_reflect()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_fl_s_any¶
[Source]


"""
Generator[String](
object is GenObj[String]
fun generate(rnd: Randomness): GenerateResult[String] =>
let size = rnd.usize(min, max)
let gen_iter = Iter[U32^](gen.value_iter(rnd))
.filter({(cp) =>
// excluding surrogate pairs
(cp <= 0xD7FF) or (cp >= 0xE000) })
.take(size)
let s: String iso = recover String(size) end
for code_point in gen_iter do
s.push_utf32(code_point)
end
s

fun shrink(s: String): ValueAndShrink[String] =>
"""
Strip off codepoints from the end, not just bytes, so we
maintain a valid utf8 string.


_alloc = alloc.max(_size.min(len.max_value() - 1))
_ptr = str
end

new from_cstring(str: Pointer[U8]) =>
"""
Return a string from a pointer to a null-terminated cstring
without making a copy. The data is not copied. This must be done
only with C-FFI functions that return pony_alloc'd character
arrays. The pointer is scanned for the first null byte, which will
be interpreted as the null terminator. Note that the scan is
unbounded; the pointed to data must be null-terminated within
the allocated array to preserve memory safety. If a null pointer
is given then an empty string is returned.
"""
if str.is_null() then
_size = 0
_alloc = 1
_ptr = Pointer[U8]._alloc(_alloc)
_set(0, 0)


(A , A)

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

Parameters¶

y: A

Returns¶

A


: None val

Parameters¶

that: List[A] ref

Returns¶

None val

prepend_list¶
[Source]
Empties the provided List by prepending all elements onto the receiving List.
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = List[String].from(["d"; "e"; "f"])
my_list.prepend_list(other_list)  // my_list is ["d"; "e"; "f"; "a"; "b"; "c"], other_list is empty

fun ref prepend_list(
that: List[A] ref)


Returns¶

F64 val

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

Returns¶

F64 val

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


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

Parameters¶

n: N

Returns¶

N

real¶
fun ref real()
: F64 val

Returns¶


fun box dso_info()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dso_max¶
[Source]


292
293
294
295
296
297
298
299use mut = "collections"

class val Vec[A: Any #share]
"""
A persistent vector based on the Hash Array Mapped Trie from 'Ideal Hash
Trees' by Phil Bagwell.
"""

let _root: (_VecNode[A] | None)
let _tail: Array[A] val
let _size: USize
let _depth: USize


fun box tcpf_ca_loss()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpf_ca_recovery¶
[Source]


if outer_iterator.has_next() then
inner_iterator = outer_iterator.next()?
return next()?
end

error
end

new repeat_value(value: A) =>
"""
Create an iterator that returns the given value forever.


process_error.pony

1
2
3
4
5
6
7
8
9
10
11


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

Returns¶

USize val

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

Returns¶

I8 val


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

Parameters¶

y: ISize val

Returns¶

(ISize val , Bool val)

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


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

Parameters¶

y: U16 val

Returns¶

U16 val

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

Parameters¶


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


"""
Builds a new list with an element added to the front of this list.
"""
Cons[A](consume a, this)

fun concat(l: List[A]): List[A] =>
"""
The concatenation of any list l with the empty list is l.
"""
l

fun map[B](f: {(val->A): val->B} box): Nil[B] =>
"""
Mapping a function from A to B over the empty list yields the
empty list of Bs.
"""
Nil[B]

fun flat_map[B](f: {(val->A): List[B]} box): Nil[B] =>
"""


(Less val | Equal val | Greater val)


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


# Fast, Safe and Cheap

* An actor has ~240 bytes of memory overhead.
* No locks. No context switches. All mutation is local.
* An idle actor consumes no resources (other than memory).
* You can have millions of actors at the same time.


ISize¶
[Source]
primitive val ISize is
SignedInteger[ISize val, USize val] val

Implements¶

SignedInteger[ISize val, USize val] val

Constructors¶
create¶
[Source]


(USize val , Bool val)

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

Parameters¶

y: USize val

Returns¶

(USize val , Bool val)

remc¶
[Source]


1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031


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


fun box ipv6_fl_a_put()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_fl_f_create¶
[Source]


host: String val)
: Bool val

Parameters¶

host: String val

Returns¶

Bool val

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

Parameters¶


is greater than the length of `that`, then the number of positions compared
will be reduced to the length of the longest substring.

Needs to be made UTF-8 safe.
"""
var j: USize = offset_to_index(offset)
var k: USize = that.offset_to_index(that_offset)
var i = n.min((_size - j).max(that._size - k))

while i > 0 do
// this and that are equal up to this point
if j >= _size then
// this is shorter
return Less
elseif k >= that._size then
// that is shorter
return Greater
end

let c1 = _ptr._apply(j)


# Traits and Interfaces

Like other object-oriented languages, Pony has __subtyping__. That is, some types serve as _categories_ that other types can be members of.

There are two kinds of __subtyping__ in programming languages: __nominal__ and __structural__. They're subtly different, and most programming languages only have one or the other. Pony has both!


fun box ipv6_minhopcount()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_mtu_discover¶
[Source]


fun box mcast_join_group()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mcast_leave_group¶
[Source]


# Built-in primitive types

The `primitive` keyword is also used to introduce certain built-in "machine word" types. Other than having a value associated with them, these work like user-defined primitives. These are:

* `Bool`. This is a 1-bit value that is either `true` or `false`.
* `ISize`, `ILong`, `I8`, `I16`, `I32`, `I64`, `I128`. Signed integers of various widths.
* `USize`, `ULong`, `U8`, `U16`, `U32`, `U64`, `U128`. Unsigned integers of various widths.
* `F32`, `F64`. Floating point numbers of various widths.

`ISize`/`USize` correspond to the bit width of the native type `size_t`, which varies by platform. `ILong`/`ULong` similarly correspond to the bit width of the native type `long`, which also varies by platform. The bit width of a native `int` is the same across all the platforms that Pony supports, and you can use `I32`/`U32` for this.


else
false
end

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

class val _Run is Equatable[_Round]
"""
An execution of a property during test mode. i.e. normal execution
to find a sample for which the property does not hold.
"""
let _round: USize

new val create(round': USize) =>
_round = round'

fun round(): USize => _round

fun inc(): _Round =>


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


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

Returns¶

USize val

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

Returns¶

U64 val


None val

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

Parameters¶

data: I32 val

Returns¶

None val


[Source]
Remove a mapping. This only takes effect if provided key currently maps to
the provided value. If the key maps to some other value (perhaps after
updating), the mapping won't be removed.
be remove(
key: String val,
value: Any tag)

Parameters¶

key: String val
value: Any tag

Public Functions¶
apply[optional A: Any tag]¶
[Source]
Lookup by name. Returns a promise that will be fulfilled with the mapped
value if it exists and is a subtype of A. Otherwise, the promise will be
rejected.


y: ULong val

Returns¶

(ULong val , ULong val)

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

Parameters¶

y: ULong val

Returns¶


embed _after_cont: AsyncBenchContinue =
AsyncBenchContinue._create(this, recover this~_after_done_cont() end)

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

be apply() =>
_bench.before(_before_cont)

be _before_done_cont(e: U64) =>
_n = 0
_a = 0


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

Parameters¶

that: FilePermissionDenied val

Returns¶

Bool val


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


### Example

```pony
Iter[USize]([as USize: 1; 1; 2; 3; 3; 2; 2].values())
.dedup()
```
`1 2 3 2`
"""
Iter[A!](
object is Iterator[A!]
var _prev_value: (A! | None) = None
var _prev_hash: USize = 0

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

fun ref next(): A! ? =>
let cur_value: A! = _iter.next()?
let cur_hash: USize = H.hash(cur_value)
match _prev_value


| 2 => int_property[U32](x.u32(), y.u32(), h)?
| 3 => int_property[U64](x.u64(), y.u64(), h)?
| 4 => int_property[ULong](x.ulong(), y.ulong(), h)?
| 5 => int_property[USize](x.usize(), y.usize(), h)?
| 6 => int_property[U128](x, y, h)?
| 7 => int_property[I8](x.i8(), y.i8(), h)?
| 8 => int_property[I16](x.i16(), y.i16(), h)?
| 9 => int_property[I32](x.i32(), y.i32(), h)?
| 10 => int_property[I64](x.i64(), y.i64(), h)?
| 11 => int_property[ILong](x.ilong(), y.ilong(), h)?
| 12 => int_property[ISize](x.isize(), y.isize(), h)?
| 13 => int_property[I128](x.i128(), y.i128(), h)?
else
h.log("rem is broken")
error
end

fun ref int_property[T: (Int & Integer[T] val)](x: T, y: T, h: PropertyHelper)?


fun box sctp_cmt_mptcp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cmt_on_off¶
[Source]


A

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

Returns¶

A

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

Returns¶


The [Generator](pony_check-Generator.md) used to produce samples to verify.
"""

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

trait Property2[T1, T2] is Property1[(T1, T2)]

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

fun gen2(): Generator[T2]
"""
The Generator for the second argument to your `property2`.
"""


: TCPListener tag^

Parameters¶

auth: TCPListenAuth val
notify: TCPListenNotify iso
host: String val = ""
service: String val = "0"
limit: USize val = 0
read_buffer_size: USize val = 16384
yield_after_reading: USize val = 16384
yield_after_writing: USize val = 16384

Returns¶

TCPListener tag^

Public Behaviours¶
set_notify¶


_tail = consume t
_size = 1 + _tail.size()

fun size(): USize =>
"""
Returns the size of the list.
"""
_size

fun apply(i: USize): val->A ? =>
"""
Returns the i-th element of the list. Errors if the index is out of bounds.
"""
match i
| 0 => _head
else _tail(i - 1)?
end

fun values(): Iterator[val->A]^ =>
"""


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

Parameters¶

map: M

Returns¶

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

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


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

Parameters¶

y: box->A

Returns¶

Bool val

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

Parameters¶


fun ref throttled(connection: TCPConnection ref) =>
_out.print("Experiencing backpressure!")
Backpressure.apply(_auth)

fun ref unthrottled(connection: TCPConnection ref) =>
_out.print("Releasing backpressure!")
Backpressure.release(_auth)

fun ref closed(connection: TCPConnection ref) =>
// if backpressure has been applied, make sure we release
// when shutting down
_out.print("Releasing backpressure if applied!")
Backpressure.release(_auth)

fun ref connect_failed(conn: TCPConnection ref) =>
None

actor Main
new create(env: Env) =>


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


if freebsd or "capsicum"
use @__cap_rights_clear[Pointer[U64]](...)
if freebsd or "capsicum"
use @__cap_rights_set[Pointer[U64]](...)
if freebsd or "capsicum"
use @__cap_rights_get[I32](version: I32, fd: I32, rights: Pointer[U64])
if freebsd or "capsicum"
use @cap_rights_limit[I32](fd: I32, rights: Pointer[U64])
if freebsd or "capsicum"
use @cap_rights_merge[None](dst: Pointer[U64], src: Pointer[U64])
if freebsd or "capsicum"
use @cap_rights_remove[None](dst: Pointer[U64], src: Pointer[U64])
if freebsd or "capsicum"
use @cap_rights_contains[Bool](big: Pointer[U64] tag, little: Pointer[U64] tag)
if freebsd or "capsicum"

type CapRights is CapRights0

class CapRights0
"""


"""
_runner.dispose_when_done(disposable)


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


FileChown¶
[Source]
primitive val FileChown

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

Returns¶

FileChown val^


fun box mod_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶

A

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

Parameters¶


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


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


FileEOF val | FileBadFileNumber val | FileExists val |
FilePermissionDenied val)

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

Parameters¶

that: CreateFile val

Returns¶

Bool val

ne¶


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

Parameters¶

that: HashSet[A, H] box

Returns¶

Bool val

ge¶
[Source]
Return true if every element in that is also in this.
fun box ge(


fun is_parent(): Bool => _type is _CommandSpecParent

fun help_name(): String =>
"""
Returns the name of the help command, which defaults to "help".
"""
_help_name

fun help_string(): String =>
"""
Returns a formated help string for this command and all of its arguments.
"""
let s = _name.clone()
s.append(" ")
let args_iter = _args.values()
for a in args_iter do
s.append(a.help_string())
if args_iter.has_next() then s.append(" ") end
end


epsilon¶
[Source]
Minimum positive value such that (1 + epsilon) != 1.
new val epsilon()
: F32 val^

Returns¶

F32 val^

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

Returns¶


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


min: USize val = 0,
max: USize val = 100)
: Generator[String val] box

Parameters¶

min: USize val = 0
max: USize val = 100

Returns¶

Generator[String val] box

unicode_bmp¶
[Source]
Create a generator for unicode strings
from the basic multilingual plane only,
with a minimum length of min codepoints (default: 0)
and a maximum length of max codepoints (default: 100).


timer.pony

1
2
3
4
5
6
7
8
9
10
11


# Structs

A `struct` is similar to a `class`. There's a couple very important differences. You'll use classes throughout your Pony code. You'll rarely use structs. We'll discuss structs in more depth in the [C-FFI chapter](/c-ffi/index.md) of the tutorial. In the meantime, here's a short introduction to the basics of structs.


Called if the signal is disposed. This is also called if the notifier
returns false.
"""
None

primitive SignalRaise
"""
Raise a signal.
"""
fun apply(sig: U32) =>
ifdef osx then
// On Darwin, @raise delivers the signal to the current thread, not the
// process, but kqueue EVFILT_SIGNAL will only see signals delivered to
// the process. @kill delivers the signal to a specific process.
@kill(@getpid(), sig)
else
@raise(sig)
end


end

i = i + 1
end
else
ok = false
end
end

if not ok then
_fail(_fmt_msg(loc, "Assert EQ failed. " + msg + " Expected ("
+ _print_array[A](expect) + ") == (" + _print_array[A](actual) + ")"))
return false
end

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


writer.pony

1
2
3
4
5
6
7
8
9
10
11


fun box icmp_redirect()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

icmp_redir_hosttos¶
[Source]


env.out.print(gcd.string())
else
env.out.print("No GCD")
end
```
"""
fun apply[A: Integer[A] val](x: A, y: A): A ? =>
let zero = A.from[U8](0)
if (x == zero) or (y == zero) then
error
end

var x': A = x
var y': A = y

while y' != zero do
let z = y'
y' = x' % y'
x' = z
end


let xs = Iter[I64]([1; 2; 3; 4; 5].values())
.map[I64]({(x) => x + 1 })
.filter({(x) => (x % 2) == 0 })
.map[None]({(x) => env.out.print(x.string()) })

This will result in an iterator that prints the numbers 2, 4, and 6. However,
due to the lazy nature of the map and filter, no iteration has actually occurred
and nothing will be printed. One solution to this would be to loop over the
resulting Iter as so:
for x in xs do
None
end

This will trigger the iteration and print out the values 2, 4, and 6. This is
where the run method comes in handy by doing the iteration without the need
for a loop. So the final code would be as follows:
Iter[I64]([1; 2; 3; 4; 5].values())
.map[I64]({(x) => x + 1 })
.filter({(x) => (x % 2) == 0 })
.map[None]({(x) => env.out.print(x.string()) })


the property is not failing anymore.
The last failing sample, which is considered the most simple one,
is then reported to the user.
class box Generator[T: T] is
GenObj[T] box

Implements¶

GenObj[T] box

Constructors¶
create¶
[Source]
new ref create(
gen: GenObj[T] box)
: Generator[T] ref^

Parameters¶


fun box dccp_sockopt_qpolicy_txqlen()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dccp_sockopt_rx_ccid¶
[Source]


### Example

```pony
Iter[I64]([1; 2; 3].values())
.nth(2)
```
`2`
"""
var c = n
while _iter.has_next() and (c > 1) do
_iter.next()?
c = c - 1
end
if not _iter.has_next() then
error
else
_iter.next()?
end

fun ref run(on_error: {ref()} = {() => None } ref) =>


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


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


apply¶
[Source]
Returns the i-th element of the sequence. For the empty list this call will
always error because any index will be out of bounds.
fun box apply(
i: USize val)
: val->A ?

Parameters¶

i: USize val

Returns¶

val->A ?

values¶
[Source]


servicename: Bool val = false

Returns¶

(String val , String val) ?

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

Parameters¶

that: NetAddress box

Returns¶

Bool val


in_list

fun ref append(that: ListNode[A]): Bool =>
"""
Append a node to this one. If `that` is already in a list, it is removed
before it is appended. Returns true if `that` was removed from another
list.

If the ListNode is not contained within a List the append will fail.
"""
if (_next is that) or (this is that) then
return false
end

var in_list = false

match _list
| let list': List[A] =>
in_list = that._list isnt None
that.remove()


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


A reject that always raises an error.
"""
fun ref apply(): A ? =>
error


y: U64 val

Returns¶

U64 val

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

Parameters¶

y: U64 val

Returns¶


that: FileTruncate val

Returns¶

Bool val

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

Parameters¶

that: FileTruncate val

Returns¶


fun box sctp_connect_x_delayed()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cookie_ack¶
[Source]


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


create¶
[Source]
Create a signal handler.
new tag create(
notify: SignalNotify iso,
sig: U32 val,
wait: Bool val = false)
: SignalHandler tag^

Parameters¶

notify: SignalNotify iso
sig: U32 val
wait: Bool val = false

Returns¶

SignalHandler tag^


weighted_generators: ReadSeq[(USize val , Generator[T] box)] box

Returns¶

Generator[T] box

frequency_safe[T: T]¶
[Source]
Version of frequency that errors if the given weighted_generators is
empty.
fun box frequency_safe[T: T](
weighted_generators: ReadSeq[(USize val , Generator[T] box)] box)
: Generator[T] box ?

Parameters¶

weighted_generators: ReadSeq[(USize val , Generator[T] box)] box

Returns¶


Parameters¶

gen1': Generator[T1] val
gen2': Generator[T2] val
h: TestHelper val

Returns¶

ForAll2[T1, T2] ref^

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

Parameters¶


FormatOctal¶
[Source]
primitive val FormatOctal is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


# Passing and Sharing References

Reference capabilities make it safe to both __pass__ mutable data between actors and to __share__ immutable data amongst actors. Not only that, they make it safe to do it with no copying, no locks, in fact, no runtime overhead at all.


F32 val

neg_unsafe¶
fun box neg_unsafe()
: F32 val

Returns¶

F32 val

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

Parameters¶

y: F32 val


let i = offset_to_index(offset)
let err: (U32, U8) = (0xFFFD, 1)

if i >= _size then error end
let c = _ptr._apply(i)

if c < 0x80 then
// 1-byte
(c.u32(), 1)
elseif c < 0xC2 then
// Stray continuation.
err
elseif c < 0xE0 then
// 2-byte
if (i + 1) >= _size then
// Not enough bytes.
err
else
let c2 = _ptr._apply(i + 1)
if (c2 and 0xC0) != 0x80 then


ifdef bsd or osx then 31
elseif linux then 12
else compile_error "no SIGUSR2"
end
else
ifdef linux or bsd or osx then
compile_error "SIGUSR2 reserved for runtime use"
else
compile_error "no SIGUSR2"
end
end

fun rt(n: U32): U32 ? =>
ifdef bsd then
if n <= 61 then
65 + n.u32()
else
error
end
elseif linux then


Returns¶

ULong val ?

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

Parameters¶

base: U8 val = 0

Returns¶

USize val ?


gen4: Generator[T4] box

Returns¶

Generator[(T1 , T2 , T3 , T4)] box

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

Parameters¶

gen1: Generator[T1] box
gen2: Generator[T2] box


interface Hashable64
"""
A version of Hashable that returns 64-bit hashes on every platform.
"""
fun hash64(): U64

interface val HashFunction[A]
"""
A pluggable hash function.
"""
new val create()
"""
Data structures create instances internally. Use a primitive if possible.
"""

fun hash(x: box->A!): USize
"""
Calculate the hash of some type. This is an alias of the type parameter to
allow data structures to hash things without consuming them.


fun box sctp_log_try_advance()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_ltrace_error_enable¶
[Source]


Bool val


1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731


fun box ndrv_demuxtype_snap()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ndrv_protocol_desc_vers¶
[Source]


# Viewpoint adaptation

The process of combining origin and field capabilities is called __viewpoint adaptation__. That is, the __origin__ has a __viewpoint__, and its fields can be "seen" only from that __viewpoint__.

Let's start with a table. This shows how a __field__ of each capability looks when using an __origin__ of each capability.

---

| ▷       | `iso` field | `trn` field | `ref` field | `val` field | `box` field | `tag` field |
| -------------- | --------- | --------- | --------- | --------- | --------- | --------- |
| __`iso` origin__ | `iso`       | `tag`       | `tag`       | `val`       | `tag`       | `tag`       |
| __`trn` origin__ | `iso`       | `box`       | `box`       | `val`       | `box`       | `tag`       |
| __`ref` origin__ | `iso`       | `trn`       | `ref`       | `val`       | `box`       | `tag`       |
| __`val` origin__ | `val`       | `val`       | `val`       | `val`       | `val`       | `tag`       |
| __`box` origin__ | `tag`       | `box`       | `box`       | `val`       | `box`       | `tag`       |
| __`tag` origin__ | n/a       | n/a       | n/a       | n/a       | n/a       | n/a       |

---

For example, if you have a `trn` origin and you read a `ref` field, you get a `box` result:


str: Pointer[U8 val] box

Returns¶

String ref^

from_utf32¶
[Source]
Create a UTF-8 string from a single UTF-32 code point.
new ref from_utf32(
value: U32 val)
: String ref^

Parameters¶

value: U32 val

Returns¶


792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811


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


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


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

ifdef linux or bsd then
var tv: (ILong, ILong, ILong, ILong) =
( atime._1.ilong(), atime._2.ilong() / 1000,
mtime._1.ilong(), mtime._2.ilong() / 1000 )

0 == @futimesat(_fd, target.cstring(), addressof tv)
else
path'.set_time(atime, mtime)
end
else
false
end

fun symlink(source: FilePath, link_name: String): Bool =>
"""
Link the source path to the link_name, where the link_name is relative to
this directory.


FormatBinary¶
[Source]
primitive val FormatBinary is
FormatSpec val

Implements¶

FormatSpec val

Constructors¶
create¶
[Source]


fun box symlinkat()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

accept¶
[Source]


After a successful reading operation `_buffer_cursor` is updated.
"""
var result = true
// get back to position of last line
let current_pos = _file.position()
_file.seek_start(_buffer_cursor)
if _file.valid() then
let read_bytes = _last_line_length.max(_min_read_size)
let read_buf = _file.read(read_bytes)
_buffer_cursor = _file.position()

let errno = _file.errno()
if (read_buf.size() == 0) and (errno isnt FileOK) then
result = false
else
// TODO: Limit size of read buffer
_reader.append(consume read_buf)
end
else
result = false


Returns¶

F32 val

f64_unsafe¶
fun box f64_unsafe()
: F64 val

Returns¶

F64 val

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


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

Parameters¶

y: U32 val

Returns¶

Bool val

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

Parameters¶