HadesLang Doc
  • Overview
  • Getting Started
    • Installing Hades
    • Basic Syntax
    • Coding Conventions
  • Language Spec
    • Foundation
      • Types
      • Built-in functions
    • Operators
      • Comparison and equality
      • Logical operators
      • Bitwise operators
      • Compound Assignment Operators
      • Operator overloading
    • Control flow
      • Conditions
      • Loops
      • Exception handling
      • Ternary and nullcheck operators
      • Pipelines
    • Classes and variables
      • Declaring variables
      • Declaring classes
      • Declaring structs
      • Declaring protos
      • Declaring arrays
      • Type conversions in simple variable types
    • Actors
      • Message passing
      • GenServer
      • Channels
    • Functions and lambdas
      • Declaring functions
      • Declaring lambdas
    • Functions of simple types
      • int
      • string
      • float
      • bool
      • atom
      • pid
    • Other
      • Annotations
      • Comments
      • Preprocessor statements
      • Reflection
      • Script file arguments
      • this keyword
  • Core Libraries
    • Standard library
      • std:io
        • console
        • file
        • directory
      • std:exceptions
      • std:int
      • std:internals
        • annotations
          • findMethod
          • findMethodInProto
          • findMethods
          • findMethodsInProto
        • function
      • std:collections
        • map
        • list
      • std:math
        • math
        • constants
        • matrix
      • std:networking
      • std:os
      • std:params
      • std:string
      • std:sql
    • Extra libraries
      • mssql:client
  • Other
    • Tools
    • Examples
    • Todos
Powered by GitBook
On this page
  • Hello world
  • Pipelines
  • Function guards
  • Actors
  • Fibonacci sequence
  1. Getting Started

Basic Syntax

Hello world

with console from std:io
console.out("Hello world")

Pipelines

with list fixed from std:collections
with console from std:io

var fruits = list.of({"Apple", "Banana", "Mango", "Kiwi", "Avocado"})

fruits
|> map(??, {x => x.toLower()})
|> filter({x => x.startsWith("a")})
//if ?? is not in the parameters, the method is inserted as the first parameter
|> forEach(??, {x => console.out(x)})

Function guards

with console fixed from std:io

func myFunction(a int) requires a < 10
    console.out("a is smaller than 10")
end

func myFunction(a int) requires a > 10
    console.out("a is greater than 10")
end

myFunction(5) // a is smaller than 10
myFunction(17) // a is greater than 10

Actors

with msg from std:io
with sleep from std:time

func ping()
    receive(m)
        {:ping, data} => {_ =>
            sleep.seconds(1)
            send(data, :pong)
        }
    end
    ping()
end

func pong()
    receive(m)
        {:pong, data} => {_ =>
            sleep.seconds(1)
            send(data, :ping)
        }
    end
    pong()
end

var pingPid = spawn({_ => ping()}
var pongPid = spawn({_ => pong()}

send(pingPid, {:ping, pongPid})

Fibonacci sequence

with console from std:io

func fib(n)
    if((n is 0) or (n is 1))
        put n
    end
    
    put fib(n-1) + fib(n-2)
end

fib(10) |> console.out
PreviousInstalling HadesNextCoding Conventions

Last updated 5 years ago