Syntax Overview

Hello, World!

>_("Hello, Styio!")

Basic Type

Boolean

x = $T

x = $F

Integer

x : i32 = 0

Float

y : f64 = 0.0

Char

z = '\n'

Project

Import Module

@(
  "module"
) -> {
  
}

Resource

Resource Declaration (Global) (Can Only Be Assigned Once)

@(x, y)

Resource Assignment (Immutable) (Final)

@(x) <- "data.csv"

Resource Definition (Immutable) (Final)

@(x <- "data.csv")

Variable

Variable Declaration (Global) (Mutable) (Flexible)

x: i32

Variable Definition (Global) (Mutable) (Flexible)

x: f64 = 0.3

Variable Assignment (Global) (Mutable) (Flexible)

x = 0

Variable Assignment (Global) (Immutable) (Final)

x := 0

Function

Function Declaration (Accept Overload) (Flexible) (Danger!)

# f = (x) => {
  == x ==>
}

# f = (x, y) => {
  == x + y ==>
}

Function Definition (Reject Overload) (Final)

# f := (x, y) => {
  == x + y ==>
}

Function Declaration / Definition (With Optional Arguments)

# f = (x, *) => {

}

# f := (x, *) => {

}

Function Declaration / Definition (With Optional Arguments and Keyword Arguments)

# f = (x, *, **) => {

}

# f := (x, *, **) => {

}

Closure / Anonymous Function / Lambda Expression

#(x, y) => {
  == x + y ==>
}

Enumeration

Definition (Final)

# Type := {
  | Some,
  | None,
}

Struct

Struct Definition (Reject Overload) (Final)

# Point := (
  x: f64, 
  y: f64,
)

Struct: Inherit

# Point3D 
  <: {
    Point; 
    Else;
  } 
  := (
    x: f64,
    y: f64,
    z: f64,
  )

Struct: Extra Methods

# Point := (
  x: f64, 
  y: f64,
) +: {
  eval := () => {
    == (x, y) ==
  }
}

Evaluation

$ sum 
  = {
    result <- 0;
  }
  >> (
    x
  ) 
  => {
    result += x
  }
  -> result
$ count 
  = {
    result <- 0;
  }
  >> (
    x
  )
  => {
    result += 1
  }
  -> result
$ [avg, mean]
  = {
    count <- 0;
    sum <- 0;
  }
  >> (
    x
  )
  => {
    count += 1
    sum += x
  } 
  -> (sum, count) 
  => {
    == sum / count ==>
  }
$ min
  = {
    result;
  }
  >> (
    x
  )
  => {
    ?? (result != {})
    :) {
      ?? (x < result)
      :) {
        result = x
      }
      :( {
        >>>>>>>>>>
      }
    }
    :( {
      result = x
    }
  } 
  -> result
$ max
  = {
    result;
  }
  >> (
    x
  )
  => {
    ?? (result != {})
    :) {
      ?? (x > result)
      :) {
        result = x
      }
      :( {
        >>>>>>>>>>
      }
    }
    :( {
      result = x
    }
  } 
  -> result

Use evaluation pipeline

max_val = array |> ${max}

Extra: Evaluate Stream Computing

$ sum_revenue
  = {result}
  >> (x) 
  => {
    result += x.revenue
  }
  -> result

Extra: Stream Template

$ extract_fields
  >> (k, v)
  ~> (k.name, k.age)
$ sum_revenue
  >> (k, v)
  ~> {
    k.uuid,
    count(k.region),
    sum(k.price),
  }

Collection

String

"Hello, Styio!"
'Hello, Styio!'

Format String

name = "Styio"

"Hello, {name}!"
name = 'Styio'

'Hello, {name}!'

Verbatim String (Resource)

@"Hello, World!"
@'Hello, World!'

Raw String

"""
Why do you need this?
"""
'''
Why do you need this?
'''

Tuple

(0, 1, 2)

Array

x: i32[100] = [0..]

List

[1, 2, 3, 4, 5, 6]

Get size (length) of the list

list = [1, 2, 3, 4, 5, 6]

|list|

</> 6

Push / Append / Add an element to the tail

list = [1, 2, 3, 4, 5, 6]

list ]< 7

</> [1, 2, 3, 4, 5, 6, 7]

Pop / Delete the last element

list = [1, 2, 3, 4, 5, 6]

item = list ]>

</> [1, 2, 3, 4, 5]

Reversed

list[<]

</> [6, 5, 4, 3, 2, 1]

Get an element by index

list = ['a', 'b', 'c']

list[0]

</> a

Get index of an element

list = ['a', 'b', 'c']

list[?= 'b']

</> 1

Insert an element by index

list = ['a', 'b', 'd']

list[+: 2 <- 'c']

</> ['a', 'b', 'c', 'd']

Insert an element to the head

list = ['b', 'c', 'd']

list[+: 0 <- 'a']

</> ['a', 'b', 'c', 'd']

Remove an element by index

list = ['a', 'o', 'b', 'c']

list[-: 1]

</> ['a', 'b', 'c']

Remove elements by many indices

list = ['a', 'o', 'b', 'c']

list[-: (1, 2)]

</> ['a', 'b', 'c']

Remove an element by value (from left to right)

list = [1, 2, 3]

list[-: ?= 2]

</> [1, 3]

Remove elements by many values (from left to right)

list = [1, 2, 3]

list[-: ?^ (2, 3)]

</> [1]

Remove element by value (from right to left)

list = [1, 2, 3, 2]

list[[<] -: ?= 2]

</> [1, 2, 3]

Remove elements by condition

list = [1, 2, 3]

list >> x -: ?(x <= 2)

</> [3]

Add elements by lambda function (Danger!)

list = [(1, 3), (2, 4)]

list >> (x, y) +: {
    // This is a lambda function.
}

Remove elements by lambda function (Danger!)

list = [(1, 3), (2, 4)]

list >> (x, y) -: {
    // This is a lambda function.    
}

Form a list from another list

a = [] << {
  b >> x => {
    == x ==>
  }
}

Form a list from a dictionary

a = [] << {
  d >> (k, v) => {
    == v ==>
  }
}

Record

< name = "Alice", 
  age = 15,
>

Get the value by name of attribute (item)

record.name
record['name']

Dictionary

{
  "A": "Alice",
  "B": "Bob",
}

Get value by key

dict["C"]

Add Key-Value Pair

dict["C"] = "Clare"

Remove key-value pair

dict[-: "B"]

Update dictionary by another dictionary

d1 <- d2

Decompose

d ~ (k, v)

Get keys

// As a list (value expression)
[d ~ (k, v) -> k]

// As a variable (still a list)
k <- [d ~ (k, v)]

Get values

// As a list (value expression)
[d ~ (k, v) -> v]

// As a variable (still a list)
v <- [d ~ (k, v)]

Apply Lambda Function

dict >> (x, y) => {
    
}

Control Flow

Condition / Cases

if ... then ... else ...

?( /* Condition */ ) 
:) {
    
} 
:( {

}

match

val ?= {
  0 => {
    // Do Something
  } 
  
  1 => {
    // Do Something
  }
  
  _ => {
    // Do Something
  }
}

Loop / Iteration

Before We Start, You Need To Know:

Return

== x ==>

Break

^^^^^^^^

Continue

>>>>>>>>

Infinite Loop

[...] >> {

}

Infinite Loop (With Auto Cast + Match Cases)

Match Cases (Only One)
x = 1

[...] >> x ?= 1 => {
  >_("x is 1")
}
Match Cases (Many)
x = 0
c = 0

[...] >> x ?= {
  0 => {
    x = 1
    
    ?(c >= 10) 
    :) {
      ^^^^^^^^
    }
  }
  
  1 => {
    x = 0
    c = c + 1
  }
  
  _ => {
    !!! <- "You should not reach this line, and there must be something wrong."
  }
}

Range

Range Iterator

[0..10] >> {
  
}

Range Iterator (With Auto Cast)

[0..10] >> x => {
  >_(x)
}

Range Iterator (With Auto Cast + Match Cases)

Match Cases (Only One)
[0..10] >> (x) ?= 5 => {
  >_("x is 5")
}
Match Cases (Branches)
[0..10] >> (x) ?= {
  0 => { >_("x is 0") }
  1 => { >_("x is 1") }
  _ => { >_("Default") }
}

Range Iterator (With Auto Cast + Check Is In)

[0..10] >> (x) ?^ (2, 3, 5, 7) => {
  >_("x is prime number")
}

Range Iterator (With Auto Cast + Check Condition)

[0..10] >> (x) ? (x % 2 == 0) :) {
  >_("x is even number")
}

List

List Iterator

[0, 1, 2] >> {
    
}

List Iterator (With Auto Cast)

[0, 1, 2] >> x => {
    >_("x")
}

List Iterator (With Auto Cast + Match Cases)

Match Cases (Only One)
[0, 1, 2] >> (x) ?= 0 => {
  >_("x is 0")
}
Match Cases (Branches)
[0, 1, 2, 3, 4] >> x ?= {
  0 => { >_("x is 0") }
  1 => { >_("x is 1") }
  _ => { >_("Default") }
}

List Iterator (With Auto Cast + Check Is In)

[0, 1, 2, 3, 4, 5] >> (x) ?^ (2, 3, 5) => {
  >_("x is prime number")
}

List Iterator (With Auto Cast + Check Condition)

[0, 1, 2] >> (x) ? (x % 2 == 1) :) {
  >_("x is odd number")
}

IO

Print

>_("Styio!")

Read File

x <- @("data.csv")

Write File

x -> @("data.csv")
x <- @("https://some.link/path/to/file.json")

Listen Web Socket (Block Thread)

@("localhost:35752") >> {
    
}

Concurrent

{
& =>
& =>
& =>
}
{
% => 
% => 
% =>
}

Lock (I'm sure there is a way but just can't find now.)

*|>

<|*

Exception handling

!!! <- "Error: There is something wrong."

Operator Overload

# This : {

}
  +: {
  `$? + {Other}`: {}
}
Template (Format Expression)
Description
`- $?` : {}

Negative: - This

`$? + {Other}` : {}

Binary Addition: This + Other

`$? - {Other}` : {}

Binary Subtraction: This - Other

`$? * {Other}` : {}

Binary Multiplication: This * Other

`$? / {Other}` : {}

Binary Division: This / Other

`$? ** {Other}` : {}

Math: Power {Base: This, Exponent: Other}

`$? % {Other}` : {}

Math: Modulo {Dividend: This, Divisor: Other}

`{Other} + $?` : {}

Reversed Addition: Other + This

`{Other} - $?` : {}

Reversed Addition: Other - This

`{Other} * $?` : {}

Reversed Addition: Other * This

`{Other} / $?` : {}

Reversed Addition: Other / This

`{Other} ** $?` : {}

Math: Power {Base: Other, Exponent: This}

`{Other} % $?` : {}

Math: Modulo {Dividend: Other, Divisor: This}

`$? += {Other}` : {}

Other += This

`$? -= {Other}` : {}

Other -= This

`$? *= {Other}` : {}

Other *= This

`$? /= {Other}` : {}

Other /= This

`$? %= {Other}` : {}

Other %= This

`! $?` : {}

Logic NOT: ! This

`$? && {Other}` : {}

Logic AND: This && Other

`$? || {Other}` : {}

Logic OR: This || Other

`$? ^ {Other}` : {}

Logic XOR: This || Other

`$? & {Other}` : {}

Bit AND: This & Other

`$? | {Other}` : {}

Bit OR: This | Other

`$? >> {Other}` : {}

Bit Right Shift: This >> Other

`$? << {Other}` : {}

Bit Left Shift: This << Other

` % |$?| ` : {}

Method: Get size (length) of This

` % "$?" ` : {}

Method: Get string of This

`% :< $?` : {}

Method: Get type of This

`$?[{Item}]` : {}

Method: Get Item of This

`$?[{Item}] = {Value}` : {}

Method: Set Item of This as Value

`$?.{Attr}` : {}

Method: Get Attr of This

`$?.{Attr} = {Value}` : {}

Method: Set Attr of This as Value

`$?[<]` : {}

Method: Get reversed collection.

`$? ?^ {List}` : {}

Method: Check if This in List or not.

`$? >>` : {}

Iterator: Implement an iterator for This collection.

`$?()` : {}

Trigger: When an instance of This is called, do ...

`$?(x, y)` : {}

Trigger: When an instance of This is called, with arguments of (x, y), do ...

`$?(*, **)` : {}

Trigger: When an instance of This is called, with optional arguments of *, and keyword arguments of **, do ...

Last updated