Skip to content

Using arrow functions

Vadim Dyachenko edited this page Jun 10, 2022 · 1 revision

2.3 function literals are cool, but what if you could have them shorter?

General idea

(pairs of what you can write instead of what)

var f = () => { print("hi!") };
var f = function() { print("hi!") }

var f = () => ;print("hi!"); // alt. - single-statement without curly brackets
var f = function() { print("hi!") }

var f = () => 1;
var f = function() { return 1; }

var f = (a, b) => a + b;
var f = function(a, b) { return a + b; }

Argument types and optional arguments are supported.

Better workflow:

Syntax extensions:

  • `vals: $v1 $v2` (template strings)
  • #args (pre-2.3 named arguments)
  • ??= (for pre-GM2022 optional arguments)
  • ?? ?. ?[ (pre-GM2022 null-conditional operators)
  • #lambda (pre-2.3 function literals)
  • => (2.3+ function shorthands)
  • #import (namespaces and aliases)
  • v:Type (local variable types)
  • #mfunc (macros with arguments)
  • #gmcr (coroutines)

Customization:

User-created:

Other:

Clone this wiki locally