- Notifications
You must be signed in to change notification settings - Fork2
Jet is a simple OOP, dynamically typed, functional language that runs on the Erlang virtual machine (BEAM). Jet's syntax is Ruby-like syntax.
License
NotificationsYou must be signed in to change notification settings
i2y/jet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
"I thought of objects being like biological cells and/or individualcomputers 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 theErlang virtual machine (BEAM).Jet's syntax isRuby-like syntax.Jet was inspired byReia andCelluloid.
### Numbers49# integer4.9# float### Booleanstruefalse### Atoms:foo### Listslist=[2,3,4]list2=[1, *list]# => [1, 2, 3, 4][1,2,3, *rest]=list2rest# => [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 *2forninlist]# => [4, 6, 8]### Tuplestuple={1,2,3}tuple.select{|item|item >1}.map{|item|item *2}# => [4, 6]tuple.to_list# => [1, 2, 3]### Mapsdict={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 *yendmultiply(7,7)# => 49### Binaries<<1,2,3>><<"abc">><<1 , 2, x>> = <<1, 2, 3>>x # => 3
Car.jet
ModuleCarclassCar# On jet, state of an instance is immutable.# The initialize method returns initial state of an instance.definitialize(){name:"foo",speed:100}enddefdisplay()@name.display()@speed.display()endendend
Enumerable.jet
moduleEnumerabledefselect(func)reduce([]){|item,acc|iffunc.(item)acc ++[item]elseaccend}enddeffilter(func)reduce([]){|item,acc|iffunc.(item)acc ++[item]elseaccend}enddefreject(func)reduce([]){|item,acc|iffunc.(item)accelseacc ++[item]end}enddefmap(func)reduce([]){|item,acc|acc ++[func.(item)]}enddefcollect(func)reduce([]){|item,acc|acc ++[func.(item)]}enddefmin(func)reduce(:infinity){|item,acc|matchfunc.(acc,item)case -10case00case1itemend}enddefmin()reduce(:infinity){|item,acc|ifacc <=itemaccelseitemend}enddefunique()reduce([]){|item,acc|ifacc.index_of(item)accelseacc ++[item]end}enddefeach(func)reduce([]){|item,acc|func.(item)}endend
SampleList.jet
moduleSampleListclassSampleListincludeEnumerabledefinitialize(items){items:items}enddefreduce(acc,func)lists::foldl(func,acc,@items)endendend
sample_list=SampleList::SampleList.new([1,2,3])sample_list.select{|item|item >1}.map{|item|item *2}# => [4, 6]
- Tail recursion optimization
- Pattern matching
- Class inheritance
- Macro definition
- Erlang/OTP >= 18.0
- Elixir >= 1.1
$ git clone https://github.com/i2y/jet.git$cd jet$ mix archive.build$ mix archive.install$ mix escript.build$ cp jet<any path>
Compiling:
$ lsFoo.jet$ jet Foo.jet$ lsFoo.beam Foo.jet
Compiling and Executing:
$ cat Foo.jetmodule Foo defself.bar()123.display() endend$ jet -r Foo::bar Foo.jet123
mix.exs file example:
defmoduleMyApp.MixfiledouseMix.Projectdefprojectdo[app::my_app,version:"1.0.0",compilers:[:jet|Mix.compilers],deps:[{:jet,git:"https://github.com/i2y/jet.git"}]]endend
".jet" files in source directory(src) is automatically compiled by mix command.