Skip to content

Arrow function to Abstract Syntax Tree

Summary

I do know Arrow function is not implemented yet. I suggest that if an arrow function is passed into a procedure/method, it will be converted to Abstract Syntax Tree. The callee will use Abstract Syntax Tree and do the work. See the example below:

Example Project

Example 1: use arrow function in ORM

type
  TQuery = class
    function Where(const AST: TAbstractSyntaxTree): TQuery; // This method will convert AST into SQL
  end;


var r = TQuery.From<TUser>.Where((const u: TUser) => u.ID <> 1).InnerJoin((const u: TUser; const p: TPost { any type and params are allowed }) => u.ID = p.UserID ).Select;

Example 2: convert AST to JavaScript


var btn: TWebButton;

btn := TWebButton.Create(nil);
btn.SetClientSideClickHandler((this: TClientButton; evt: TClientClickEvent) => begin this.Text := 'This is a test'; alert('The button is clicked'); end);

SetClientSideClickHandler will convert AST into JavaScript!

Sorry for my bad English!

Edited by Thach Ngo
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information