Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

PONY ACTOR

actor MyActor
OPERATORS
math
REF CAPS (REFERENCE CAPABILITIES)
iso - (isolated) alias is R/W, no other alias can R or W

CHEAT
let _x: Type // private + trn -(transitional) alias is R/W, other aliases are R-only
let x: Type // public - ref -(reference) alias is R/W, other aliases can be R/W
val -(value) alias is R-only, other aliases are R-only
SHEET
new create() => *
// initialization / box -(box) alias is R-only, other aliases can be R-only or R/W
be my_behavior() => % tag -(tag) alias cannot R or W, other aliases can R-only or R/W
Any alias can be used to send a message to an actor
COMMUNITY
// async behavior
fun my_fun(): Type => bit shift
website: https://ponylang.io
chat: https://ponylang.zulipchat.com/
// synchronous function << REF CAP RULES CONSUME
>>
twitter: @ponylang ● if an object can be written to then get rid of an alias
tutorial: https://tutorial.ponylang.io
CLASS only one actor can have a readable let x: Type iso = …
bitwise & logical
stdlib: https://stdlib.ponylang.io
class MyClass alias to it let y: Type val = consume x
and
github: https://github.com/ponylang
let _x: Type // private ● if an object can be read by
or
play: https://playground.ponylang.io
let x: Type // public
xor
multiple actors then no actor can RECOVER
new create() => have a writable alias to it “lift” the reference capability of the object
// initialization not
created inside the recover block
HELLO WORLD fun my_fun(): Type =>
compare
REF CAP USAGE ● iso, trn, or ref objects can become
// synchronous function default refcap for type anything
""" ==
class refcap MyClass ● val or box objects can become val
PRIMITIVE
module doc (top of file) !=
""" <
trait refcap MyTrait or tag
primitive MyPrimitive interface refcap MyInterface let x = recover refcap
actor Main >
""" // only has functions <= // create something
// no members refcap of alias end
type doc >=
fun my_fun(): Type => let x: Type refcap
"""
ALIAS TYPE (!)
is
// synchronous function fun my_fun(x: Type refcap)
new create(env: Env) => isnt
""" means “a type (including refcap) that can be
refcap of recovered object
method doc TRAIT (nominal subtyping) negative assigned to this type (including refcap)”
""" subtyping is explicit using is -
recover refcap … end ● useful in generics
env.out.print("hello") trait MyTrait refcap!
refcap of new object
fun my_fun() // opt impl method call
CONTROL
new refcap create()
class MyClass is MyTrait . EPHEMERAL TYPE (^)
if … then … fun my_fun() => refcap of method receiver type for an object that has no alias
elseif … else … end // do something method call, return ● object returned by constructor
fun refcap my_fun()
receiver ● object from consumed alias
try … else … end INTERFACE (structural .>
refcap of return value refcap^
subtyping) fun my_fun(): Type refcap
match expr any class that implements the interface’s LITERALS
| let x: T1 => … methods is a subtype of the interface // string
| let x: T2 if expr => …
else …
interface MyInterface "hello" REF CAP SUBTYPING
end
fun my_fun() // opt impl if you give up an alias of X then you can assign (-->) the aliased object to a new alias of Y
class MyClass // array
fun my_fun() => [1; 2; 3] val
for expr in iter do … end // do something iso trn box tag
while expr do … end LAMBDA ref
{(arg, …)(capture=alias, ...): Type => … }
repeat expr do … end version 0.0.3

You might also like