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
  • Fibonacci
  • fib.hd
  • main.hd
  • Perceptron
  • Factorial
  • main.hd
  1. Other

Examples

Fibonacci

fib.hd

func calculate(n int64) -> int64
    if((n is 0) or (n is 1))
        put n
    end
    
    put fib(n-1) + fib(n-2)
end
var calculate lambda::(int64)->int64 = { x => ((x == 0) or (x == 1)) ? x : calculate(x-1) + calculate(x-2) }

main.hd

with fib from fib.hd
with console from std:io
with Int fixed from std:int

fib.calculate(parse(value=console.in(),raise=false,defaultValue=0))

Perceptron

let points double[*] = 
{
    {245, 1400},
    {312, 1600},
    {279, 1700},
    {308, 1875},
    {199, 1100},
    {219, 1550},
    {405, 2350},
    {324, 2450},
    {319, 1425},
    {255, 1700}
}

var weight = 10.0
var bias = 100.0
var lr = 0.000001

for(_ in range(1000000))
    for(var point in points)
        var prediction = point[0] * weight + bias
        var error = point[1] - prediction
        var gradient = point[0] * error * lr

        bias = bias + gradient
        weight = weight + weight * gradient
    end
end

Factorial

main.hd

with console from std:io

var factorial = { x => (x >= 1) ? x * factorial(x-1) : 1 }
console.out(factorial(6))
PreviousToolsNextTodos

Last updated 5 years ago