The Erg Programming Language
This is the main source code repository for Erg. This contains the compiler and documentation.
Erg can be recommended to a person that:
- wants Rust-like robustness and comfortable compiler support, and yet, doesn't need the verbose type specifications & memory management model like Rust.
- frustrated with Python, but can't throw away Python code assets.
- wants a simple and consistent language like ML.
- wants a practical general-purpose language with dependent/refinement types.
- wants a language like Scala that can be used both object-oriented and functional.
Features
Some features are not yet implemented. Please see TODO.md for implementation status.
-
Robustness
Erg has a smart & powerful type system. For example, Erg can do null checking (Option type), division by zero, and out-of-range addresses in arrays at compile time.
= = assert in # type checking assert in # more detailed = assert in assert + in # This causes an IndexError, Erg can detect it at compile time # IndexError: `l2` has 7 elements but was accessed the 11th element 2.! !: print! , : # => hello, hello, -2.! !: print! , : # TypeError: `.times!` is a method of `Nat` (0 or more Int), not `Int` = : , : = / = 3yard, 2sec # TypeError: the type of `x` was mismatched: expect `Meter`, found `Yard` = 3meter, 2sec # v == 1.5 m/s -
Simplicity
Erg consists of a very simple syntax, which can significantly reduce the amount of code compared to other languages. However, its functionality is not inferior to them.
Since the type inference system is powerful, you can code like a dynamically typed language.
0 = 0 1 = 1 = + assert == 55In Erg, there are very few things that are treated as special; there are no reserved words. even for and while expressions are just one of the subroutines, so this is possible.
! = # equals to `while! True, do! print! "hello"` ! !: print! -
Functional & Object-oriented
Erg is a pure object-oriented language. Everything is an object; types, functions, and operators are all objects. On the other hand, Erg is also a functional language. Erg requires some kinds of markers to be placed on code that causes side effects or changes internal state, which can localize the complexity of code. This will greatly improve the maintainability of your code.
# Functional style (immutable), same as `sorted(list)` in Python = assert == # Object-oriented style (mutable) = ! ! assert == = !1 ! -> + 1 assert == 2 # Functions cannot cause side effects : ! = ! -> + 1 # SyntaxError: cannot call a procedural method in a function # hint: only methods of mutable types can change the state of objects # Code that uses a lot of side effects is redundant, so you will naturally write pure code ! = ! !. : = !:: ! ! ! = ! -> + 1 = !. 1 ! assert == 2 -
Interoperability
Erg is internally compatible with Python and can import the Python API at zero cost.
# using built-in Python modules , = , = # using an external Python module ! = . print! # 1.2246467991473532e-16 ! 0.01 * -
Readable Error Messages
Erg emphasizes the readability of error messages; Erg is a programmer-friendly language,
unlike C++.! = = !Error[#12]: File example.er, line 3, in <module>::proc! 2│ l = [1, 2, 3] 3│ l.push!(x) ^^^^^ AttributeError: Array object has no attribute `.push!` hint: to update the internal state of an object, make it mutable by using `!` operator hint: `Array` has `push`, see https://erg-lang.github.io/docs/prelude/Array/##push for more information hint: `Array!` has `push!`, see https://erg-lang.github.io/docs/prelude/Array!/##push! for more information
Requirements
A Python3 interpreter is required. If it is already installed on your machine, no setup is required.
Installation
Installing by cargo (Rust package manager)
By enabling the --features flag, you can change the language in which error messages are displayed.
- Japanese
- Chinese (Simplified)
- Chinese (Traditional)
And more languages will be added (we are looking for translators. Please join the Translation Project).
- Debugging mode (for contributors)
Building from source
Building from source code requires the Rust toolchain.
Building by Nix
If you've been installed Nix, the following command will be generate binary into result/bin/erg under the project.
If you've been enabled Nix Flakes.
Contribution
Contributions are always welcome! To get started with contributions, please look CONTRIBUTING.md.
If you have any questions, please feel free to ask them on the Discord channel.
License
All files in the CODE_OF_CONDUCT, assets and doc folders are licensed with CC-BY-4.0. The rest of the files in this repository are licensed with Apache License 2.0 + MIT License.
For credits about third party crates, see THIRD_PARTY_CREDITS.md.