Syntax Overview

This is a cheatsheet for Roto’s syntax. Refer to the Language Reference for the full explanation of these concepts.

Name

Example

See

Comment

# this is a comment

Comments

Unit

()

Unit Type

Never type

!

Never Type

Boolean

true, false

Booleans, bool

Integer

10, -100, 0

Integers

Float

10.5, -10.0, 1., 1e+10

Floating Point Numbers

IP address

0.0.0.0, 2001:DB8::5673:23b5, ::

IpAddr

AS number

AS1234

Asn

String

"hello, world!"

Strings, String

Format string

f"hello, world!"

String Formatting

Optional values

None, Some(x)

Optional Values

Anonymous record

{ x: 10, y: 20 }

Anonymous Records

Named record

Foo { x: 10, y: 20 }

Named Records

List

[10, 20, 30]

Lists, List[T]

Unary operator

-x

Arithmetic Operators

Binary operator

x + y

Arithmetic Operators

Assignment

x = 10

Local Variables

Field access

x.y

Anonymous Records, Named Records

Function call

add(x, y)

Method call

x.add(y)

Static method call

String.append(x, y)

Let binding

let x = 10

Local Variables

Function declaration

fn add(x: i32, y: i32) -> i32 { .. }

Functions

Filter-map declaration

filter foo(..) { .. }, filtermap foo(..) { .. }

Filtermap

Record declaration

record Foo { .. }

Named Records

Enum declaration

enum Foo { .. }

Enum Types

If-else

if x == 1 { .. }, if x == 1 {..} else {..}

If-else

Pattern matching

match x { .. }

Match

While loop

while x < 10 { .. }

While Loops

For loop

for x in e { .. }

For Loops

Return

return x

Functions

Verdict

accept x, reject x

Filtermap

Import items from module

import foo.bar

Imports