Steel
Strongly Typed Experimental Expressive Language
Language that transpile to TypeScript and JavaScript.
Steel is a bootstraped language. That means the code itself is developed in Steel.
Check ./src folder for steel sources. Check ./lib for the compiled sources.
Highly inspired from LiveScript.
Goals
This language tries to implement strong static typing over a subset of Livescript.
To do so, it transpile first to TypeScript, and let it transpile to Javascript. This allow to use the power of a well typed and designed language while smoothing its syntax.
It alse tries not to fall into the same 'over-simplification' Livescript does, and avoid to implement features complexifying the read and understanding of the code.
At term, this language aim to be more functional, and might borrow some concepts from language like Haskell or Ocaml (custom operator?, immutability?, infinite lists?, ...).
Exemples
Basics
import fs path: { resolve } './localFile' './localFile2': customName foo := number -> number -> numberfoo = (a, b) -> a + b bar = (c: number, d: number): number ~> if c? and d? and d isnt 0 c + d else 0 nonReturning = !-> 1 map = <T>(f: (x: T): T, arr: T[]): T[] --> arr.map ffilter = <T>(f: (x: T): T, arr: T[]): T[] --> arr.filter f [1, 2, 3] |> map (+ 2) |> filter (> 2) class Animal a: 1 b: -> 2 constructor: (val: number) -> @a = val class Dog: Animal dog: Dog = new Dog 1
Transpiled in TypeScript with sc -cts source.s
turns into:
;
Install
npm install -g steel-lang
Compiler usage
Compiler name is sc
, and stands for Steel Compiler
.
Usage
$> sc -h Usage: sc [options] <files ...> Options: -V, --version output the version number -c, --compile Compile files -p, --print Print files -o, --output <folder> File/folder of output -s, --strict Disallow implicit use of <Any> type -t, --typescript Output Typescript instead of Javascript -b, --bare Dont wrap into top level anonymous function -q, --quiet Dont output types errors/warnings -h, --help output usage information
Compile and execute on the fly
sc file.s
You can only compile and execute single file on the fly
Files extensions are .s
.
This extension is registered inside NodeJS when loading steel-lang
to auto-compile steel files on the fly when required.
This means you can write
;const obj = ;
Compile a file/folder
sc -c file1.s file2.ssc -c folder/*.ssc -c folder/**/*.s
The format of the path is the same as for gulp. If you want to compile recursively or exclude some folders for exemple.
Compile to a diferent output
sc -o dir -c file1.s file2.ssc -o dir -c folder/*.s
Will output compiled files into dir
folder.
If the folder doesnt exists, it is created on the fly.
The arborescence is recreated if a folder is recursively compiled.
Features
-
Indent based language
if a is baelseb -
Variable declaration
foo = 1bar = -> 2 -
Inline type declaration
foo: number = 1bar = (a: number, b: number): number -> a + b -
Externalized type declaration
foo := numberfoo = 1bar := number -> number -> numberbar = (a, b) -> a + b -
Function declaration
-
Standard function
foo = (a, b) -> a + b -
Arrow function
foo = (a, b) ~> a + b -
Last statement is returned (can be disabled by '!')
foo = (a, b) -> a + b# bar does not return its resultbar = (a, b) !-> a + b -
Argument types
foo = (a:number, b: number):number -> a + b
-
-
Function call
-
with parentheses
foo(1, 'a', var1) -
with spaces
foo 1, 'a', var1 -
with '!' for no arguments
foo()# same asfoo!
-
-
Generics
map = <T>(f: any, arr: T[]): T[] -> arr.map fmap (+ 2), [1, 2, 3] -
Curry operator
# Exists for arrow function : '~~>'add = (a, b) --> a + badd5 = add 5add5 5 # === 10 -
Auto add argument 'it' when only one
a = -> it + 2a 2 # === 4 -
Shorthand function declaration
add2 = (+ 2)add2 2 # === 4obj = a: 1getA = (.a)getA obj # === 1 -
Chained calls
[1, 2, 3]|> map (+ 2)|> filter (> 2) -
Objects
obj1 = {}obj1 = { a: 1 }obj1 = a: 1, b: variable, c: -> 3, d: e: 4obj2 =a: 1b: variablec: -> 3d:e: 4 -
Object usage
obj.a.b(a.b).1.c!.f 1, 2 .d -
Array
arr = [1, 2, 3] -
Class
class Animalwalk: -> 1class Dog: Animala: 1walk: -> super.walk! + 1 -
Interface
interface Testa: numberb?: string -
If / Else
if a is baelseb -
For / While
while a < ba = a + 1for i = 0; i < 10; i++console.log i -
Try / Catch
trya = JSON.parse foocatch econsole.error e -
'not' stands for '!'
-
'?' for existance checks (!= null)
-
'is / isnt' become '=== / !=='
-
'and / or' become '&& / ||'
-
Arithmetic operations
-
Import
importfslodash: _path: { resolve }'./foo/bar'Become
;;;;;You can use
require
instead ofimport
to make a regular require
TODO:
- fix bug with $curry that swallows arguments type
- generics specification on func call (map(f, arr))
- decimals
- return loops
- typeof, delete, instanceof, ...
- Exports
- Expression as assignable (if, while, ...)
- implements
- Class visibility (public, private,...)
- class static
- Class types for methods and properties
- cast
- Generics
- readonly for interface
- propname for interface
- index for interface
- func type for interface
- abstract
- Transpile code in template strings
- Better error system (more details, more accuracy)
- Std lib
- Multiline string
- Better error management for on-the-fly compilation (get rid of typescript-simple)
- Import native (through options)
- Add tests for
- Operation
- Existance
- Function shorthand
- Import native
- Full compile
- Comments
- Generics / array type
- Support tsconfig.json
- (Plugin system ?)
- |< operator for chained call with flipped arguments