Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax changes #40

Open
8 of 12 tasks
cm4ker opened this issue Mar 9, 2022 · 0 comments
Open
8 of 12 tasks

syntax changes #40

cm4ker opened this issue Mar 9, 2022 · 0 comments

Comments

@cm4ker
Copy link
Owner

cm4ker commented Mar 9, 2022

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant