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

Variant type declaration

variant Foo { .. }

Variant 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