Thanks to visit codestin.com
Credit goes to github.com

Skip to content

syntax changes #40

@cm4ker

Description

@cm4ker

Code example demonstrates language capabilites

  • modules
  • types with context
  • file visibility
  • clr import namespace
  • clr import class
  • clr import methods & aliasing it
  • flip argument name and type
  • async functions
  • lambdas
  • closures
  • partial types
  • func out / ref arg modifiers
file - main.aq


//look modules in source files (can use external lib)
import math;

//import clr namespace
import clr System;

//import clr class
import clr System.Console;

//you can alias imported static members for more readability
import clr System.Console { method1_name as m1, method2_name as m2 }

fn main ()
{
    // static methods import as a [class_name]_[method_name] ex:
    console_write("some string");
    
    // just write() on importing System.Console;

    m1();
    m2();
    
    //call add function form math module
    add(10, 1);
}

file - math.aq

//declare new module
module math


//create async method with _async postfix
pub fn add_async(x int, y int) Task<int>
{
    // use await for create state machine for waiting result and continue op
    // it helps create write async code as sync
    return await go {
                        do_stuff();
                        return x + y;
                     };
}

// create private for module function
fn do_stuff()
{
    // do some havy work
}

//sample pass lambda delegate
fn lamda_sample(func fn(int) int) int
{
    return func(10);
}

// create public for module function
pub fn add(int x, int y) int
{
    // use wait operator for waiting the result
    return wait add_async(x, y);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions