Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/i2y/jet
Jet is a simple OOP, dynamically typed, functional language that runs on the Erlang virtual machine (BEAM). Jet's syntax is Ruby-like syntax.
https://github.com/i2y/jet
beam concurrent-programming distributed-computing erlang jet oop programming-language ruby
Last synced: 2 months ago
JSON representation
Jet is a simple OOP, dynamically typed, functional language that runs on the Erlang virtual machine (BEAM). Jet's syntax is Ruby-like syntax.
- Host: GitHub
- URL: https://github.com/i2y/jet
- Owner: i2y
- License: mit
- Created: 2016-04-19T03:59:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-10T20:28:04.000Z (over 7 years ago)
- Last Synced: 2024-04-21T09:33:05.642Z (9 months ago)
- Topics: beam, concurrent-programming, distributed-computing, erlang, jet, oop, programming-language, ruby
- Language: Elixir
- Homepage:
- Size: 188 KB
- Stars: 24
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> "I thought of objects being like biological cells and/or individual
> computers on a network, only able to communicate with messages"
> _--Alan Kay, creator of Smalltalk, on the meaning of "object oriented programming"_Jet is a simple OOP, dynamically typed, functional language that runs on the [Erlang](http://www.erlang.org) virtual machine (BEAM).
Jet's syntax is [Ruby](https://www.ruby-lang.org)-like syntax.
Jet was inspired by [Reia](https://github.com/tarcieri/reia) and [Celluloid](https://github.com/celluloid/celluloid).## Language features
### Builtin Types
```ruby
### Numbers49 # integer
4.9 # float### Booleans
true
false### Atoms
:foo
### Lists
list = [2, 3, 4]
list2 = [1, *list] # => [1, 2, 3, 4]
[1, 2, 3, *rest] = list2
rest # => [4]list.append(5) # => [2, 3, 4, 5]
list # => [2, 3, 4]list.select {|item| item > 2}
.map {|item| item * 2} # => [6, 8]
list # => [2, 3, 4]# list comprehensions
[n * 2 for n in list] # => [4, 6, 8]### Tuples
tuple = {1, 2, 3}
tuple.select {|item| item > 1}
.map {|item| item * 2} # => [4, 6]tuple.to_list # => [1, 2, 3]
### Maps
dict = {foo: 1, bar: 2}
dict2 = dict.put(:baz, 3) # => {foo: 1, bar: 2, baz: 3}
dict # => {foo: 1, bar: 2}
dict.get(:baz, 100) # => 100### Strings (Lists)
"Abc"
### Anonymous functions (Blocks)
add = {|x, y| x + y}
add(40, 9) # => 49multiply = do |x, y|
x * y
endmultiply(7, 7) # => 49
### Binaries
<<1, 2, 3>>
<<"abc">>
<<1 , 2, x>> = <<1, 2, 3>>
x # => 3```
### Class definition
Car.jet
```ruby
Module Car
class Car
# On jet, state of an instance is immutable.
# The initialize method returns initial state of an instance.
def initialize()
{name: "foo",
speed: 100}
end
def display()
@name.display()
@speed.display()
end
end
end
```### Module definition
Enumerable.jet
```ruby
module Enumerable
def select(func)
reduce([]) {|item, acc|
if func.(item)
acc ++ [item]
else
acc
end
}
enddef filter(func)
reduce([]) {|item, acc|
if func.(item)
acc ++ [item]
else
acc
end
}
enddef reject(func)
reduce([]) {|item, acc|
if func.(item)
acc
else
acc ++ [item]
end
}
enddef map(func)
reduce([]) {|item, acc|
acc ++ [func.(item)]
}
enddef collect(func)
reduce([]) {|item, acc|
acc ++ [func.(item)]
}
enddef min(func)
reduce(:infinity) {|item, acc|
match func.(acc, item)
case -1
0
case 0
0
case 1
item
end
}
enddef min()
reduce(:infinity) {|item, acc|
if acc <= item
acc
else
item
end
}
enddef unique()
reduce([]) {|item, acc|
if acc.index_of(item)
acc
else
acc ++ [item]
end
}
enddef each(func)
reduce([]) {|item, acc|
func.(item)
}
end
end
```### Mixing in Modules
SampleList.jet
```ruby
module SampleList
class SampleList
include Enumerable
def initialize(items)
{items: items}
end
def reduce(acc, func)
lists::foldl(func, acc, @items)
end
end
end
```### Trailing closures (Trailing blocks)
```ruby
sample_list = SampleList::SampleList.new([1, 2, 3])
sample_list.select {|item| item > 1}
.map {|item| item * 2}
# => [4, 6]
```### Other supported features
- Tail recursion optimization
- Pattern matching### Currently unsupported features
- Class inheritance
- Macro definition## Requirements
- Erlang/OTP >= 18.0
- Elixir >= 1.1## Installation
```sh
$ git clone https://github.com/i2y/jet.git
$ cd jet
$ mix archive.build
$ mix archive.install
$ mix escript.build
$ cp jet
```## Usage
### Command
Compiling:
```sh
$ ls
Foo.jet
$ jet Foo.jet
$ ls
Foo.beam Foo.jet
```Compiling and Executing:
```sh
$ cat Foo.jet
module Foo
def self.bar()
123.display()
end
end
$ jet -r Foo::bar Foo.jet
123
```### Mix
mix.exs file example:
```elixir
defmodule MyApp.Mixfile do
use Mix.Projectdef project do
[app: :my_app,
version: "1.0.0",
compilers: [:jet|Mix.compilers],
deps: [{:jet, git: "https://github.com/i2y/jet.git"}]]
end
end
```
".jet" files in source directory(src) is automatically compiled by mix command.