User:Vicky.katara/sandbox

GorillaScript is a scripting language that transcompiles to JavaScript. It is designed to empower the user while attempting to prevent some common errors. Specific additional features include Constants, Some new operators, String interpolation, Optional parameters, Spread parameters, Maps and Sets, Lexical scoping in loops, Array slicing, Cascades, Class es Destructuring, Topicless switch, Iterators, Promises, Parallel loops, Optional typing, Operators-as-functions, Getters and setters (only in engines that support it), Curried functions, Generics, Macros

Access with ownership
Every key owned by the object can be accessed.

Apply syntax
GorillaScript provides the   syntax to replace  either   or   used with JavaScript. It transparently converts to   or   (whichever is more appropriate), using the first argument as its .

Binding access
In GorillaScript, the familiar   syntax with access is, instead of

Classes
While Vanilla JavaScript does not allow definition of classes in the classical style, GorillaScript permits this. Classes can   other classes and call into their superclass with . The constructor functions automatically check the  argument and if it is not the current class’s type (such as when called without  ), it will create a new one on-the-fly.

Regular Expressions
In GorillaScript, Regular Expressions borrow the string syntax simply prefixed with  and postfixed with any RegExp flags deemed necessary. This is unlike JavaScript where  is used to mark Regular Expressions.

Also, if triple-quoted strings (e.g. ) are used, all spaces are ignored as well as any

Promises
GorillaScript provides mechanisms for Promises/A+-compliant Promises to be used and joined and manipulated together.

Promises provide a whole slew of asynchronous-capable syntax to make dealing with “callback hell” just a little easier. Since JavaScript fundamentals and frameworks (node.js, for example) tend to be very async-friendly, this is especially helpful.

Promises have the benefit over simple callbacks in that they are well-defined by the Promises/A+ spec, have easy-to-follow resolve/reject rules, and can be combined together shockingly easily.

Piggy-backing on the   syntax, since   can be used as an expression and not just a statement, information can be sent back to the iterator every time a   occurs. GorillaScript takes advantage of this with the   keyword, which converts a generator function into a Promise factory or allows an arbitrary block of code to turn into a Promise. To achieve this, all that needs to be done is that other Promises need to  until complete. It practically reads like synchronous code, and it is guaranteed to execute in the same order as if it were synchronous.

The   can also be used with a body of code instead of just a function:

Optional typing
On parameters, the format  may be used. These will be checked at runtime and the type inference engine will be aware of them.

The types  ,  , , and   will check against  , not with  ,  , and   (alias for  ) are also seen as valid types.

Arrays can be made using the syntax of   for an array of any type or   for a specific array. The contents will be checked at runtime.

Objects can be made using the standard object syntax with all values being types, e.g.

Functions with specific parameters or return value can be defined with   for any parameter, any return. for a specific return value,   for a single-argument with a specific return value, or   for two arguments with a specific return value.

Type unions can be made with , e.g. . Order is irrelevant.

Functions are also permitted to bear a return type. Types can also be placed on let statements, to help with the type inference engine.

Curried functions
Currying is a technique of transforming a function which takes multiple arguments in such a way that it can be called as a chain of functions. GorillaScript provides automatic currying of functions. Simply by putting the caret after the function parameters, functions are automatically curried. Curried functions tend to find their use in functional-style programming and when coupled with the compose operators (  and  )

Generics
GorillaScript supports reified generic classes and functions, which are similar to .NET's generics or C++'s templates.

If a function is called with generic arguments, it will get converted like this: How the function handles the   call can vary, but GorillaScript's classes are built to handle it. In the previous case,  , , and   (same as  ) all refer to three independent classes which have different semantics.

The  above refers to absolutely any type being accepted, whether it's a , ,  , or some custom object.

Below is an example of a simple function (rather than a class) with generic arguments:

Macros
Macros are a way to write some code that will be used to write other code. They are similar to functions, except that they are evaluated during compile-time rather than run-time. This means that the macros themselves won't appear in the resultant JavaScript source code, as they will have been executed as-necessary and not need to exist when the JavaScript itself is executed.

Macro names can be normal identifiers, custom symbols, or a mixture of the two.

Any macros will be just as capable as any built-in GorillaScript syntax construct, as nearly all of GorillaScript's syntax are actually defined as macros

Support
GNOME has JavaScript bindings with Gjs and GorillaScript supports this.

As long as you have   installed locally, there are three ways to run Gjs with GorillaScript: Aside from being written in GorillaScript rather than JavaScript, it will then function as any other Gjs script
 * REPL: On running   or , a REPL opens that pipes its JavaScript code to
 * Running a   file: On running   or , it will compile the code of   and pipe its results to   all at once.
 * Compile and run with  . On compilation of any   file as per usual with   and run the result   file with  . This is the standard method for distribution of code.

Here is the standard Hello World Gjs code converted to GorillaScript:

Build support
The recommended method to automatically build GorillaScript files is through Grunt. It is easy to add GorillaScript support with the grunt-gorillaplugin.

Here is a sample case that demonstrates the compilation of three   files into a single   file: The code extract below will compile all files in   to  :

Coverage
GorillaScript has built-in coverage instrumentation, that can be picked up by any tool that already supports JSCoverage, including Mocha.

To achieve this, the   option must be passed on the command line or   in the Grunt task.

Browser support
There is a browser-specific version of the GorillaScript compiler as. By including this it will run any   tags, with or without . It compiles and runs each tag in-order.

Caveat: this will not run synchronously like normal   tags, so it is recommended to wait for an   event or something similar.

Once   is included, the global   object will be available.

Any compiled GorillaScript file should work in all browsers, including older browsers. Certain features like getters and setters may not work in engines that do not support them, and this will cause a runtime exception on defining such properties rather than a compile-time error.

Some examples: