U32 val

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

Returns¶

U32 val

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


Bool val

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

Parameters¶

that: HashEq64[A] val

Returns¶

Bool val


[Source]
fun box op_or(
y: Bool val)
: Bool val

Parameters¶

y: Bool val

Returns¶

Bool val

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


: None val

Parameters¶

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

Returns¶

None val

clear¶
[Source]
Truncate the string to zero length.
fun ref clear()
: None val

Returns¶


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


# Mutable reference capabilities

The __mutable__ reference capabilities are `iso`, `trn` and `ref`. These reference capabilities are __mutable__ because they can be used to both read from and write to an object.

* If an actor has an `iso` variable, no other variable can be used by _any_ actor to read from or write to that object. This means an `iso` variable is the only variable anywhere in the program that can read from or write to that object. It is _read and write unique_.
* If an actor has a `trn` variable, no other variable can be used by _any_ actor to write to that object, and no other variable can be used by _other_ actors to read from or write to that object. This means a `trn` variable is the only variable anywhere in the program that can write to that object, but other variables held by the same actor may be able to read from it. It is _write unique_.
* If an actor has a `ref` variable, no other variable can be used by _other_ actors to read from or write to that object. This means that other variables can be used to read from and write to the object, but only from within the same actor.

__Why can they be used to write?__ Because they all stop _other_ actors from reading from or writing to the object. Since we know no other actor will be reading, it's safe for us to write to the object, without having to worry about data-races. And since we know no other actor will be writing, it's safe for us to read from the object, too.


"""
MUST be called by each long test to indicate the test has finished, unless
a timeout occurs. If you are using expect_action() then complete(true) will
be called once the last expected action has been completed via
complete_action().

The "success" parameter specifies whether the test succeeded. However if
any asserts fail the test will be considered a failure, regardless of the
value of this parameter.

Once this is called tear_down() may be called at any time.
"""
_runner.complete(success)

fun expect_action(name: String) =>
"""
Can be called in a long test to set up expectations for one or more actions
that, when all completed, will complete the test.

This pattern is useful for cases where you have multiple things that need


Returns¶

F32 val

f64_unsafe¶
fun box f64_unsafe()
: F64 val

Returns¶

F64 val

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


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


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


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


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


y: U16 val

Returns¶

U16 val

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

Returns¶

U16 val

add¶
[Source]


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

Returns¶

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

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

Parameters¶

f: {(B, val->A): B^}[A, B] box
acc: B


fun box sctp_pr_assoc_status()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pr_supported¶
[Source]


fun box mrt_mfc_flags_disable_wrongvif()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mrt_pim¶
[Source]


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

Returns¶

None val ?

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

Returns¶

None val ?


// Generates values from `from` to 0
class ref Countdown is Iterator[USize]
var _cur: USize
var _has_next: Bool = true

new ref create(from: USize) =>
_cur = from

fun ref has_next(): Bool =>
_has_next

fun ref next(): USize =>
let elem = _cur = _cur - 1
if elem == 0 then
_has_next = false
end
elem

interface ref Iterator[A: A]


bright_blue_bg¶
[Source]
Bright blue background.
fun box bright_blue_bg()
: String val

Returns¶

String val

bright_magenta_bg¶
[Source]
Bright magenta background.
fun box bright_magenta_bg()
: String val

Returns¶


A ?

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

Parameters¶

y: A

Returns¶

A ?

div_partial¶
[Source]


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


72
73
74
75
76
77
78class RingBuffer[A]
"""
A ring buffer.
"""
embed _array: Array[A]
let _mod: USize
var _write: USize = 0

new create(len: USize) =>
"""
Create a ring buffer with a fixed size. The size will be rounded up to the
next power of 2.
"""
let n = len.max(2).next_pow2()


U8 val

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

Returns¶

U16 val

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

Returns¶


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

Parameters¶

that: AlignRight val

Returns¶

Bool val

ne¶
[Source]


s

class val OptionSpec
"""
OptionSpec describes the specification of a named Option. They have a name,
descr(iption), a short-name, a typ(e), and a default value when they are not
required.

Options can be placed anywhere before or after commands, and can be thought
of as named arguments.
"""
let _name: String
let _descr: String
let _short: (U8 | None)
let _typ: _ValueType
let _default: _Value
let _required: Bool

fun tag _init(typ': _ValueType, default': (_Value | None))
: (_ValueType, _Value, Bool)


clear¶
[Source]
Remove all elements from the array.
fun ref clear()
: None val

Returns¶

None val

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


```pony
let a: String val = "Hello, world!"
let b: String = "I'm a wombat!" // Also a String val
```

__So do I have to specify a reference capability when I define a type?__ Only if you want to. There are sensible defaults that most types will use. These are `ref` for classes, `val` for primitives (i.e. immutable references), and `tag` for actors.


I64 val

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

Returns¶

String iso^

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

Parameters¶


Parameters¶

to: String val
target: String val

Returns¶

String val ?

split¶
[Source]
Splits the path into a pair, (head, tail) where tail is the last pathname
component and head is everything leading up to that. The tail part will
never contain a slash; if path ends in a slash, tail will be empty. If
there is no slash in path, head will be empty. If path is empty, both head
and tail are empty. The path in head will be cleaned before it is returned.
In all cases, join(head, tail) returns a path to the same location as path
(but the strings may differ). Also see the functions dir() and base().


# Testing with PonyTest

PonyTest is Pony's unit testing framework. It is designed to be as simple as possible to use, both for the unit test writer and the user running the tests.

Each unit test is a class, with a single test function. By default, all tests run concurrently.

Each test run is provided with a helper object. This provides logging and assertion functions. By default log messages are only shown for tests that fail.

When any assertion function fails the test is counted as a fail. However, tests can also indicate failure by raising an error in the test function.


that: ASCIIWhiteSpace val

Returns¶

Bool val

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

Parameters¶

that: ASCIIWhiteSpace val

Returns¶


6
4
2
```

If `dec` is 0, produces an infinite series of `max`.

If `dec` is negative, produces a range with `max` as the only value.

"""

let _min: A
let _max: A
let _dec: A
var _idx: A

new create(max: A, min: A, dec: A = 1) =>
_min = min
_max = max
_dec = dec


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


fun box ipv6_2292hoplimit()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_2292pktinfo¶
[Source]


Option¶
[Source]
Option contains a spec and an effective value for a given option.
class val Option

Constructors¶
create¶
[Source]
new val create(
spec': OptionSpec val,
value': (Bool val | String val | I64 val |
U64 val | F64 val | _StringSeq val))
: Option val^


object is Iterator[B]
fun ref has_next(): Bool =>
_iter.has_next()

fun ref next(): B ? =>
f(_iter.next()?)?
end)

fun ref filter_stateful(f: {ref(A!): Bool ?}): Iter[A!]^ =>
"""
Allows filtering of elements based on a stateful adapter, similar to
`filter`.
"""
Iter[A!](
object
var _next: (A! | _None) = _None

fun ref _find_next() =>
try
match _next


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

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

fun bitwidth(): U128 => 128

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

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


Parameters¶

n: N

Returns¶

N

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

Returns¶

F64 val


caps': FileCaps val = recover val FileCaps .> all() end) ?
=>
"""
Create a new path from an existing `FilePath`.

path' is relative to the existing `FilePath`,
and the existing `FilePath` must be a prefix of the resulting path.

The resulting `FilePath` will have capabilities that are the intersection of
the supplied capabilities and the capabilities of the existing `FilePath`.
"""
caps.union(caps')
if not base.caps(FileLookup) then
error
end

let tmp_path = Path.join(base.path, path')
caps.intersect(base.caps)

if not tmp_path.at(base.path, 0) then


Parameters¶

target: String val

Returns¶

Bool val

create_file¶
[Source]
Open for read/write, creating if it doesn't exist, preserving the contents
if it does exist.
fun box create_file(
target: String val)
: File iso^ ?

Parameters¶

target: String val


object is Iterator[ValueAndShrink[T]]
fun ref has_next(): Bool => true
fun ref next(): ValueAndShrink[T] ? =>
match that.generate(rnd)?
| let value_only: T => that.shrink(consume value_only)
| (let v: T, let shrinks: Iterator[T^]) => (consume v, consume shrinks)
end
end

class box Generator[T] is GenObj[T]
"""
A Generator is capable of generating random values of a certain type `T`
given a source of `Randomness`
and knows how to shrink or simplify values of that type.

When testing a property against one or more given Generators,
those generators' `generate` methods are being called many times
to generate sample values that are then used to validate the property.


fun box fpathconf()
: U64 val

Returns¶

U64 val

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

Returns¶

U64 val

fstat¶
[Source]


Bool val

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

Returns¶

Bool val

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

Returns¶


You never have to declare variables as `let`, but if you know you're never going to change what a variable references then using `let` is a good way to catch errors. It can also serve as a useful comment, indicating what is referenced is not meant to be changed.


var wr: _WaitResult = WaitpidError
if h_process != 0 then
var exit_code: I32 = 0
match @ponyint_win_process_wait(h_process, addressof exit_code)
| 0 =>
wr = Exited(exit_code)
final_wait_result = wr
wr
| 1 => _StillRunning
| let code: I32 =>
// we might want to propagate that code to the user, but should it do
// for other errors too
final_wait_result = wr
wr
end
else
final_wait_result = wr
wr
end
end


"""
let that = this
Generator[ULong](
object is GenObj[ULong]
fun generate(rnd: Randomness): ULong^ =>
rnd.ulong(min, max)

fun shrink(u: ULong): ValueAndShrink[ULong] =>
that._int_shrink[ULong](consume u, min)
end)

fun i8(
min: I8 = I8.min_value(),
max: I8 = I8.max_value())
: Generator[I8]
=>
"""
Create a generator for I8 values.
"""
let that = this


fun box i64()
: I64 val

Returns¶

I64 val

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

Returns¶

I128 val

ilong¶
[Source]


fun box sctp_ss_round_robin_packet()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_status¶
[Source]


if element.size() > 0 then
let r = ifdef windows then
@_mkdir(element.cstring())
else
@mkdir(element.cstring(), U32(0x1FF))
end

if r != 0 then
if @pony_os_errno() != @pony_os_eexist() then
return false
end

if must_create and (offset < 0) then
return false
end
end
end
until offset < 0 end


fun box af_coip()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

af_inet6¶
[Source]


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


fun dispose(): U32 => 0

fun read(): U32 => 1 << 0

fun write(): U32 => 1 << 1

fun timer(): U32 => 1 << 2

fun signal(): U32 => 1 << 3

fun read_write(): U32 => read() or write()

fun oneshot(): U32 => 1 << 8

fun read_write_oneshot(): U32 => read() or write() or oneshot()


U64 val | U128 val | ULong val |
USize val) & Real[N] val)](
n: N)
: N

Parameters¶

n: N

Returns¶

N

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


fun box tcpi_opt_toe()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpolen_cc¶
[Source]


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

The --noadjust option outputs results of the overhead measured prior to each
benchmark run followed by the unadjusted benchmark result. An example of the
output of this program with --noadjust is as follows:
Benchmark                                   mean            median   deviation  iterations
Benchmark Overhead                        604 ns            603 ns      ±0.58%      300000
Nothing                                   553 ns            553 ns      ±0.30%      300000
Benchmark Overhead                        555 ns            555 ns      ±0.51%      300000
_Fib(5)                                   574 ns            574 ns      ±0.43%      300000
Benchmark Overhead                        554 ns            556 ns      ±0.48%      300000
_Fib(10)                                  822 ns            821 ns      ±0.39%      200000
Benchmark Overhead                        554 ns            553 ns      ±0.65%      300000
_Fib(20)                                30470 ns          30304 ns      ±1.55%        5000


b.i32()
```

Let's say we wish to compare the pure Pony performance to an existing C function with the following header:

```c


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


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


_out = out

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


Parameters¶

that: Flags[A, B] box

Returns¶

Flags[A, B] iso^

without¶
[Source]
The flags in this that are not in that.
fun box without(
that: Flags[A, B] box)
: Flags[A, B] iso^

Parameters¶

that: Flags[A, B] box


None val

recalc¶
[Source]
Recalculates the string length. This is only needed if the string is
changed via an FFI call. If a null terminator byte is not found within the
allocated length, the size will not be changed.
fun ref recalc()
: None val

Returns¶

None val

truncate¶
[Source]
Truncates the string at the minimum of len and space. Ensures there is a
null terminator. Does not check for null terminators inside the string.


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


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


fun box ip_dummynet_configure()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ip_dummynet_flush¶
[Source]


"""
let pos = position()
_seek(0, 2)
let len = position()
_seek(pos.i64(), 0)
len

fun ref seek_start(offset: USize) =>
"""
Set the cursor position relative to the start of the file.
"""
if path.caps(FileSeek) then
_seek(offset.i64(), 0)
end

fun ref seek_end(offset: USize) =>
"""
Set the cursor position relative to the end of the file.
"""
if path.caps(FileSeek) then


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

Parameters¶

y: I64 val

Returns¶

I64 val

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

Parameters¶


I64 val

ilong_unsafe¶
fun box ilong_unsafe()
: ILong val

Returns¶

ILong val

isize_unsafe¶
fun box isize_unsafe()
: ISize val

Returns¶

ISize val


if group_read then m = m or 0x20 end
if group_write then m = m or 0x10 end
if group_exec then m = m or 0x8 end
if any_read then m = m or 0x4 end
if any_write then m = m or 0x2 end
if any_exec then m = m or 0x1 end
end
m


"""
let s = recover String(path.size()) end
let vol = volume(path)
s.append(vol)

var state: _PathState = _PathOther
var i = vol.size()
var backtrack = ISize(-1)
let n = path.size()

try
var c = path(i)?

if is_sep(c) then
s.append(sep())
i = i + 1
state = _PathSep
elseif c == '.' then
i = i + 1
state = _PathDot


_SignedCheckedArithmetic.mod_checked[ISize, USize](this, y)

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

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

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

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

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

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


"""
Assert that the 2 given expressions resolve to different instances.
"""
_check_isnt[A]("isn't", consume not_expect, consume actual, msg, loc)

fun _check_isnt[A](
check: String,
not_expect: A,
actual: A,
msg: String,
loc: SourceLoc)
: Bool
=>
"""
Check that the 2 given expressions resolve to different instances.
"""
if not_expect is actual then
fail(_format_loc(loc) + "Assert " + check + " failed. " + msg
+ " Expected (" + (digestof not_expect).string() + ") isnt ("
+ (digestof actual).string() + ")")


y: USize val

Returns¶

USize val

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

Returns¶

USize val

eq¶
[Source]


Constructors¶
create¶
[Source]
new ref create(
seq: Seq[T] ref)
: Poperator[T] ref^

Parameters¶

seq: Seq[T] ref

Returns¶

Poperator[T] ref^

empty¶
[Source]
new ref empty()
: Poperator[T] ref^


fun box mcast_exclude()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mcast_join_group¶
[Source]


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

Parameters¶

y: U16 val

Returns¶

U16 val ?

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

Parameters¶


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.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let folded = my_list.fold[String]( {(str: String, s: String): String => str + s }, "z")  // "zabc"
```
"""
let h = try
head()?
else
return acc
end

_fold[B](h, f, consume acc)

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


FileLink¶
[Source]
primitive val FileLink

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

Returns¶

FileLink val^


"""
Write the bytes and a newline without explicitly flushing.
"""
@pony_os_std_print(_stream, data.cpointer(), data.size())


_start_next_read()

new ip4(
auth: UDPAuth,
notify: UDPNotify iso,
host: String = "",
service: String = "0",
size: USize = 1024)
=>
"""
Listens for IPv4 datagrams.
"""
_notify = consume notify
_event =
@pony_os_listen_udp4(this, host.cstring(), service.cstring())
_fd = @pony_asio_event_fd(_event)
@pony_os_sockname(_fd, _ip)
_packet_size = size
_read_buf = recover Array[U8] .> undefined(size) end
_notify_listening()


Zip three iterators together so that each call to next() results in
a tuple with the next value of the first iterator, the next value
of the second iterator, and the value of the third iterator. The
number of items returned is the minimum of the number of items
returned by the three iterators.
fun ref zip2[B: B, C: C](
i2: Iterator[B] ref,
i3: Iterator[C] ref)
: Iter[(A , B , C)] ref^

Parameters¶

i2: Iterator[B] ref
i3: Iterator[C] ref

Returns¶

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


"""
Print some bytes and insert a newline afterwards.
"""
_print(data)

be write(data: ByteSeq) =>
"""
Print some bytes without inserting a newline afterwards.
"""
_write(data)

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

be writev(data: ByteSeqIter) =>


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¶


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


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

Parameters¶

data: U128 val

Returns¶

None val

i128_le¶
[Source]
Write an I128 to the buffer in little-endian byte order.
fun ref i128_le(


option: U32 val

Returns¶

U32 val

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

Returns¶

(U32 val , U32 val)

get_so_rcvbuf¶
[Source]


_stdout.dispose()
end
| _stderr.event =>
if AsioEvent.readable(flags) then
_pending_reads(_stderr)
elseif AsioEvent.disposable(flags) then
_stderr.dispose()
end
| _err.event =>
if AsioEvent.readable(flags) then
_pending_reads(_err)
elseif AsioEvent.disposable(flags) then
_err.dispose()
end
end
_try_shutdown()

be timer_notify() =>
"""
Windows IO polling timer has fired


else
(this << y') or (this >> (bitwidth() - y'))
end

fun rotr(y: A): A =>
let y' = y % bitwidth()
if y' == y'.min_value() then
this._value()
else
(this >> y') or (this << (bitwidth() - y'))
end

fun popcount(): A
fun clz(): A
fun ctz(): A

fun clz_unsafe(): A
"""
Count leading zeroes.


fun encode[A: Seq[U8] iso = String iso](
data: ReadSeq[U8],
at62: U8 = '+',
at63: U8 = '/',
pad: U8 = '=',
linelen: USize = 0,
linesep: String = "\r\n")
: A^
=>
"""
Configurable encoding. The defaults are for RFC 4648.
"""
let len = ((data.size() + 2) / 3) * 4
let out = recover A(len) end
let lineblocks = linelen / 4

var srclen = data.size()
var blocks = USize(0)
var i = USize(0)


A

sub_unsafe¶
[Source]
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 box sub_unsafe(
y: A)
: A

Parameters¶

y: A

Returns¶

A


InputStream¶
[Source]
Asynchronous access to some input stream.
interface tag InputStream

Public Behaviours¶
apply¶
[Source]
Set the notifier. Optionally, also sets the chunk size, dictating the
maximum number of bytes of each chunk that will be passed to the notifier.
be apply(
notify: (InputNotify iso | None val),
chunk_size: USize val = 32)


fun box sctp_default_sndinfo()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_del_vrf_id¶
[Source]


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

Returns¶

ULong val

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

Returns¶

USize val


fun sctp_selective_ack():I32 => @pony_os_sockopt_option(I32(762))
fun sctp_set_debug_level():I32 => @pony_os_sockopt_option(I32(763))
fun sctp_set_dynamic_primary():I32 => @pony_os_sockopt_option(I32(764))
fun sctp_set_initial_dbg_seq():I32 => @pony_os_sockopt_option(I32(765))
fun sctp_set_peer_primary_addr():I32 => @pony_os_sockopt_option(I32(766))
fun sctp_shutdown():I32 => @pony_os_sockopt_option(I32(767))
fun sctp_shutdown_ack():I32 => @pony_os_sockopt_option(I32(768))
fun sctp_shutdown_ack_sent():I32 => @pony_os_sockopt_option(I32(769))
fun sctp_shutdown_complete():I32 => @pony_os_sockopt_option(I32(770))
fun sctp_shutdown_pending():I32 => @pony_os_sockopt_option(I32(771))
fun sctp_shutdown_received():I32 => @pony_os_sockopt_option(I32(772))
fun sctp_shutdown_sent():I32 => @pony_os_sockopt_option(I32(773))
fun sctp_smallest_pmtu():I32 => @pony_os_sockopt_option(I32(774))
fun sctp_ss_default():I32 => @pony_os_sockopt_option(I32(775))
fun sctp_ss_fair_bandwith():I32 => @pony_os_sockopt_option(I32(776))
fun sctp_ss_first_come():I32 => @pony_os_sockopt_option(I32(777))
fun sctp_ss_priority():I32 => @pony_os_sockopt_option(I32(778))
fun sctp_ss_round_robin():I32 => @pony_os_sockopt_option(I32(779))
fun sctp_ss_round_robin_packet():I32 => @pony_os_sockopt_option(I32(780))
fun sctp_ss_value():I32 => @pony_os_sockopt_option(I32(781))


Bool val


fun box ipproto_xtp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sol_ax25¶
[Source]


fun ref set_so_sndbuf(bufsize: U32): U32 =>
"""
Wrapper for the FFI call `setsockopt(fd, SOL_SOCKET, SO_SNDBUF, ...)`
"""
_OSSocket.set_so_sndbuf(_fd, bufsize)

fun ref set_tcp_nodelay(state: Bool): U32 =>
"""
Wrapper for the FFI call `setsockopt(fd, SOL_SOCKET, TCP_NODELAY, ...)`
"""
var word: Array[U8] ref =
_OSSocket.u32_to_bytes4(if state then 1 else 0 end)
_OSSocket.setsockopt(_fd, OSSockOpt.sol_socket(), OSSockOpt.tcp_nodelay(), word)


Flags[A: Flag[B] val, optional B: ((U8 val | U16 val | U32 val | U64 val | U128 val | ULong val | USize val) & Integer[B] val)]¶
[Source]
Flags is a set of flags. The flags that are recognised should be passed as
a union type for type parameter A. For example:
primitive SSE
fun value(): U64 => 1
primitive AVX
fun value(): U64 => 2
primitive RDTSCP
fun value(): U64 => 4
type Features is Flags[(SSE | AVX | RDTSCP)]
Type parameter B is the underlying field used to store the flags.
class ref Flags[A: Flag[B] val, optional B: ((U8 val | U16 val | U32 val |


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


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


# Lexicon

Words are hard. We can all be saying the same thing but do we _mean_ the same thing? It's tough to know. Hopefully, this lexicon helps a little.


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


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

Parameters¶

y: U16 val

Returns¶

Bool val

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

Parameters¶


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

Parameters¶

auth: ApplyReleaseBackpressureAuth val

Returns¶

None val

release¶
[Source]


"""
(flags and (1 << 0)) != 0

fun writeable(flags: U32): Bool =>
"""
Returns true if the flags contain the writeable flag.
"""
(flags and (1 << 1)) != 0

fun disposable(flags: U32): Bool =>
"""
Returns true if the event should be disposed of.
"""
flags == 0

fun oneshotable(flags: U32): Bool =>
"""
Returns true if the flags contain the oneshot flag.
"""
(flags and (1 << 8)) != 0


fun clone(): List[this->A!]^ =>
"""
Clone all elements into a new List.

Note: elements are not copied, an additional reference to each element is created in the new List.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = my_list.clone()  // my_list is ["a"; "b"; "c"], other_list is ["a"; "b"; "c"]
```
"""
let out = List[this->A!]

for v in values() do
out.push(v)
end
out

fun map[B](f: {(this->A!): B^} box): List[B]^ =>
"""


USize val

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

Returns¶

ISize val

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

Returns¶


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

Returns¶

U32 val

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

Parameters¶


312
313
314
315type Set[A: (Hashable #read & Equatable[A] #read)] is HashSet[A, HashEq[A]]

type SetIs[A] is HashSet[A, HashIs[A!]]

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

new create(prealloc: USize = 8) =>
"""
Defaults to a prealloc of 8.
"""
_map = _map.create(prealloc)


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


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


Returns¶

U32 val

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

Returns¶

U32 val

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


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


new e() => 2.71828182845904523536

new _nan() => compile_intrinsic
new _inf(negative: Bool) => compile_intrinsic

new from_bits(i: U32) => compile_intrinsic
fun bits(): U32 => compile_intrinsic
new from[B: (Number & Real[B] val)](a: B) => a.f32()

new min_value() =>
"""
Minimum negative value representable.
"""
from_bits(0xFF7FFFFF)

new max_value() =>
"""
Maximum positive value representable.
"""
from_bits(0x7F7FFFFF)


_idx = max

fun has_next(): Bool =>
(_idx >= _min) and (_idx <= _max)

fun ref next(): A =>
if has_next() then
_idx = _idx - _dec
else
_idx + _dec
end

fun ref rewind() =>
_idx = _max


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


fun box ipproto_routing()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_rvd¶
[Source]


FloatingPoint[A: FloatingPoint[A] val]¶
[Source]
trait val FloatingPoint[A: FloatingPoint[A] val] is
Real[A] val

Implements¶

Real[A] val

Constructors¶
min_normalised¶
[Source]


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


if expect.size() != actual.size() then
ok = false
else
try
var i: USize = 0
while i < expect.size() do
if expect(i)? != actual(i)? then
ok = false
break
end

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

if not ok then


y: I16 val

Returns¶

I16 val ?

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

Parameters¶

y: I16 val

Returns¶


var y = "Hello"

var z: String
z = "Hello"
```

__Can I miss out both the type and initial value for a variable?__ No. The compiler will complain that it can't figure out a type for that variable.

All local variable names start with a lowercase letter. If you want to you can end them with a _prime_ `'` (or more than one) which is useful when you need a second variable with almost the same meaning as the first. For example, you might have one variable called `time` and another called `time'`.

The chunk of code that a variable lives in is known as its __scope__. Exactly what its scope is depends on where it is defined. For example, the scope of a variable defined within the `then` expression of an `if` statement is that `then` expression. We haven't looked at `if` statements yet, but they're very similar to every other language.

```pony
if a > b then
var x = "a is bigger"
env.out.print(x)  // OK
end

env.out.print(x)  // Illegal


Returns¶

None val

before_iteration¶
[Source]
fun ref before_iteration(
c: AsyncBenchContinue val)
: None val

Parameters¶

c: AsyncBenchContinue val

Returns¶

None val


fun repeat_str(num: USize = 1, sep: String = ""): String iso^ =>
"""
Returns a copy of the string repeated `num` times with an optional
separator added inbetween repeats.
"""
var c = num
var str = recover String((_size + sep.size()) * c) end

while c > 0 do
c = c - 1
str = (consume str)._append(this)
if (sep.size() > 0) and (c != 0) then
str = (consume str)._append(sep)
end
end

consume str

fun mul(num: USize): String iso^ =>
"""


Constructors¶
create¶
[Source]
new val create(
code: I32 val)
: Exited val^

Parameters¶

code: I32 val

Returns¶

Exited val^

Public Functions¶
exit_code¶
[Source]
Retrieve the exit code of the exited process.


@ftruncate64(_fd, len.i64())
else
@ftruncate(_fd, len.i64())
end
end

if pos >= len then
_seek(0, 2)
end

if result == 0 then
true
else
_errno = _get_error()
false
end
else
false
end


our Pony program that prevents them from sending. There's no way for the Pony
runtime to detect this, so intervention by the programmer is needed.
TCPConnection is a single example. This Backpressure package exists to allow
a programmer to indicate to the runtime that a given actor is experiencing
pressure and sending messages to it should be adjusted accordingly.
Any actor that needs to be able to tell the runtime to "send me messages
slower" due to external conditions can do so via this package. Additionally,
actors that maintain their own internal queues of any sort, say for buffering,
are also prime candidates for using this package. If an actor's internal
queue grows too large, it can call Backpressure.apply to let the runtime know
it is under pressure.
Example program¶
// Here we have a TCPConnectionNotify that upon construction
// is given a ApplyReleaseBackpressureAuth token. This allows the notifier
// to inform the Pony runtime when to apply and release backpressure
// as the connection experiences it.
// Note the calls to
//
// Backpressure.apply(_auth)
// Backpressure.release(_auth)


class ref CommandSpec

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

Parameters¶

name': String val
descr': String val = ""
options': Array[OptionSpec val] box = call
commands': Array[CommandSpec ref] box = call


fun box sctp_pcb_flags_stream_resetevnt()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_udptype¶
[Source]


[Source]
Return the equivalent canonical absolute path. Raise an error if there
isn't one.
fun box canonical(
path: String val)
: String val ?

Parameters¶

path: String val

Returns¶

String val ?

is_list_sep¶
[Source]
Determine if a byte is a path list separator.
fun box is_list_sep(


# How does this work?

Inside the `recover` expression, your code only has access to __sendable__ values from the enclosing lexical scope. In other words, you can only use `iso`, `val` and `tag` things from outside the `recover` expression.

This means that when the `recover` expression finishes, any aliases to the result of the expression other than `iso`, `val` and `tag` ones won't exist anymore. That makes it safe to "lift" the reference capability of the result of the expression.

If the `recover` expression could access __non-sendable__ values from the enclosing lexical scope, "lifting" the reference capability of the result wouldn't be safe. Some of those values could "leak" into an `iso` or `val` result, and result in data races.


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


end
(let host', let service') = _notify.proxy_via(host, service)
_connect_count =
@pony_os_connect_tcp6(this, host'.cstring(), service'.cstring(),
from.cstring(), asio_flags)
_notify_connecting()

new _accept(
listen: TCPListener,
notify: TCPConnectionNotify iso,
fd: U32,
read_buffer_size: USize = 16384,
yield_after_reading: USize = 16384,
yield_after_writing: USize = 16384)
=>
"""
A new connection accepted on a server.
"""
_listen = listen
_notify = consume notify


fun sctp_status():I32 => @pony_os_sockopt_option(I32(782))
fun sctp_stream_reset():I32 => @pony_os_sockopt_option(I32(783))
fun sctp_stream_reset_incoming():I32 => @pony_os_sockopt_option(I32(784))
fun sctp_stream_reset_outgoing():I32 => @pony_os_sockopt_option(I32(785))
fun sctp_str_logging_enable():I32 => @pony_os_sockopt_option(I32(786))
fun sctp_threshold_logging():I32 => @pony_os_sockopt_option(I32(787))
fun sctp_timeouts():I32 => @pony_os_sockopt_option(I32(788))
fun sctp_use_ext_rcvinfo():I32 => @pony_os_sockopt_option(I32(789))
fun sctp_vrf_id():I32 => @pony_os_sockopt_option(I32(790))
fun sctp_wake_logging_enable():I32 => @pony_os_sockopt_option(I32(791))
fun sock_cloexec():I32 => @pony_os_sockopt_option(I32(792))
fun sock_dgram():I32 => @pony_os_sockopt_option(I32(793))
fun sock_maxaddrlen():I32 => @pony_os_sockopt_option(I32(794))
fun sock_nonblock():I32 => @pony_os_sockopt_option(I32(795))
fun sock_raw():I32 => @pony_os_sockopt_option(I32(796))
fun sock_rdm():I32 => @pony_os_sockopt_option(I32(797))
fun sock_seqpacket():I32 => @pony_os_sockopt_option(I32(798))
fun sock_stream():I32 => @pony_os_sockopt_option(I32(799))
fun somaxconn():I32 => @pony_os_sockopt_option(I32(800))
fun sonpx_setoptshut():I32 => @pony_os_sockopt_option(I32(801))


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

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

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

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

Behavior is undefined if `min` > `max`.


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


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


HashEq64[A: (Hashable64 #read & Equatable[A] #read)]¶
[Source]
primitive val HashEq64[A: (Hashable64 #read & Equatable[A] #read)] is
HashFunction64[A] val

Implements¶

HashFunction64[A] val

Constructors¶
create¶
[Source]


fun value_of(s: String): _Value ? => s.u64()?

primitive _F64Type is _ValueType
fun string(): String => "F64"
fun value_of(s: String): _Value ? => s.f64()?

primitive _StringSeqType is _ValueType
fun string(): String => "ReadSeq[String]"
fun value_of(s: String): _Value => _StringSeq.from_string(s)
fun is_seq(): Bool => true
fun append(v1: _Value, v2: _Value): _Value =>
"""
When is_seq() returns true, append() is called during parsing to append
a new parsed value onto an existing value.
"""
try
_StringSeq.from_concat(v1 as _StringSeq val, v2 as _StringSeq val)
else
v1
end


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

Parameters¶

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

Returns¶

None val

filter¶
[Source]
Builds a new list with those elements that satisfy a provided predicate.
fun val filter(
f: {(val->A): Bool}[A] box)
: (Cons[A] val | Nil[A] val)

Parameters¶


ILong val

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

Parameters¶

y: ILong val

Returns¶

ILong val

fld_unsafe¶


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


| -------------- | ----------------------------------------------------------------------------------------- |
| `addc()`         | Checked addition, second tuple element is `true` on overflow/underflow.                   |
| `subc()`         | Checked subtraction, second tuple element is `true` on overflow/underflow.                |
| `mulc()`         | Checked multiplication, second tuple element is `true` on overflow.                       |
| `divc()`         | Checked division, second tuple element is `true` on overflow or division by zero.         |
| `remc()`         | Checked remainder, second tuple element is `true` on overflow or division by zero.        |
| `modc()`         | Checked modulo, second tuple element is `true` on overflow or division by zero.           |
| `fldc()`         | Checked floored division, second tuple element is `true` on overflow or division by zero. |

---


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


Not biased with small values of `n` like `int`.
"""
N.from[U64](_u64_unbiased(U64.from[N](n)))

fun ref _u64_unbiased(range: U64): U64 =>
"""
Generates a U64 in the range `[0, n)`
while avoiding bias.

See:
- https://arxiv.org/abs/1805.10941
- http://www.pcg-random.org/posts/bounded-rands.html
"""
var x: U64 = next()
var m: U128 = x.u128() * range.u128()
var l: U64 = m.u64()
if l < range then
var t: U64 = -range
if t >= range then


fun box ipv6_priority_control()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_priority_interactive¶
[Source]


None val ?

keys¶
[Source]
Return an iterator over the indices in the array.
fun box keys()
: ArrayKeys[A, this->Array[A] ref] ref^

Returns¶

ArrayKeys[A, this->Array[A] ref] ref^

values¶
[Source]
Return an iterator over the values in the array.
fun box values()
: ArrayValues[A, this->Array[A] ref] ref^


fun box sctp_pcb_flags_assoc_resetevnt()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_autoclose¶
[Source]


fun ref set_hunger(to: U64 = 0): U64 => _hunger_level = to
```

The first function, `hunger`, is pretty straight forward. It has a result type of `U64`, and it returns `_hunger_level`, which is a `U64`. The only thing a bit different here is that no `return` keyword is used. This is because the result of a function is the result of the last expression in the function, in this case, the value of `_hunger_level`.

__Is there a `return` keyword in Pony?__ Yes. It's used to return "early" from a function, i.e. to return something right away and not keep running until the last expression.

The second function, `set_hunger`, introduces a _bunch_ of new concepts all at once. Let's go through them one by one.

* The `ref` keyword right after `fun`

This is a __reference capability__. In this case, it means the _receiver_, i.e. the object on which the `set_hunger` function is being called, has to be a `ref` type. A `ref` type is a __reference type__, meaning that the object is __mutable__. We need this because we are writing a new value to the `_hunger_level` field.

__What's the receiver reference capability of the `hunger` method?__ The default receiver reference capability if none is specified is `box`, which means "I need to be able to read from this, but I won't write to it".

__What would happen if we left the `ref` keyword off the `set_hunger` method?__ The compiler would give you an error. It would see you were trying to modify a field and complain about it.

* The `= 0` after the parameter `to`

This is a __default argument__. It means that if you don't include that argument at the call site, you will get the default argument. In this case, `to` will be zero if you don't specify it.


that: HashSet[A, H] box)
: Bool val

Parameters¶

that: HashSet[A, H] box

Returns¶

Bool val

values¶
[Source]
Return an iterator over the values in the set.
fun box values()
: Iterator[A] ref^

Returns¶


align. Specify whether fill characters should be added at the beginning or
end of the generated string, or both.
fill. The character to pad a string with if is is shorter than width.

primitive val Format

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

Returns¶

Format val^

Public Functions¶
apply¶
[Source]


y: A

Returns¶

(A , Bool val)

modc¶
[Source]
Calculate the modulo of this number after floored division by y and return the result and a flag indicating division by zero or overflow.
The result will have the sign of the divisor.
fun box modc(
y: A)
: (A , Bool val)

Parameters¶

y: A


CommonPrefix val^

Public Functions¶
apply¶
[Source]
fun box apply(
data: ReadSeq[Stringable box] box)
: String iso^

Parameters¶

data: ReadSeq[Stringable box] box

Returns¶

String iso^


is set, the path is made readable, and if any write flag is set, the path
is made writeable.
"""
var m: U32 = 0

ifdef windows then
if owner_read or group_read or any_read then
m = m or 0x100
end

if owner_write or group_write or any_write then
m = m or 0x80
end
else
if setuid then m = m or 0x800 end
if setgid then m = m or 0x400 end
if sticky then m = m or 0x200 end
if owner_read then m = m or 0x100 end
if owner_write then m = m or 0x80 end
if owner_exec then m = m or 0x40 end


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

ifdef linux or bsd then
0 == @renameat(_fd, source.cstring(), to._fd, target.cstring())
else
path'.rename(path'')
end
else
false
end

fun ref dispose() =>
"""
Close the directory.
"""
if _fd != -1 then
ifdef posix then
@close(_fd)
end


that: box->A

Returns¶

Bool val

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

Parameters¶

that: box->A

Returns¶

Bool val


include <stdint.h>

// A fast, minimal memory, consistent hash algorithm
// https://arxiv.org/abs/1406.2294
int32_t jch_chash(uint64_t key, uint32_t num_buckets)
{
int b = -1;
uint64_t j = 0;

do {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * ((double)(1LL << 31) / ((double)(key >> 33) + 1));
} while(j < num_buckets);

return (int32_t)b;
}
```

We need to compile the native code to a shared library. This example is for MacOS. The exact details may vary on other platforms.


fun box dso_max()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

dso_nodelay¶
[Source]


value: A)
: A^ ?

Parameters¶

i: USize val
value: A

Returns¶

A^ ?

clear¶
[Source]
Removes all elements from the sequence.
fun ref clear()
: None val

Returns¶


String val

params¶
fun box params()
: PropertyParams val

Returns¶

PropertyParams val


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


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


var _env: Env

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

let bucket_size: U32 = 1000000

_env.out.print("C implementation:")
for i in Range[U64](1, 20) do
let hash = @jch_chash(i, bucket_size)
_env.out.print(i.string() + ": " + hash.string())
end

_env.out.print("Pony implementation:")
for i in Range[U64](1, 20) do
let hash = jch(i, bucket_size)
_env.out.print(i.string() + ": " + hash.string())
end

fun jch(key: U64, buckets: U32): I32 =>


Returns¶

Bool val

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

Parameters¶

y: F64 val

Returns¶

Bool val


fun bytewidth(): USize

fun string(): String iso^ =>
_ToString._u64(abs().u64(), i64() < 0)

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

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

// both fld and mod behave the same as div and rem for unsigned integers
fun fld(y: A): A => this / y
fun fldc(y: A): (A, Bool) => this.divc(y)
fun fld_partial(y: A): A ? => this.div_partial(y)?
fun fld_unsafe(y: A): A => this.div_unsafe(y)

fun mod(y: A): A => this % y
fun modc(y: A): (A, Bool) => this.remc(y)
fun mod_partial(y: A): A ? => this.rem_partial(y)?


var ponyprintstatsinterval: U32 val¶
[Source]
Print actor stats before an actor is destroyed and print scheduler stats
every X seconds. Defaults to -1 (never).

var ponyversion: Bool val¶
[Source]
Print the version of the compiler and exit.

var ponyhelp: Bool val¶
[Source]
Print the runtime usage options and exit.


new val create()
: Equal val^

Returns¶

Equal val^

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

Returns¶

String iso^

eq¶


### Example
```pony
Iter[USize](Range(0, 3))
.intersperse(8)
```
`0 8 1 8 2`
"""
Iter[A!](
object is Iterator[A!]
var _count: USize = 0
let _v: A = consume value

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

fun ref next(): A! ? =>
if (_count == n) then
_count = 0
_v
else


I64 val

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

Parameters¶

y: I64 val

Returns¶

I64 val

mul¶
[Source]


1 2 3
fun ref take(
n: USize val)
: Iter[A] ref^

Parameters¶

n: USize val

Returns¶

Iter[A] ref^

take_while¶
[Source]
Return an iterator that returns values while the predicate f returns
true. This iterator short-circuits the first time that f returns false or
raises an error.
Example¶


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


Real[A] val^

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

Returns¶

Real[A] val^

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

Returns¶


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


fun box f64()
: F64 val

Returns¶

F64 val

i8_unsafe¶
fun box i8_unsafe()
: I8 val

Returns¶

I8 val

i16_unsafe¶
fun box i16_unsafe()
: I16 val


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


Generate a random value from the given ReadSeq.
This generator will generate nothing if the given xs is empty.
Generators created with this method do not support shrinking.
If do_shrink is set to true, it will return the same value
for each shrink round. Otherwise it will return nothing.
fun box one_of[T: T](
xs: ReadSeq[T] box,
do_shrink: Bool val = false)
: Generator[box->T] box

Parameters¶

xs: ReadSeq[T] box
do_shrink: Bool val = false

Returns¶

Generator[box->T] box


path: String val

Returns¶

Bool val

join¶
[Source]
Join two paths together. If the next_path is absolute, simply return it.
The returned path will be cleaned.
fun box join(
path: String val,
next_path: String val)
: String val

Parameters¶

path: String val


fun box so_bintime()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_broadcast¶
[Source]


U16 val

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

Returns¶

U32 val

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

Returns¶


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


Returns¶

Bool val


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

As an alternative Pony provides the `elseif` keyword that combines an `else` and an `if`. This works the same as saying `else if` in other languages and you can have as many `elseif`s as you like for each `if`.

```pony
if a == b then
env.out.print("they are the same")
elseif a > b then
env.out.print("a is bigger")
else
env.out.print("b bigger")
end
```


fun box sctp_cause_no_user_data()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cause_protocol_violation¶
[Source]


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

Returns¶

A

sqrt_unsafe¶
[Source]
Unsafe operation.
If this is negative, the result is undefined.
fun box sqrt_unsafe()
: A

Returns¶


If neither stdout nor stderr are open we close down and exit.
"""
if _stdin.is_closed() and
_stdout.is_closed() and
_stderr.is_closed()
then
_close()
end

fun ref _pending_reads(pipe: _Pipe) =>
"""
Read from stdout or stderr while data is available. If we read 4 kb of
data, send ourself a resume message and stop reading, to avoid starving
other actors.
It's safe to use the same buffer for stdout and stderr because of
causal messaging. Events get processed one _after_ another.
"""
if pipe.is_closed() then return end
var sum: USize = 0
while true do


"""
ifdef freebsd or "capsicum" then
@cap_rights_contains(addressof _r0, addressof that._r0)
else
true
end

fun _version(): I32 => 0


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


Parameters¶

y: ISize val

Returns¶

Bool val

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

Parameters¶

y: ISize val

Returns¶


fun box netlink_rdma()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netlink_rx_ring¶
[Source]


generators' output and verifies a custom property with the help of a
[PropertyHelper](pony_check-PropertyHelper.md).

A property is verified if no failed assertion on
[PropertyHelper](pony_check-PropertyHelper.md) has been
reported for all the samples it consumed.

The property execution can be customized by returning a custom
[PropertyParams](pony_check-PropertyParams.md) from the
[`params()`](pony_check-Property1.md#params) method.

The [`gen()`](pony_check-Property1.md#gen) method is called exactly once to
instantiate the generator.
The generator produces
[PropertyParams.num_samples](pony_check-PropertyParams.md#num_samples)
samples and each is passed to the
[property](pony_check-Property1.md#property) method for verification.

If the property did not verify, the given sample is shrunken if the
generator supports shrinking.


This is useful for getting the [root authority](builtin-AmbientAuth.md) in
order to access the filesystem (See [files](files--index.md)) or the network
(See [net](net--index.md)) in your tests.
"""

new val _create(runner: _TestRunner, env': Env) =>
"""
Create a new TestHelper.
"""
env = env'
_runner = runner

fun log(msg: String, verbose: Bool = false) =>
"""
Log the given message.

The verbose parameter allows messages to be printed only when the --verbose
command line option is used. For example, by default assert failures are
logged, but passes are not. With --verbose both passes and fails are
reported.


if y > 0 then
(this > (max_value() - y))
else
(this < (min_value() - y))
end

(this + y, overflow)
end

fun subc(y: I128): (I128, Bool) =>
ifdef native128 then
@"llvm.ssub.with.overflow.i128"(this, y)
else
let overflow =
if y > 0 then
(this < (min_value() + y))
else
(this > (max_value() + y))
end


let r =
ifdef bigendian then
data.read_u32(offset)?
else
data.read_u32(offset)?.bswap()
end

offset = offset + num_bytes
_available = _available - num_bytes

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


Return an iterator over the keys and values.
fun box pairs()
: MapPairs[K, V, H, this->HashMap[K, V, H] ref] ref^

Returns¶

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


Returns¶

Bool val

nan¶
[Source]
Check whether this number is NaN.
fun box nan()
: Bool val

Returns¶

Bool val

ldexp¶
[Source]
fun box ldexp(
x: F64 val,


fun box sctp_max_sack_delay()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_mbuf_logging_enable¶
[Source]


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


U128 val

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

Parameters¶

y: U128 val

Returns¶

U128 val

fld¶
[Source]


Parameters¶

y: F32 val

Returns¶

F32 val

neg¶
fun box neg()
: F32 val

Returns¶

F32 val

eq¶
fun box eq(


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


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


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


TCPConnectAuth¶
[Source]
primitive val TCPConnectAuth

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

Parameters¶


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

Parameters¶

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

Returns¶

None val


fun box so_rxq_ovfl()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_sco_mtu¶
[Source]


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

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


USize val

space¶
[Source]
The available space in the map. Resize will happen when
size / space >= 0.75.
fun box space()
: USize val

Returns¶

USize val

apply¶
[Source]
Gets a value from the map. Raises an error if no such item exists.
fun box apply(


fun box mrt_del_vif()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

mrt_init¶
[Source]


apply¶
[Source]
Return the value if it is in the set, otherwise raise an error.
fun box apply(
value: val->A)
: val->A ?

Parameters¶

value: val->A

Returns¶

val->A ?

contains¶
[Source]


fun box u32_unsafe()
: U32 val

Returns¶

U32 val

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

Returns¶

U64 val

u128_unsafe¶
[Source]


fun box u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶
[Source]


fun box sctp_pcb_flags_socket_gone()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_stream_resetevnt¶
[Source]


fun box sctp_pcb_flags_recvdataioevnt()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_pcb_flags_recvnxtinfo¶
[Source]


Parameters¶

y: ISize val

Returns¶

ISize val ?

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

Parameters¶

y: ISize val

Returns¶


is out of bounds.
fun box apply(
i: USize val)
: this->A ?

Parameters¶

i: USize val

Returns¶

this->A ?

update¶
[Source]
Replaces the i-th element of the sequence. Returns the previous value.
Raises an error if the index is out of bounds.
fun ref update(
i: USize val,


A

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

Parameters¶

y: A

Returns¶

A

op_xor¶


var _x: U64
var _y: U64

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

new create(x: U64 = 5489, y: U64 = 0) =>
_x = x
_y = y
next()

fun ref next(): U64 =>
let x = _x
var y = _y


| `ilong()`         | `ilong_unsafe()`    |
| `isize()`         | `isize_unsafe()`    |
| `f32()`           | `f32_unsafe()`      |
| `f64()`           | `f64_unsafe()`      |

---


y: I16 val

Returns¶

I16 val

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

Returns¶

I16 val

add¶
[Source]


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

Parameters¶

y: USize val

Returns¶

Bool val

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

Parameters¶


// interface towards PropertyHelper

be expect_action(name: String, round: _Round) =>
if round != this._current_round then
_logger.log("unexpected expect action \"" + name + "\" call for " + round.string() +
". Currently at " + this._current_round.string(), true)
return
end
_logger.log("Action expected: " + name)
_expected_actions.set(name)

be complete_action(name: String, round: _Round, ph: PropertyHelper) =>
if round != this._current_round then
_logger.log("unexpected complete action \"" + name + "\" msg for " + round.string() +
". Currently at " + this._current_round.string(), true)
return
end
_logger.log("Action completed: " + name)
_finish_action(name, true, round, ph)


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


Choose a value of one of the given Generators,
while controlling the distribution with the associated weights.
The weights are of type USize and control how likely a value is chosen.
The likelihood of a value v to be chosen
is weight_v / weights_sum.
If all weighted_generators have equal size the distribution
will be uniform.
Example of a generator to output odd U8 values
twice as likely as even ones:
Generators.frequency[U8]([
(1, Generators.u8().filter({(u) => (u, (u % 2) == 0 }))
(2, Generators.u8().filter({(u) => (u, (u % 2) != 0 }))
])

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

Parameters¶


A^ ?

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

fun ref unshift(
a: A)
: None val

Parameters¶

a: A

Returns¶


compile_intrinsic

fun ref _insert(n: USize, len: USize): Pointer[A] =>
"""
Creates space for n new elements at the head, moving following elements.
The array length before this should be len, and the available space should
be at least n + len.
"""
compile_intrinsic

fun ref _delete(n: USize, len: USize): A^ =>
"""
Delete n elements from the head of pointer, compact remaining elements of
the underlying array. The array length before this should be n + len.
Returns the first deleted element.
"""
compile_intrinsic

fun _copy_to(that: Pointer[this->A!], n: USize): this->Pointer[A] =>
"""


fun box sctp_shutdown_complete()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_shutdown_received¶
[Source]


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


from: USize val = 0,
to: USize val = call)
: String val

Parameters¶

from: USize val = 0
to: USize val = call

Returns¶

String val

chop¶
[Source]
Chops the string in half at the split point requested and returns both
the left and right portions. The original string is trimmed in place and
returned as the left portion. If the split point is larger than the
string, the left portion is the original string and the right portion


U8 val

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

Returns¶

U16 val

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

Returns¶


len: USize val

Returns¶

Bool val

info¶
[Source]
Return a FileInfo for this directory. Raise an error if the fd is invalid
or if we don't have FileStat permission.
fun box info()
: FileInfo val ?

Returns¶

FileInfo val ?


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

Returns¶

Bool val

assert_error¶
[Source]
Assert that the given test function throws an error when run.
fun box assert_error(
test: ITest box,
msg: String val = "",
loc: SourceLoc val = __loc)
: Bool val

Parameters¶


552
553
554use "time"
use @pony_os_realpath[Pointer[U8] iso^](path: Pointer[U8] tag)
use @pony_os_cwd[Pointer[U8]]()

primitive _PathSep
primitive _PathDot
primitive _PathDot2
primitive _PathOther

type _PathState is (_PathSep | _PathDot | _PathDot2 | _PathOther)

primitive Path
"""
Operations on paths that do not require a capability. The operations can be
used to manipulate path names, but give no access to the resulting paths.
"""
fun is_sep(c: U8): Bool =>
"""


end

if
(s.size() == 0) or
(s.compare_sub("../", 3, backtrack) is Equal) or
ifdef windows then
s.compare_sub("..\\", 3, backtrack) is Equal
else
false
end
then
backtrack = -1
end
end
| _PathOther =>
s.append(sep())
end
state = _PathSep
elseif c == '.' then
match state


fun box tcp_max_winshift()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcp_md5sig_maxkeylen¶
[Source]


DNS val^

Public Functions¶
apply¶
[Source]
Gets all IPv4 and IPv6 addresses for a host and service.
fun box apply(
auth: DNSAuth val,
host: String val,
service: String val)
: Array[NetAddress val] iso^

Parameters¶

auth: DNSAuth val
host: String val
service: String val

Returns¶


"""
ifdef windows then
try
@pony_os_recvfrom(_event, _read_buf.cpointer(),
_read_buf.space(), _read_from) ?
else
_readable = false
_close()
end
end

fun ref _write(data: ByteSeq, to: NetAddress) =>
"""
Write the datagram to the socket.
"""
if not _closed then
try
@pony_os_sendto(_fd, data.cpointer(), data.size(), to) ?
else
_close()


fun box ilong()
: ILong val

Returns¶

ILong val

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

Returns¶

ISize val

u8¶
[Source]


fun box right(
n: U32 val = 0)
: String val

Parameters¶

n: U32 val = 0

Returns¶

String val

left¶
[Source]
Move the cursor left n columns. 0 is the same as 1.
fun box left(
n: U32 val = 0)
: String val


y: U32 val

Returns¶

U32 val

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

Returns¶

U32 val

eq¶
[Source]


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


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


If all expected actions are completed successfully,
the property is considered successful.

If 1 action fails, the property is considered failing.

Call `complete_action(name)` or `fail_action(name)`
to mark some action as completed.

Example:

```pony
actor AsyncActor

let _ph: PropertyHelper

new create(ph: PropertyHelper) =>
_ph = ph

be complete(s: String) =>


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

Returns¶

String iso^

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

Parameters¶


"""
Listen for a specific signal.
If the wait parameter is true, the program will not terminate until the SignalHandler's dispose method is called, or if the SignalNotify returns false, after handling the signal as this also disposes the SignalHandler and unsubscribes it.

"""
let _notify: SignalNotify
let _sig: U32
var _event: AsioEventID

new create(notify: SignalNotify iso, sig: U32, wait: Bool = false) =>
"""
Create a signal handler.
"""
_notify = consume notify
_sig = sig
_event =
@pony_asio_event_create(this, 0, AsioEvent.signal(), sig.u64(), wait)

be raise() =>
"""


fun box netrom_node()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

netrom_t1¶
[Source]


fun box sctp_rttvar_logging_enable()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_sack_logging_enable¶
[Source]


broadcast_ip6¶
[Source]
Link-local IP6 broadcast address.
fun box broadcast_ip6(
auth: DNSAuth val,
service: String val)
: Array[NetAddress val] iso^

Parameters¶

auth: DNSAuth val
service: String val

Returns¶

Array[NetAddress val] iso^


- an optional help option+command name for help parsing
- one of:
- a Map of child commands.
- an Array of arguments.
"""
let _type: _CommandSpecType
let _name: String
let _descr: String
let _options: Map[String, OptionSpec] = _options.create()
var _help_name: String = ""
var _help_info: String = ""

// A parent commands can have sub-commands; leaf commands can have args.
let _commands: Map[String, CommandSpec box] = _commands.create()
let _args: Array[ArgSpec] = _args.create()

new parent(
name': String,
descr': String = "",
options': Array[OptionSpec] box = Array[OptionSpec](),


I128 val ?

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

Parameters¶

y: I128 val

Returns¶

I128 val ?

shl¶
[Source]


fun ref ulong(
min: ULong val = call,
max: ULong val = call)
: ULong val

Parameters¶

min: ULong val = call
max: ULong val = call

Returns¶

ULong val

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


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


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


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


I64 val ?

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

Parameters¶

y: I64 val

Returns¶

I64 val ?

divrem_partial¶
[Source]


Device IDs consist of a major and minor device id,
denoting the type of device and the instance of this type on the system.
"""

let inode: U64 = 0
"""UNIX specific INODE number of `filepath`. Is 0 on Windows."""

let uid: U32 = 0
"""UNIX-style user ID of the owner of `filepath`."""

let gid: U32 = 0
"""UNIX-style user ID of the owning group of `filepath`."""

let size: USize = 0
"""
Total size of `filepath` in bytes.

In case of a symlink this is the size of the target, not the symlink itself.
"""


y: I32 val

Returns¶

Bool val

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

Parameters¶

y: I32 val

Returns¶


fun sctp_pcb_flags_socket_gone():I32 => @pony_os_sockopt_option(I32(722))
fun sctp_pcb_flags_stream_changeevnt():I32 => @pony_os_sockopt_option(I32(723))
fun sctp_pcb_flags_stream_resetevnt():I32 => @pony_os_sockopt_option(I32(724))
fun sctp_pcb_flags_tcptype():I32 => @pony_os_sockopt_option(I32(725))
fun sctp_pcb_flags_udptype():I32 => @pony_os_sockopt_option(I32(726))
fun sctp_pcb_flags_unbound():I32 => @pony_os_sockopt_option(I32(727))
fun sctp_pcb_flags_wakeinput():I32 => @pony_os_sockopt_option(I32(728))
fun sctp_pcb_flags_wakeoutput():I32 => @pony_os_sockopt_option(I32(729))
fun sctp_pcb_flags_was_aborted():I32 => @pony_os_sockopt_option(I32(730))
fun sctp_pcb_flags_was_connected():I32 => @pony_os_sockopt_option(I32(731))
fun sctp_pcb_flags_zero_copy_active():I32 => @pony_os_sockopt_option(I32(732))
fun sctp_pcb_status():I32 => @pony_os_sockopt_option(I32(733))
fun sctp_peeloff():I32 => @pony_os_sockopt_option(I32(734))
fun sctp_peer_addr_params():I32 => @pony_os_sockopt_option(I32(735))
fun sctp_peer_addr_thlds():I32 => @pony_os_sockopt_option(I32(736))
fun sctp_peer_auth_chunks():I32 => @pony_os_sockopt_option(I32(737))
fun sctp_pktdrop_supported():I32 => @pony_os_sockopt_option(I32(738))
fun sctp_pluggable_cc():I32 => @pony_os_sockopt_option(I32(739))
fun sctp_pluggable_ss():I32 => @pony_os_sockopt_option(I32(740))
fun sctp_primary_addr():I32 => @pony_os_sockopt_option(I32(741))


# Capabilities and concurrency

The object-capability model on its own does not address concurrency. It makes clear _what_ will happen if there is simultaneous access to an object, but it does not prescribe a single method of controlling this.

Combining capabilities with the actor-model is a good start, and has been done before in languages such as [E](http://erights.org/) and Joule.

Pony does this and also uses a system of _reference capabilities_ in the type system.


fun box ipproto_pigp()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipproto_prm¶
[Source]


count: U64 val,
sides: U64 val)
: U64 val

Parameters¶

count: U64 val
sides: U64 val

Returns¶

U64 val


A

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

Parameters¶

y: A

Returns¶

A

div¶
[Source]


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


Print an iterable collection of ByteSeqs.
be printv(
data: ByteSeqIter val)

Parameters¶

data: ByteSeqIter val

writev¶
[Source]
Write an iterable collection of ByteSeqs.
be writev(
data: ByteSeqIter val)

Parameters¶

data: ByteSeqIter val


"""
let letters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let s = recover String(len) end
var n = USize(0)
var r = Time.nanos().usize()

try
while n < len do
let c = letters(r % letters.size())?
r = r / letters.size()
s.push(c)
n = n + 1
end
end
s


[Source]
fun box shr(
y: B)
: A

Parameters¶

y: B

Returns¶

A

shl_unsafe¶
[Source]
Unsafe operation.
If bits differing from the final sign bit are shifted-out, the result is
undefined.
fun box shl_unsafe(


F64 val

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

Parameters¶

that: ILong val

Returns¶

(Less val | Equal val | Greater val)


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


"""
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 mul_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 div_unsafe(y: A): A =>
"""
Unsafe operation.


Parameters¶

file: File ref
min_read_size: USize val = 256

Returns¶

FileLines ref^

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

Returns¶

Bool val


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


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


# Integration with PonyTest

PonyCheck properties need to be executed. The test runner for PonyCheck is [PonyTest](https://stdlib.ponylang.io/pony_test--index). To integrate [`Property1`](https://stdlib.ponylang.io/pony_check-Property1) into [PonyTest](https://stdlib.ponylang.io/pony_test--index), `Property1` needs to be wrapped inside a [`Property1UnitTest`](hhttps://stdlib.ponylang.io/pony_check-Property1UnitTest) and passed to the PonyTest `apply` method as a regular PonyTest [`UnitTest`](https://stdlib.ponylang.io/pony_test-UnitTest):

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

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

fun tag tests(test: PonyTest) =>
test(Property1UnitTest[String](_MyFirstProperty))
```

It is also possible to integrate any number of properties directly into one
[`UnitTest`](https://stdlib.ponylang.io/pony_test-UnitTest) using the [`PonyCheck.for_all`](https://stdlib.ponylang.io/pony_check-PonyCheck) convenience function:

```pony


(_next = None) as A!
else error
end

fun ref _try_next(): Bool =>
if _done then false
elseif not _iter.has_next() then
_done = true
false
else
_next =
try _iter.next()?
else
_done = true
return false
end
_done = try not f(_next as A!)? else true end
not _done
end
end)


fun box u8()
: U8 val

Returns¶

U8 val

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

Returns¶

U16 val

u32¶
[Source]


i = i + 1
end
_size < that._size

fun le(that: String box): Bool =>
"""
Returns true if this is lexically less than or equal to that. Needs to be
made UTF-8 safe.
"""
let len = _size.min(that._size)
var i: USize = 0

while i < len do
if _ptr._apply(i) < that._ptr._apply(i) then
return true
elseif _ptr._apply(i) > that._ptr._apply(i) then
return false
end
i = i + 1
end


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

Returns¶

U32 val ?

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

Returns¶

I32 val ?


fun val partition(f: {(val->A): Bool} box): (List[A], List[A]) =>
"""
Builds a pair of lists, the first of which is made up of the elements
satisfying the supplied predicate and the second of which is made up of
those that do not.
"""
var hits: List[A] = Nil[A]
var misses: List[A] = Nil[A]
var cur: List[A] = this
while true do
match cur
| let cons: Cons[A] =>
let next = cons.head()
if f(next) then
hits = hits.prepend(next)
else
misses = misses.prepend(next)
end
cur = cons.tail()
else


"""
Hash the identity rather than the contents.
"""
(digestof x).hash()

fun hash64(x: box->A!): U64 =>
"""
Hash the identity rather than the contents.
"""
(digestof x).hash64()

fun eq(x: box->A!, y: box->A!): Bool =>
"""
Determine equality by identity rather than structurally.
"""
x is y

primitive HashByteSeq is
(HashFunction[ByteSeq box] & HashFunction64[ByteSeq box])
"""


ArrayKeys[A: A, B: Array[A] #read]¶
[Source]
class ref ArrayKeys[A: A, B: Array[A] #read] is
Iterator[USize val] ref

Implements¶

Iterator[USize val] ref

Constructors¶
create¶
[Source]


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

Parameters¶

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

Returns¶

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

take¶
[Source]
Builds a list of the first n elements.
fun val take(
n: USize val)
: (Cons[A] val | Nil[A] val)

Parameters¶


=>
"""
Append len elements from a sequence, starting from the given offset.

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

Does not remove elements from sequence.

```pony
let my_list = List[String].from(["a"; "b"; "c"])
let other_list = List[String].from(["d"; "e"; "f"])
my_list.append(other_list)  // my_list is ["a"; "b"; "c"; "d"; "e"; "f"], other_list is unchanged
```
"""
if offset >= seq.size() then
return
end

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


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


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


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

fun shrink(u: U32): ValueAndShrink[U32] =>
that._int_shrink[U32](consume u, min)
end)

fun u64(


As the returned value can also be `iso`, it needs to be consumed and
returned.

It is preferred to already return a `ValueAndShrink` from `generate`.
"""
_gen.shrink(consume t)

fun generate_value(rnd: Randomness): T^ ? =>
_gen.generate_value(rnd)?

fun generate_and_shrink(rnd: Randomness): ValueAndShrink[T] ? =>
_gen.generate_and_shrink(rnd)?

fun filter(predicate: {(T): (T^, Bool)} box): Generator[T] =>
"""
Apply `predicate` to the values generated by this Generator
and only yields values for which `predicate` returns `true`.

Example:


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109use "pony_test"

class ForAll[T]


fun ipproto_mux():I32 => @pony_os_sockopt_level(I32(4071))
fun ipproto_nd():I32 => @pony_os_sockopt_level(I32(4072))
fun ipproto_nhrp():I32 => @pony_os_sockopt_level(I32(4073))
fun ipproto_none():I32 => @pony_os_sockopt_level(I32(4074))
fun ipproto_nsp():I32 => @pony_os_sockopt_level(I32(4075))
fun ipproto_nvpii():I32 => @pony_os_sockopt_level(I32(4076))
fun ipproto_old_divert():I32 => @pony_os_sockopt_level(I32(4077))
fun ipproto_ospfigp():I32 => @pony_os_sockopt_level(I32(4078))
fun ipproto_pfsync():I32 => @pony_os_sockopt_level(I32(4079))
fun ipproto_pgm():I32 => @pony_os_sockopt_level(I32(4080))
fun ipproto_pigp():I32 => @pony_os_sockopt_level(I32(4081))
fun ipproto_pim():I32 => @pony_os_sockopt_level(I32(4082))
fun ipproto_prm():I32 => @pony_os_sockopt_level(I32(4083))
fun ipproto_pup():I32 => @pony_os_sockopt_level(I32(4084))
fun ipproto_pvp():I32 => @pony_os_sockopt_level(I32(4085))
fun ipproto_raw():I32 => @pony_os_sockopt_level(I32(4086))
fun ipproto_rccmon():I32 => @pony_os_sockopt_level(I32(4087))
fun ipproto_rdp():I32 => @pony_os_sockopt_level(I32(4088))
fun ipproto_reserved_253():I32 => @pony_os_sockopt_level(I32(4089))
fun ipproto_reserved_254():I32 => @pony_os_sockopt_level(I32(4090))


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

Parameters¶

y: USize val

Returns¶

(USize val , Bool val)

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

Parameters¶


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


file_mode.pony

1
2
3
4
5
6
7
8
9
10
11


: T^ ?

Returns¶

T^ ?


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


fun box rem_partial(
y: I128 val)
: I128 val ?

Parameters¶

y: I128 val

Returns¶

I128 val ?

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

Parameters¶


IniNotify¶
[Source]
Notifications for INI parsing.
interface ref IniNotify

Public Functions¶
apply¶
[Source]
This is called for every valid entry in the INI file. If key/value pairs
occur before a section name, the section can be an empty string. Return
false to halt processing.
fun ref apply(
section: String val,


_esc_buf.push(c)
| '[' =>
_escape = _EscapeCSI
_esc_buf.push(c)
else
_esc_flush()
end
| _EscapeSS3 =>
match c
| 'A' => _up()
| 'B' => _down()
| 'C' => _right()
| 'D' => _left()
| 'H' => _home()
| 'F' => _end()
| 'P' => _fn_key(1)
| 'Q' => _fn_key(2)
| 'R' => _fn_key(3)
| 'S' => _fn_key(4)
else


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


y: U128 val

Returns¶

(U128 val , Bool val)

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

Parameters¶

y: U128 val

Returns¶


be dispose() =>
"""
Stop listening.
"""
close()

fun local_address(): NetAddress =>
"""
Return the bound IP address.
"""
let ip = recover NetAddress end
@pony_os_sockname(_fd, ip)
ip

be _event_notify(event: AsioEventID, flags: U32, arg: U32) =>
"""
When we are readable, we accept new connections until none remain.
"""
if event isnt _event then


fun box signal()
: U32 val

Returns¶

U32 val

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

Returns¶

String iso^

eq¶
[Source]


fun box apply()
: this->A ?

Returns¶

this->A ?

update¶
[Source]
Replace the item and return the previous one. Raise an error if we have no
previous value.
fun ref update(
value: (A | None val))
: A^ ?

Parameters¶

value: (A | None val)


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

Parameters¶

value: U16 val

Returns¶

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


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


_out.print("Releasing backpressure!")
Backpressure.release(_auth)

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

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

Caveat¶
The runtime backpressure is a powerful system. By intervening, programmers can
create deadlocks. Any call to Backpressure.apply should be matched by a
corresponding call to Backpressure.release. Authorization via the
ApplyReleaseBackpressureAuth capability is required to apply or release
backpressure. By requiring that the caller have a token to apply or release a
backpressure, rouge 3rd party library code can't run wild and unknowingly
interfere with the runtime.


fun box so_rcvbuf()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

so_rcvlowat¶
[Source]


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


that: FileMkdir val

Returns¶

Bool val

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

Parameters¶

that: FileMkdir val

Returns¶


//
// that apply and release backpressure as needed

use "backpressure"
use "collections"
use "net"

class SlowDown is TCPConnectionNotify
let _auth: ApplyReleaseBackpressureAuth
let _out: OutStream

new iso create(auth: ApplyReleaseBackpressureAuth, out: OutStream) =>
_auth = auth
_out = out

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

fun ref unthrottled(connection: TCPConnection ref) =>


fun log(): F64 => @"llvm.log.f64"(this)
fun log2(): F64 => @"llvm.log2.f64"(this)
fun log10(): F64 => @"llvm.log10.f64"(this)
fun logb(): F64 => @logb(this)

fun pow(y: F64): F64 => @"llvm.pow.f64"(this, y)
fun powi(y: I32): F64 =>
ifdef windows then
pow(y.f64())
else
@"llvm.powi.f64"(this, y)
end

fun sqrt(): F64 =>
if this < 0.0 then
_nan()
else
@"llvm.sqrt.f64"(this)
end


U8 val

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

Returns¶

U8 val

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


fun box ipv6_fl_s_any()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

ipv6_fl_s_none¶
[Source]


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

Parameters¶

y: I8 val

Returns¶

I8 val ?

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

Parameters¶


# Other stuff

Type aliases get used for a lot of things, but this gives you the general idea. Just remember that a type alias is always a convenience: you could replace every use of the type alias with the full type after the `is`.

In fact, that's exactly what the compiler does.


ForAll4[T1: T1, T2: T2, T3: T3, T4: T4]¶
[Source]
class ref ForAll4[T1: T1, T2: T2, T3: T3, T4: T4]

Constructors¶
create¶
[Source]
new ref create(
gen1': Generator[T1] val,
gen2': Generator[T2] val,
gen3': Generator[T3] val,
gen4': Generator[T4] val,
h: TestHelper val)


fun box tcpolen_nop()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

tcpolen_sack¶
[Source]


fun box f64()
: F64 val

Returns¶

F64 val

i8_unsafe¶
fun box i8_unsafe()
: I8 val

Returns¶

I8 val

i16_unsafe¶
fun box i16_unsafe()
: I16 val


let key' = key

if not found then
_array(i)? = (consume key, consume value)

_size = _size + 1

if (_size * 4) > (_array.size() * 3) then
_resize(_array.size() * 2)
end
end

_array(i)? as (_, V)
else
// This is unreachable, since index will never be out-of-bounds.
value'
end

fun ref remove(key: box->K!): (K^, V^) ? =>
"""


ApplyReleaseBackpressureAuth¶
[Source]
primitive val ApplyReleaseBackpressureAuth

Constructors¶
create¶
[Source]
new val create(
from: AmbientAuth val)
: ApplyReleaseBackpressureAuth val^

Parameters¶


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


y: I8 val

Returns¶

I8 val

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

Parameters¶

y: I8 val

Returns¶


ambient_auth.pony

1
2
3
4
5
6
7
8
9
10
11


primitive FileLookup
primitive FileMkdir
class FileMode
primitive FileOK
class FilePath
primitive FilePermissionDenied
primitive FileRead
primitive FileRemove
primitive FileRename
primitive FileSeek
primitive FileStat
actor FileStream
primitive FileSync
primitive FileTime
primitive FileTruncate
primitive FileWrite
primitive OpenFile
primitive Path
interface WalkHandler


```pony
let my_list = List[String].unit("element")
```
"""
push(consume a)

new from(seq: Array[A^]) =>
"""
Creates a list equivalent to the provided Array (both node number and order are preserved).

```pony
let my_list = List[String].from(["a"; "b"; "c"])
```
"""
for value in seq.values() do
push(consume value)
end

fun ref reserve(len: USize) =>


Start reading off this TCPConnection again after having been muted.
"""
_muted = false
if not _reading then
_pending_reads()
end

be set_notify(notify: TCPConnectionNotify iso) =>
"""
Change the notifier.
"""
_notify = consume notify

be dispose() =>
"""
Close the connection gracefully once all writes are sent.
"""
close()

fun local_address(): NetAddress =>


fun box hash64()
: U64 val

Returns¶

U64 val

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

Returns¶

I8 val

i16¶
[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]


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


break
end
end
(hits.reverse(), misses.reverse())

fun val drop(n: USize): List[A] =>
"""
Builds a list by dropping the first n elements.
"""
var cur: List[A] = this
if cur.size() <= n then return Nil[A] end
var count = n
while count > 0 do
match cur
| let cons: Cons[A] =>
cur = cons.tail()
count = count - 1
end
end
cur


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


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


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


pointer.pony

1
2
3
4
5
6
7
8
9
10
11


| Equal => error
| Greater =>
let minuend: T = _next_minuend()
let old = _cur
_cur = _cur - minuend
if old < _cur then
_overflow = true
end
old
end
end

let min_iter =
match relation
| let _: (Less | Greater) => Poperator[T]([min])
| Equal => Poperator[T].empty()
end

let shrunken_iter = Iter[T].chain(
[


y: A

Returns¶

(A , Bool val)

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

Parameters¶

y: A

Returns¶


fun ipv6_multicast_if():I32 => @pony_os_sockopt_option(I32(142))
fun ipv6_multicast_loop():I32 => @pony_os_sockopt_option(I32(143))
fun ipv6_nexthop():I32 => @pony_os_sockopt_option(I32(144))
fun ipv6_origdstaddr():I32 => @pony_os_sockopt_option(I32(145))
fun ipv6_pathmtu():I32 => @pony_os_sockopt_option(I32(146))
fun ipv6_pktinfo():I32 => @pony_os_sockopt_option(I32(147))
fun ipv6_pmtudisc_do():I32 => @pony_os_sockopt_option(I32(148))
fun ipv6_pmtudisc_dont():I32 => @pony_os_sockopt_option(I32(149))
fun ipv6_pmtudisc_interface():I32 => @pony_os_sockopt_option(I32(150))
fun ipv6_pmtudisc_omit():I32 => @pony_os_sockopt_option(I32(151))
fun ipv6_pmtudisc_probe():I32 => @pony_os_sockopt_option(I32(152))
fun ipv6_pmtudisc_want():I32 => @pony_os_sockopt_option(I32(153))
fun ipv6_prefer_src_cga():I32 => @pony_os_sockopt_option(I32(154))
fun ipv6_prefer_src_coa():I32 => @pony_os_sockopt_option(I32(155))
fun ipv6_prefer_src_home():I32 => @pony_os_sockopt_option(I32(156))
fun ipv6_prefer_src_noncga():I32 => @pony_os_sockopt_option(I32(157))
fun ipv6_prefer_src_public():I32 => @pony_os_sockopt_option(I32(158))
fun ipv6_prefer_src_pubtmp_default():I32 => @pony_os_sockopt_option(I32(159))
fun ipv6_prefer_src_tmp():I32 => @pony_os_sockopt_option(I32(160))
fun ipv6_priority_10():I32 => @pony_os_sockopt_option(I32(161))


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


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


that: Backpressure val

Returns¶

Bool val

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

Parameters¶

that: Backpressure val

Returns¶


WriteError¶
[Source]
primitive val WriteError

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

Returns¶

WriteError val^


if _muted then
hard_close()
else
_close()
end
end

fun ref _close() =>
_closed = true
_try_shutdown()

fun ref _try_shutdown() =>
"""
If we have closed and we have no remaining writes or pending connections,
then shutdown.
"""
if not _closed then
return
end


fib_j * (fib_j + (fib_i * 2))
elseif (n % 4) == 1 then
(((fib_j * 2) + fib_i) * ((fib_j * 2) - fib_i)) + 2
else
(((fib_j * 2) + fib_i) * ((fib_j * 2) - fib_i)) - 2
end
end

//The generator stops on overflow.
fun has_next(): Bool => _last <= _next

fun ref next(): A =>
_last = _next = _uber_next = _next + _uber_next
_last


use @"llvm.uadd.with.overflow.i16"[(U16, Bool)](a: U16, b: U16)
use @"llvm.uadd.with.overflow.i32"[(U32, Bool)](a: U32, b: U32)
use @"llvm.uadd.with.overflow.i64"[(U64, Bool)](a: U64, b: U64)
use @"llvm.uadd.with.overflow.i128"[(U128, Bool)](a: U128, b: U128)
use @"llvm.usub.with.overflow.i8"[(U8, Bool)](a: U8, b: U8)
use @"llvm.usub.with.overflow.i16"[(U16, Bool)](a: U16, b: U16)
use @"llvm.usub.with.overflow.i32"[(U32, Bool)](a: U32, b: U32)
use @"llvm.usub.with.overflow.i64"[(U64, Bool)](a: U64, b: U64)
use @"llvm.usub.with.overflow.i128"[(U128, Bool)](a: U128, b: U128)
use @"llvm.umul.with.overflow.i8"[(U8, Bool)](a: U8, b: U8)
use @"llvm.umul.with.overflow.i16"[(U16, Bool)](a: U16, b: U16)
use @"llvm.umul.with.overflow.i32"[(U32, Bool)](a: U32, b: U32)
use @"llvm.umul.with.overflow.i64"[(U64, Bool)](a: U64, b: U64)
use @"llvm.umul.with.overflow.i128"[(U128, Bool)](a: U128, b: U128)

primitive U8 is UnsignedInteger[U8]
new create(value: U8) => value
new from[B: (Number & Real[B] val)](a: B) => a.u8()

new min_value() => 0


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

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


[Source]
Returns true if the flag is set.
fun box apply(
flag: A)
: Bool val

Parameters¶

flag: A

Returns¶

Bool val

all¶
[Source]
Sets all bits, including undefined flags.
fun ref all()
: None val


F64 val

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

Returns¶

I8 val

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

Returns¶


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

fun clz_unsafe(): ULong =>
"""
Unsafe operation.
If this is 0, the result is undefined.
"""
ifdef ilp32 or llp64 then
@"llvm.ctlz.i32"(this.u32(), true).ulong()
else
@"llvm.ctlz.i64"(this.u64(), true).ulong()
end

fun ctz_unsafe(): ULong =>
"""
Unsafe operation.
If this is 0, the result is undefined.
"""


Bool val

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

Parameters¶

y: U64 val

Returns¶

Bool val

lt¶
[Source]


y: I128 val

Returns¶

(I128 val , I128 val)

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

Parameters¶

y: I128 val

Returns¶


32
33
34
35
36
37primitive GreatestCommonDivisor
"""
Get greatest common divisor of x and y.

Providing 0 will result in an error.

Example usage:

```pony
use "math"

actor Main
new create(env: Env) =>
try
let gcd = GreatestCommonDivisor[I64](10, 20)?


group: String val,
to: String val = "")

Parameters¶

group: String val
to: String val = ""

dispose¶
[Source]
Stop listening.
be dispose()

Public Functions¶
local_address¶
[Source]
Return the bound IP address.
fun box local_address()


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


fun ref f32_le(data: F32) =>
"""
Write an F32 to the buffer in little-endian byte order.
"""
u32_le(data.bits())

fun ref f32_be(data: F32) =>
"""
Write an F32 to the buffer in big-endian byte order.
"""
u32_be(data.bits())

fun ref u64_le(data: U64) =>
"""
Write a U64 to the buffer in little-endian byte order.
"""
let num_bytes = U64(0).bytewidth()
ifdef littleendian then
_current.push_u64(data)


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


Help¶
[Source]
primitive val Help

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

Returns¶

Help val^


TCPListener¶
[Source]
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.
use "net"

class MyTCPConnectionNotify is TCPConnectionNotify
fun ref received(
conn: TCPConnection ref,
data: Array[U8] iso,
times: USize)
: Bool


from: AmbientAuth val

Returns¶

FileAuth val^

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

Parameters¶

that: FileAuth val

Returns¶


ListNode[A: A]¶
[Source]
A node in a doubly linked list.
See Pony collections.List
class for usage examples.
Each node contains four fields: two link fields (references to the previous and
to the next node in the sequence of nodes), one data field, and the reference to
the List in which it resides.
As you would expect functions are provided to create a ListNode, update a
ListNode's contained item, and pop the item from the ListNode.
Additional functions are provided to operate on a ListNode as part of a Linked
List. These provide for prepending, appending, removal, and safe traversal in
both directions.  The Ponylang


## Write

The TCP protocol has built-in backpressure support. This is generally
experienced as the outgoing write buffer becoming full and being unable
to write all requested data to the socket. In `TCPConnection`, this is
hidden from the programmer. When this occurs, `TCPConnection` will buffer
the extra data until such time as it is able to be sent. Left unchecked,
this could result in uncontrolled queuing. To address this,
`TCPConnectionNotify` implements two methods `throttled` and `unthrottled`
that are called when backpressure is applied and released.

Upon receiving a `throttled` notification, your application has two choices
on how to handle it. One is to inform the Pony runtime that it can no
longer make progress and that runtime backpressure should be applied to
any actors sending this one messages. For example, you might construct your
application like:

```pony
// Here we have a TCPConnectionNotify that upon construction
// is given a ApplyReleaseBackpressureAuth token. This allows the notifier


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


OutStream¶
[Source]
Asnychronous access to some output stream.
interface tag OutStream

Public Behaviours¶
print¶
[Source]
Print some bytes and insert a newline afterwards.
be print(
data: (String val | Array[U8 val] val))

Parameters¶


be flush() =>
"""
Flush pending data to write.
"""
_file.flush()


=>
"""
Assert that the given expression is true.
"""
if not predicate then
_fail(_fmt_msg(loc, "Assert true failed. " + msg))
return false
end
_runner.log(_fmt_msg(loc, "Assert true passed. " + msg))
true

fun assert_error(
test: {(): None ?} box,
msg: String = "",
loc: SourceLoc = __loc)
: Bool
=>
"""
Assert that the given test function throws an error when run.
"""


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


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


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


# Lambdas

Arbitrarily complex closures are nice, but sometimes we just want a simple closure. In Pony, you can use the lambdas for that. A lambda is written as a function (implicitly named `apply`) enclosed in curly brackets:

```pony
{(s: String): String => "lambda: " + s }
```

This produces the same code as:

```pony
object
fun apply(s: String): String => "lambda: " + s
end
```

The reference capability of the lambda object can be declared by appending it after the closing curly bracket:

```pony
{(s: String): String => "lambda: " + s } iso


cpointer¶
[Source]
Returns a C compatible pointer to the underlying string allocation.
fun box cpointer(
offset: USize val = 0)
: Pointer[U8 val] tag

Parameters¶

offset: USize val = 0

Returns¶

Pointer[U8 val] tag

cstring¶
[Source]
Returns a C compatible pointer to a null-terminated version of the
string, safe to pass to an FFI function that doesn't accept a size


end

out.append("\r")
out.append(ANSI.right(pos.u32()))
_out.write(consume out)
end

fun ref _add_history(line: String) =>
"""
Add a line to the history, trimming an earlier line if necessary.
"""
try
if (_history.size() > 0) and (_history(_history.size() - 1)? == line) then
_cur_line = _history.size()
return
end
end

if (_maxlen > 0) and (_history.size() >= _maxlen) then
try


fun box sctp_closed()
: I32 val

Returns¶

I32 val

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

Returns¶

I32 val

sctp_cmt_base¶
[Source]