TeaScript

From Esolang
Jump to navigation Jump to search

TeaScript is a language designed for code-golfing. A JavaScript program is a valid TeaScript program but TeaScript adds a few more things. This includes shorter property names, implicit i/o, ES2015 features, and smarter syntax. Anyone reasonably familiar with JavaScript can write a TeaScript program.

This page is severely out of date, please go to Read The Docs for the full docs

Overview

The main difference between JavaScript and TeaScript is shorter property names. Property-names are shortened to one-letter and because of only being one letter long, this can negate the need for periods. In addition, TeaScript adds smarter semantics such as the # operator which can remove the need for some brackets. Input is also stored in some variables. Output is implicit.

TeaScript is a compiled language, or specifically, transpiled. This is done with the help of Babel.js.

I/O

Input methods

Input is automatically stored in various variables. Because TeaScript is JavaScript, other functions such as prompt or readline may also be used depending on the enviorment. TeaScript can take multiple inputs.

Name Value
_ Array of inputs
x First input
y Second input
z Third input

Output methods

The output is the value of the last evaluated expression. To put simply, this means that the last thing run is the output. The global L can also be used to output but this is not implemented yet in the online interpreter.

New Syntax

To avoid accidentally parsing within strings. In syntax can be relatively strict in some places.

Using #

Function declarations

To shorten function declarations, you can write (# instead of ((l,i,a)=>

Normally, when defining functions, you would need to write something like this:

array.map((item, index, array)=> /* code */ )

To avoid rewriting this over and over. You can simply use a # instead:

array.map(#/* code */)

This will compile to...

array.map((l,i,a)=>/* code */)

Array / String indexes

This works in a similar way as above. When you have a function and then and then an array key. You may use an alternative syntax to shorten this.

Essentially what the # does is: #n where n is a digit or letter becomes: )[n]

An example, if you were to get the n-th item from a string:

string.slice(x,y)[z]

This can become:

string.slice(x,y#z

Removing periods

In some cases you can completely remove periods (e.g. str.slice -> strslice). After the characters xliaLSAX$`)/]'", any letter/character will be considered a property. That probably sounds confusing so if you speak regex, it's matched by, [xliaLSAX$`)\/\]'"][A-Za-z0-9]. The full RegExp used is: ((?:[^A-Za-z]|^)[xyzliaLIASX]|[\])$/'"])([A-Za-z])(?=[`(:.+,)<>?: /*-])

Because this is probably very confusing, some examples:

x.S(3) -> xS(3)
l.S(3) -> lS(3)
i.S(3) -> iS(3)
a.S(3) -> aS(3)
b.S(3) -> b.S(3) // Period can't be removed because of 'b'

And for parenthesis:

x.S(3).s`` -> xS(3)s``
b.S(3).s`` -> b.S(3)s``

Abbreviations / Property Names

The shortening or property names is probably one of the most important aspect of TeaScript, because new built-ins / shortened property names are added all the time, it would be difficult to keep this list up to date. You may see the list at website.

1-byte Special Characters

With ISO-8859-1 (not UTF-8), certain characters will be replaced with longer character sequences at compile-time.

Àl+',')

Will be converted to:

x.l(#+',')

A full list of these can be found in the properties json file, here (line 68).

Compilers / Interpreters