Coder Social home page Coder Social logo

erg-lang / erg Goto Github PK

View Code? Open in Web Editor NEW
2.6K 17.0 53.0 16.5 MB

A statically typed language compatible with Python

Home Page: http://erg-lang.org

License: Apache License 2.0

Rust 93.11% Python 6.81% Batchfile 0.01% Shell 0.01% Nix 0.06%
compiler programming-language python rust language erg transpiler

erg's Introduction

The Erg Programming Language


This is the main source code repository for Erg. This contains the compiler and documentation.

Build status Build status

日本語 | 简体中文 | 繁體中文

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.

  1. 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.

    rand = pyimport "random"
    
    l = [1, 2, 3]
    assert l in [Nat; 3] # type checking
    assert l in [1..3; 3] # more detailed
    l2 = l.push(rand.choice! 0..10)
    assert l2 in [0..10; 4]
    assert l2 + [3, 5, 7] in [0..10; 7]
    # This causes an IndexError, Erg can detect it at compile time
    l2[10] # IndexError: `l2` has 7 elements but was accessed the 11th element
    
    2.times! do!:
        print! "hello, ", end := ""
    # => hello, hello,
    -2.times! do!:
        print! "hello, ", end := ""
    # TypeError: `.times!` is a method of `Nat` (0 or more Int), not `Int`
    
    {Meter; Sec; meter; yard; sec} = import "unit"
    
    velocity x: Meter, t: Sec = x / t
    
    v = velocity 3yard, 2sec # TypeError: the type of `x` was mismatched: expect `Meter`, found `Yard`
    v = velocity 3meter, 2sec # v == 1.5 m/s
  2. 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.

    fib 0 = 0
    fib 1 = 1
    fib n = fib(n - 1) + fib(n - 2)
    assert fib(10) == 55

    Even for and while expressions are just one of the subroutines, so this is possible.

    loop! block! = while! do! True, block!
    
    # equals to `while! do(True), do! print! "hello"`
    loop! do!:
        print! "hello"
  3. 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
    immut_arr = [1, 3, 2]
    assert immut_arr.sort() == [1, 2, 3]
    # Object-oriented style (mutable)
    mut_arr = ![1, 3, 2]
    mut_arr.sort!()
    assert mut_arr == [1, 2, 3]
    i = !1
    i.update! old -> old + 1
    assert i == 2
    
    # Functions cannot cause side effects
    inc i: Int! =
        i.update! old -> old + 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
    Counter! = Inherit Int!
    Counter!.
        new i: Int = Counter! !i
        inc! ref! self =
            self.update! old -> old + 1
    
    c = Counter!.new 1
    c.inc!()
    assert c == 2
  4. Interoperability

    Erg is internally compatible with Python and can import the Python API at zero cost.

    # using built-in Python modules
    math, time = pyimport "math", "time"
    {sin; pi} = math
    # using an external Python module
    tqdm = pyimport "tqdm"
    
    print! sin pi # 1.2246467991473532e-16
    for! tqdm.tqdm(0..99), i =>
        time.sleep! 0.01 * i
  5. Readable Error Messages

    Erg emphasizes the readability of error messages; Erg is a programmer-friendly language, unlike C++.

    proc! x =
        l = [1, 2, 3]
        l.push!(x)
        l
    Error[#12]: File example.er, line 3, in <module>::proc!
    2│     l = [1, 2, 3]
    3│     l.push!(x)
             ^^^^^
    AttributeError: List object has no attribute `.push!`
    hint: to update the internal state of an object, make it mutable by using `!` operator
    hint: `List` has `push`, see https://erg-lang.github.io/docs/prelude/List/##push for more information
    hint: `List!` has `push!`, see https://erg-lang.github.io/docs/prelude/List!/##push! for more information

Requirements

A Python3 (3.7~3.11) interpreter is required. If it is already installed on your machine, no setup is required.

Installation

Installing by cargo (Rust package manager)

cargo install erg

Building from source

Building from source code requires the Rust toolchain.

git clone https://github.com/erg-lang/erg.git
cd erg
cargo build --release

Building by Nix

If you've been installed Nix, the following command will be generate binary into result/bin/erg under the project.

git clone https://github.com/erg-lang/erg.git
cd erg
nix-build

If you've been enabled Nix Flakes.

git clone https://github.com/erg-lang/erg.git
cd erg
nix build

Flags

By enabling the --features flag, you can customize the installation and build.

  • You can change the language of the error message by using --features {language}
--features japanese
--features simplified_chinese
--features traditional_chinese

And more languages will be added (we are looking for translators. Please join the Translation Project).

Other flags:

  • Install and build ELS (Erg Language Server)
    • --features els
  • Debugging mode (for contributors)
    • --features debug
  • Rich REPL experience (cursor movement, pasting, history, etc.)
    • --features full-repl
  • Makes the display look better
    • --features unicode and --features pretty
  • Enable all features (exclude features for developers)
    • --features full
  • See here for more flags.

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 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.

erg's People

Contributors

anzhi0708 avatar buster-blue avatar c-bj avatar cclauss avatar estin avatar github-actions[bot] avatar greasyslug avatar hanaasagi avatar itsliamdowd avatar jonatan1609 avatar kisaragieffective avatar mtshiba avatar passcod avatar pingiun avatar shantanukumar avatar sno2wman avatar soukouki avatar tako8ki avatar toddlerer avatar ytoml avatar yuk1ty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

erg's Issues

Configure `cargo fmt` and `cargo clippy`

Currently, this project does not seem to utilize cargo fmt and cargo clippy, which would be important in near future.

I tried executing cargo fmt for all crates, and produced a huge amount of diff.
Git features, like git blame, are not good at handling formatting differences, so I suggest we format everything before it's too late.

This issue depends on #4 . cargo fmt did not format everything when current directory is on root because workspace feature is not utilized.

Crash with file input

Reproducible command:

> cargo run --features debug examples/helloworld.er

Error log:

compiler\erg_compiler\compile.rs:160: [DEBUG] the compiling process has started.
compiler\erg_parser\parse.rs:325: [DEBUG] the parsing process has started.
compiler\erg_parser\parse.rs:326: token stream: [Symbol print!, StrLit "Hello, world!", Newline \n, Symbol print!, StrLit "こんにちは、世界!", Newline \n, Symbol print!, StrLit "Γειά σου Κόσμε!", Newline \n, Symbol print!, StrLit "!مرحبا بالعالم", Newline \n, Newline \n, Symbol greeting, Equal =, StrLit "Hello", Newline \n, Symbol print!, StrLit "{greeting}, world!", Newline \n, EOF ]
compiler\erg_parser\parse.rs:358: [DEBUG] entered try_reduce_module, cur: Symbol print!
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol print!
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: Symbol print!
compiler\erg_parser\parse.rs:1433: [DEBUG] entered try_reduce_call_or_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:604: [DEBUG] entered try_reduce_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:1068: [DEBUG] entered opt_reduce_args, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1097: [DEBUG] entered try_reduce_args, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1195: [DEBUG] entered try_reduce_arg, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "Hello, world!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol print!
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: Symbol print!
compiler\erg_parser\parse.rs:1433: [DEBUG] entered try_reduce_call_or_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:604: [DEBUG] entered try_reduce_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:1068: [DEBUG] entered opt_reduce_args, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1097: [DEBUG] entered try_reduce_args, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1195: [DEBUG] entered try_reduce_arg, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "こんにちは、世界!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol print!
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: Symbol print!
compiler\erg_parser\parse.rs:1433: [DEBUG] entered try_reduce_call_or_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:604: [DEBUG] entered try_reduce_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:1068: [DEBUG] entered opt_reduce_args, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1097: [DEBUG] entered try_reduce_args, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1195: [DEBUG] entered try_reduce_arg, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "Γειά σου Κόσμε!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol print!
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: Symbol print!
compiler\erg_parser\parse.rs:1433: [DEBUG] entered try_reduce_call_or_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:604: [DEBUG] entered try_reduce_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:1068: [DEBUG] entered opt_reduce_args, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1097: [DEBUG] entered try_reduce_args, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1195: [DEBUG] entered try_reduce_arg, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "!مرحبا بالعالم"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol greeting
compiler\erg_parser\parse.rs:472: [DEBUG] entered try_reduce_decl, cur: Symbol greeting
compiler\erg_parser\parse.rs:1484: [DEBUG] entered try_reduce_name, cur: Symbol greeting
compiler\erg_parser\parse.rs:684: [DEBUG] entered opt_reduce_params, cur: Equal =
compiler\erg_parser\parse.rs:386: [DEBUG] entered try_reduce_block, cur: StrLit "Hello"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "Hello"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "Hello"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "Hello"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: Symbol print!
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: Symbol print!
compiler\erg_parser\parse.rs:1433: [DEBUG] entered try_reduce_call_or_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:604: [DEBUG] entered try_reduce_acc, cur: Symbol print!
compiler\erg_parser\parse.rs:1068: [DEBUG] entered opt_reduce_args, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:1097: [DEBUG] entered try_reduce_args, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:1195: [DEBUG] entered try_reduce_arg, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:1254: [DEBUG] entered try_reduce_expr, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:1397: [DEBUG] entered try_reduce_lhs, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:1493: [DEBUG] entered try_reduce_lit, cur: StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:340: [DEBUG] the parsing process has completed.
compiler\erg_parser\parse.rs:341: AST:
(print!):
    StrLit "Hello, world!"
(print!):
    StrLit "こんにちは、世界!"
(print!):
    StrLit "Γειά σου Κόσμε!"
(print!):
    StrLit "!مرحبا بالعالم"
greeting =
    StrLit "Hello"
(print!):
    StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:342: [DEBUG] the desugaring process has started.
compiler\erg_parser\parse.rs:345: AST (desugared):
(print!):
    StrLit "Hello, world!"
(print!):
    StrLit "こんにちは、世界!"
(print!):
    StrLit "Γειά σου Κόσμε!"
(print!):
    StrLit "!مرحبا بالعالم"
greeting =
    StrLit "Hello"
(print!):
    StrLit "{greeting}, world!"
compiler\erg_parser\parse.rs:346: [DEBUG] the desugaring process has completed.
compiler\erg_compiler\lower.rs:387: [DEBUG] the type-checking process has started.
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:163: [DEBUG] entered lower_call(print!(...))
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:110: [DEBUG] entered lower_acc(print!)
compiler\erg_compiler\context.rs:3052: Found:
callee: print!
found: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3054: Instantiated:
instance: (objs: ...Ref(Obj)) => None
pos_args: (StrLit "Hello, world!")
kw_args: ()
compiler\erg_compiler\context.rs:3060: Substituted:
instance: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3062: Derefed:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3064: Params Evaluated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3066: Derefed (2):
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3068: Propagated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:163: [DEBUG] entered lower_call(print!(...))
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:110: [DEBUG] entered lower_acc(print!)
compiler\erg_compiler\context.rs:3052: Found:
callee: print!
found: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3054: Instantiated:
instance: (objs: ...Ref(Obj)) => None
pos_args: (StrLit "こんにちは、世界!")
kw_args: ()
compiler\erg_compiler\context.rs:3060: Substituted:
instance: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3062: Derefed:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3064: Params Evaluated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3066: Derefed (2):
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3068: Propagated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:163: [DEBUG] entered lower_call(print!(...))
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:110: [DEBUG] entered lower_acc(print!)
compiler\erg_compiler\context.rs:3052: Found:
callee: print!
found: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3054: Instantiated:
instance: (objs: ...Ref(Obj)) => None
pos_args: (StrLit "Γειά σου Κόσμε!")
kw_args: ()
compiler\erg_compiler\context.rs:3060: Substituted:
instance: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3062: Derefed:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3064: Params Evaluated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3066: Derefed (2):
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3068: Propagated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:163: [DEBUG] entered lower_call(print!(...))
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:110: [DEBUG] entered lower_acc(print!)
compiler\erg_compiler\context.rs:3052: Found:
callee: print!
found: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3054: Instantiated:
instance: (objs: ...Ref(Obj)) => None
pos_args: (StrLit "!مرحبا بالعالم")
kw_args: ()
compiler\erg_compiler\context.rs:3060: Substituted:
instance: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3062: Derefed:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3064: Params Evaluated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3066: Derefed (2):
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3068: Propagated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:255: [DEBUG] entered lower_def(greeting)
compiler\erg_compiler\context.rs:3942: grow: current namespace: <module>::greeting
compiler\erg_compiler\lower.rs:273: [DEBUG] entered lower_var_def(greeting)
compiler\erg_compiler\lower.rs:377: [DEBUG] entered lower_block
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\context.rs:3961: pop: current namespace: <module>
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:163: [DEBUG] entered lower_call(print!(...))
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:362: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:110: [DEBUG] entered lower_acc(print!)
compiler\erg_compiler\context.rs:3052: Found:
callee: print!
found: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3054: Instantiated:
instance: (objs: ...Ref(Obj)) => None
pos_args: (StrLit "{greeting}, world!")
kw_args: ()
compiler\erg_compiler\context.rs:3060: Substituted:
instance: (objs: ...Ref(Obj)) => None
compiler\erg_compiler\context.rs:3062: Derefed:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3064: Params Evaluated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3066: Derefed (2):
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\context.rs:3068: Propagated:
res: (objs: ...Ref(Obj)) => None

compiler\erg_compiler\lower.rs:405: [DEBUG] lower() has completed, found errors: 0
compiler\erg_compiler\lower.rs:411: HIR:
(print!): (objs: ...Ref(Obj)) => None:
    StrLit "Hello, world!"
(print!): (objs: ...Ref(Obj)) => None:
    StrLit "こんにちは、世界!"
(print!): (objs: ...Ref(Obj)) => None:
    StrLit "Γειά σου Κόσμε!"
(print!): (objs: ...Ref(Obj)) => None:
    StrLit "!مرحبا بالعالم"
greeting (: {%v16: Str | %v16 == "Hello"}) =
    StrLit "Hello"
(print!): (objs: ...Ref(Obj)) => None:
    StrLit "{greeting}, world!"
compiler\erg_compiler\lower.rs:412: [DEBUG] the type-checking process has completed.
compiler\erg_compiler\effectcheck.rs:43: [DEBUG] the side-effect checking process has started.
compiler\erg_compiler\effectcheck.rs:69: [DEBUG] the side-effect checking process has completed, found errors: 0
compiler\erg_compiler\ownercheck.rs:59: [DEBUG] the ownership checking process has started.
compiler\erg_compiler\ownercheck.rs:66: [DEBUG] the ownership checking process has completed, found errors: 0
compiler\erg_compiler\codegen.rs:1217: [DEBUG] the code-generating process has started.
compiler\erg_compiler\codegen.rs:1280: [DEBUG] the code-generating process has completed.
compiler\erg_compiler\compile.rs:195: code object:
Disassembly of <code object <module> at 0xfe1c6fd6b8, file "examples/helloworld.er", line 1>:
Name:              <module>
FileName:          examples/helloworld.er
Argument count:    0
Positional-only arguments: 0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:             NoFree
Constants:
   0: "Hello, world!"
   1: "こんにちは、世界!"
   2: "Γειά σου Κόσμε!"
   3: "!مرحبا بالعالم"
   4: "Hello"
   5: "{greeting}, world!"
Names:
   0: print
   1: print
   2: print
   3: print
   4: greeting
   5: print
lnotab: [8, 1, 8, 1, 8, 1, 8, 2, 4, 1]
1:
              0 LOAD_NAME                0 (print)
              2 LOAD_CONST               0 ("Hello, world!")
              4 CALL_FUNCTION            1
              6 POP_TOP
2:
              8 LOAD_NAME                1 (print)
             10 LOAD_CONST               1 ("こんにちは、世界!")
             12 CALL_FUNCTION            1
             14 POP_TOP
3:
             16 LOAD_NAME                2 (print)
             18 LOAD_CONST               2 ("Γειά σου Κόσμε!")
             20 CALL_FUNCTION            1
             22 POP_TOP
4:
             24 LOAD_NAME                3 (print)
             26 LOAD_CONST               3 ("!مرحبا بالعالم")
             28 CALL_FUNCTION            1
             30 POP_TOP
6:
             32 LOAD_CONST               4 ("Hello")
             34 STORE_NAME               4 (greeting)
7:
             36 LOAD_NAME                5 (print)
             38 LOAD_CONST               5 ("{greeting}, world!")
             40 CALL_FUNCTION            1
             42 RETURN_VALUE


compiler\erg_compiler\compile.rs:196: [DEBUG] the compiling process has completed, found errors: 0
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src\dummy.rs:88:50
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:142
   2: core::panicking::panic
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:48
   3: enum$<core::option::Option<ref_mut$<std::net::tcp::TcpStream> >, 1, 18446744073709551615, Some>::unwrap<ref_mut$<std::net::tcp::TcpStream> >
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f\library\core\src\option.rs:775
   4: erg::dummy::impl$0::eval
             at .\src\dummy.rs:88
   5: erg_common::traits::Runnable::run<erg::dummy::DummyVM>
             at .\compiler\erg_common\traits.rs:333
   6: erg::main
             at .\src\main.rs:31
   7: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f\library\core\src\ops\function.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\erg.exe examples/helloworld.er` (exit code: 101)

One-step exit from REPL

Now - causes the REPL to exit unexpectedly and directly, which is a bug, but can be borrowed for one-step exit from the REPL

`log` funtion does not accept variable length arguments

Describe the bug
log syntax/04_function.md

Reproducible code

Erg interpreter 0.2.8 (tags/?:, 2022/08/25 23:56:48) on aarch64/macos

>>> log "Hello"
Hello
None

>>> log "Hello", "World"
Error[#1549]: File <stdin>, line 1, in <module>
1│ log "Hello", "World"

   ^^^
TypeError: too many arguments for log:
total expected params:  1
passed positional args: 2
passed keyword args:    0

Expected behavior
Expected that it printsHello World.

Cannot infer an array type

Reproducible code:

a = [1, 2]

Error log:

compiler\erg_compiler\compile.rs:164: [DEBUG] the compiling process has started.
compiler\erg_parser\parse.rs:327: [DEBUG] the parsing process has started.
compiler\erg_parser\parse.rs:328: token stream: [Symbol a, Equal =, LSqBr [, NatLit 1, Comma ,, NatLit 2, RSqBr ], EOF ]
compiler\erg_parser\parse.rs:360: [DEBUG] entered try_reduce_module, cur: Symbol a
compiler\erg_parser\parse.rs:1248: [DEBUG] entered try_reduce_expr, cur: Symbol a
compiler\erg_parser\parse.rs:467: [DEBUG] entered try_reduce_decl, cur: Symbol a
compiler\erg_parser\parse.rs:1478: [DEBUG] entered try_reduce_name, cur: Symbol a
compiler\erg_parser\parse.rs:678: [DEBUG] entered opt_reduce_params, cur: Equal =
compiler\erg_parser\parse.rs:388: [DEBUG] entered try_reduce_block, cur: LSqBr [
compiler\erg_parser\parse.rs:1248: [DEBUG] entered try_reduce_expr, cur: LSqBr [
compiler\erg_parser\parse.rs:1391: [DEBUG] entered try_reduce_lhs, cur: LSqBr [
compiler\erg_parser\parse.rs:1465: [DEBUG] entered try_reduce_array, cur: LSqBr [
compiler\erg_parser\parse.rs:1091: [DEBUG] entered try_reduce_args, cur: NatLit 1
compiler\erg_parser\parse.rs:1189: [DEBUG] entered try_reduce_arg, cur: NatLit 1
compiler\erg_parser\parse.rs:1248: [DEBUG] entered try_reduce_expr, cur: NatLit 1
compiler\erg_parser\parse.rs:1391: [DEBUG] entered try_reduce_lhs, cur: NatLit 1
compiler\erg_parser\parse.rs:1487: [DEBUG] entered try_reduce_lit, cur: NatLit 1
compiler\erg_parser\parse.rs:1189: [DEBUG] entered try_reduce_arg, cur: NatLit 2
compiler\erg_parser\parse.rs:1248: [DEBUG] entered try_reduce_expr, cur: NatLit 2
compiler\erg_parser\parse.rs:1391: [DEBUG] entered try_reduce_lhs, cur: NatLit 2
compiler\erg_parser\parse.rs:1487: [DEBUG] entered try_reduce_lit, cur: NatLit 2
compiler\erg_parser\parse.rs:342: [DEBUG] the parsing process has completed.
compiler\erg_parser\parse.rs:343: AST:
a =
    [NatLit 1
NatLit 2]
compiler\erg_parser\parse.rs:344: [DEBUG] the desugaring process has started.
compiler\erg_parser\parse.rs:347: AST (desugared):
a =
    [NatLit 1
NatLit 2]
compiler\erg_parser\parse.rs:348: [DEBUG] the desugaring process has completed.
compiler\erg_compiler\lower.rs:381: [DEBUG] the type-checking process has started.
compiler\erg_compiler\lower.rs:356: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:249: [DEBUG] entered lower_def(a)
compiler\erg_compiler\context.rs:3942: grow: current namespace: <module>::a
compiler\erg_compiler\lower.rs:267: [DEBUG] entered lower_var_def(a)
compiler\erg_compiler\lower.rs:371: [DEBUG] entered lower_block
compiler\erg_compiler\lower.rs:356: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:88: [DEBUG] entered lower_array([NatLit 1
NatLit 2])
compiler\erg_compiler\lower.rs:356: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:356: [DEBUG] entered lower_expr
compiler\erg_compiler\context.rs:3961: pop: current namespace: <module>
compiler\erg_compiler\lower.rs:398: HIR (not derefed):
a (: Array(?1(: Type)[1], 0)) =
    [NatLit 1
NatLit 2]
compiler\erg_compiler\context.rs:1804: ### Array(?1(: Type)[1], 0)
compiler\erg_compiler\context.rs:1627: Type(FreeVar(Free(RcCell(RefCell { value: Unbound { id: 1, lev: 1, constraint: TypeOf(Type) } }))))
Error[#1695]: File <stdin>
?│ a = [1, 2]

CompilerSystemError: this is a bug of Erg, please report it to https://github.com/...
caused from: deref_tyvar:1695

Erg chat

There should be an IRC, Matrix, or Gitter chat for Erg to be discussed.

Put a badge on all translated documents

Continuation from #48.

A badge indicating the translation status should be attached to all translated documents.

The format of the badge is as follows.

[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3{ORIGINAL_FILE_NAME}%26commit_hash%3D{ORIGINAL_COMMIT_HASH})
](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path={ORIGINAL_FILE_NAME}&commit_hash={ORIGINAL_COMMIT_HASH})

Replace {ORIGINAL_FILE_NAME} and {ORIGINAL_COMMIT_HASH} with the appropriate ones.

As an example, here is the badge of README_zh-CN.md. The original one is README.md.
{ORIGINAL_FILE_NAME} = README.md
{ORIGINAL_HASH} = 47b9b75
The result is as follows.

[![badge](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fgezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com%2Fdefault%2Fsource_up_to_date%3Fowner%3Derg-lang%26repos%3Derg%26ref%3Dmain%26path%3DREADME.md%26commit_hash%3D47b9b758acea9d4ea5d618436935b197636074f6)
](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=README.md&commit_hash=47b9b758acea9d4ea5d618436935b197636074f6)

The badge should be placed directly below the document title.

The documents under doc/EN are the ones I have not yet finished putting badges on. The original is located under doc/JA.

The REPL input contains special symbols, causing the program to crash

The inclusion of some symbols in the input of REPL can cause the program to crash, or the cumulative inclusion of another type of symbol twice in a different input can also cause the program to crash(line breaks fall into this category).

+ and - Belongs to the first category

In Windows, panicked at python not found

Python3

version 3.10.4

I tried

git clone url
cargo run

Error log

Starting the REPL server...
thread 'main' panicked at 'cannot execute python: Error { kind: NotFound, message: "program not found" }', compiler\erg_common\python_util.rs:114:14
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
error: process didn't exit successfully: target\debug\erg.exe (exit code: 101)

I think that cmd, powershll and PowerShell have no which command

So I recommend this crate https://docs.rs/which/latest/which/

Script input from pipeline

$ echo "1+2" | ./erg
Erg 0.1.0 (tags/?:8a62e0f, 2021/09/13 17:11:40.30) on x86_64/windows
Type "help!()", "copyright", "credits" or "license" for more information.
'>>>' 3
'>>>'

When I try to pass a script from the pipeline, I get this message: it seems to start in REPL mode.
I don't know how to distinguish between the stdin types in Rust.

REPL status is not saved

>>> i = 0

>>> print! i
Traceback (most recent call last):
  File "<stdin>", line -1, in <module>
NameError: name 'i' is not defined. Did you mean: 'id'?

Dict is not implemented

Reproducible code:

> erg examples/dict.er

Result:

thread 'main' panicked at 'not yet implemented', C:\Users\sbym8\.cargo\registry\src\github.com-1ecc6299db9ec823\erg_parser-0.2.4\parse.rs:1425:17
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

`if True, ...` doesn't work

Reproducible code

>>> if True, do:
...   log 1

Expected behavior
prints 1.

Result

...
Traceback (most recent call last):
  File "<string>", line 28, in <module>
  File "<string>", line 1, in <module>
  File "<stdin>", line -1, in <module>
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 32, in <module>
NameError: name 'e' is not defined

>>>

Error in type variable instantiation

Reproducible code:

i = 1 + 1

Error log:

compiler\erg_compiler\compile.rs:160: [DEBUG] the compiling process has started.
compiler\erg_parser\parse.rs:325: [DEBUG] the parsing process has started.
compiler\erg_parser\parse.rs:326: token stream: [Symbol i, Equal =, NatLit 1, Plus +, NatLit 1, EOF ]
compiler\erg_parser\parse.rs:358: [DEBUG] entered try_reduce_module, cur: Symbol i
compiler\erg_parser\parse.rs:1252: [DEBUG] entered try_reduce_expr, cur: Symbol i
compiler\erg_parser\parse.rs:472: [DEBUG] entered try_reduce_decl, cur: Symbol i
compiler\erg_parser\parse.rs:1482: [DEBUG] entered try_reduce_name, cur: Symbol i
compiler\erg_parser\parse.rs:686: [DEBUG] entered opt_reduce_params, cur: Equal =
compiler\erg_parser\parse.rs:386: [DEBUG] entered try_reduce_block, cur: NatLit 1
compiler\erg_parser\parse.rs:1252: [DEBUG] entered try_reduce_expr, cur: NatLit 1
compiler\erg_parser\parse.rs:1395: [DEBUG] entered try_reduce_lhs, cur: NatLit 1
compiler\erg_parser\parse.rs:1491: [DEBUG] entered try_reduce_lit, cur: NatLit 1
compiler\erg_parser\parse.rs:1395: [DEBUG] entered try_reduce_lhs, cur: NatLit 1
compiler\erg_parser\parse.rs:1491: [DEBUG] entered try_reduce_lit, cur: NatLit 1
compiler\erg_parser\parse.rs:340: [DEBUG] the parsing process has completed.
compiler\erg_parser\parse.rs:341: AST:
i =
    `+`:
        NatLit 1
        NatLit 1
compiler\erg_parser\parse.rs:342: [DEBUG] the desugaring process has started.
compiler\erg_parser\parse.rs:345: AST (desugared):
i =
    `+`:
        NatLit 1
        NatLit 1
compiler\erg_parser\parse.rs:346: [DEBUG] the desugaring process has completed.
compiler\erg_compiler\lower.rs:386: [DEBUG] the type-checking process has started.
compiler\erg_compiler\lower.rs:361: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:254: [DEBUG] entered lower_def(i)
compiler\erg_compiler\context.rs:3493: grow: current namespace: <module>::i
compiler\erg_compiler\lower.rs:272: [DEBUG] entered lower_var_def(i)
compiler\erg_compiler\lower.rs:376: [DEBUG] entered lower_block
compiler\erg_compiler\lower.rs:361: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:142: [DEBUG] entered lower_bin(`+`:
    NatLit 1
    NatLit 1)
compiler\erg_compiler\lower.rs:361: [DEBUG] entered lower_expr
compiler\erg_compiler\lower.rs:361: [DEBUG] entered lower_expr
compiler\erg_compiler\context.rs:2660: Found:
callee: __add__
found: |{'L <: Add('R, 'O), 'O: Type, 'R: Type}| ('L, 'R) -> 'O
thread 'main' panicked at 'not yet implemented', compiler\erg_compiler\context.rs:260:21
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:142
   2: core::panicking::panic
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library\core\src\panicking.rs:48
   3: erg_compiler::context::TyVarContext::instantiate_tp
             at .\compiler\erg_compiler\context.rs:260

...

  28: erg::main
             at .\src\main.rs:31
  29: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f\library\core\src\ops\function.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Traceback (most recent call last):
  File "<string>", line 17, in <module>
ConnectionAbortedError: [WinError 10053] 確立された接続がホスト コンピューターのソウトウェアによって中止されました。
error: process didn't exit successfully: `target\debug\erg.exe` (exit code: 101)

I have already pinpointed the cause.
It is due to the fact that during TyVarContext::new, there is an order dependency in the initialization of the type variable, yet it is ignored.

    pub fn new(level: usize, bounds: Set<TyBound>) -> Self {
        let mut self_ = Self {
            level,
            tyvar_instances: Dict::new(),
            typaram_instances: Dict::new(),
        };
        for bound in bounds.into_iter() { # this is wrong, the order should be sorted
            self_.instantiate_bound(bound);
        }
        } self_.
    }

We need to sort the type variables according to the order of dependencies.
Fortunately, I had a function in erg_common that does topological sorting, so this would be a quick fix.

Confused by apparently duplicate syntaxes (might just be a docs issue)

Hey! Erg looks really cool. However, my one big hesitancy with it from a language design perspective is that there are multiple endorsed ways to do the same thing that appear to not be consequences of composition of features. eg,

Functions can be declared in four different ways. None of them can omit the return type.

f(x: Int, y: Int): Int
f(Int, Int): Int
f: (x: Int, y: Int) -> Int
f: (Int, Int) -> Int

I'm not sure if I'm misunderstanding the docs here. Maybe there's some equivalence between : and -> that makes them related, and instead of remembering "there are several ways to write function definitions", I should remember "colon is usually optional on one line" or something along those lines.

it's also pretty unclear to me why these are equivalent:

functions are invoked like f x, y, ..., but if there are too many arguments for a single line, they can be applied using : (colon).

f arg1 + arg2, arg3 * arg4

f arg1 + arg2:
    arg3 * arg4

f:
    arg1 + arg2
    arg3 * arg4

coming from python, I would have expected this to either define a function with no arguments f(), or perhaps coming from yaml, pass a list. but the middle invocation is very confusing to me - we're splitting the parameter list with a colon. why is that equivalent? this seems like it might merely be a documentation issue and that there's an underlying consistency that would make it make sense, but the docs didn't get to that point quickly, and the result is that the language looks like it has redundant syntax to my brain.

Just some commentary cuz I found the language while browsing github. Looks like a fun project!

Change Erg's introduction text on the right side of the Github page and README

Now: A Python-compatible statically typed language
Suggested Changes: A general-purpose statically typed language that can interoperate seamlessly with Python

Why:
1.Python compatibility is ambiguous
2.Erg's niche market should be bigger than Python's, so to prevent misunderstandings, add generic embellishments

Feature request: Python syntax

Great effort, always wanted to have statically typed Python.
Please consider replacing the current syntax with Python syntax to 1) reusability of existing code 2) zero learning of new syntax needed.

Tuple is not implemented

Reproducible code:

> erg examples/tuple.er

Result:

Error[#0000]: File examples/tuple.er, line 1
1│ p = (1, 2)
         ^
SyntaxError: invalid syntax
Error[#0000]: File examples/tuple.er, line 4
4│ q = (1, 1.0)
         ^
SyntaxError: invalid syntax
Error[#0000]: File examples/tuple.er, line 7
7│ i, j = 0, 1
    ^
SyntaxError: invalid syntax
Error[#0000]: File examples/tuple.er, line 7
7│ i, j = 0, 1
           ^
SyntaxError: invalid syntax

Operator error messages are not displayed and cause panic

OS: Windows
python-version: 3.10.6

Reproduction Steps

  1. In REPl or scripts, write code that intentionally causes errors by using operators.
# only operator:*, -
+ 
  1. Panic instead of error messages.
> erg
Starting the REPL server...
Connecting to the REPL server...
Erg interpreter 0.2.2 (tags/?:6d3dda8, 2022/08/15  5:30:08.61) on x86_64/windows
>>> +
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', compiler\erg_parser\lex.rs:682:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<string>", line 17, in <module>
ConnectionAbortedError: [WinError 10053] 確立された接続がホスト コンピューターのソウトウェアによって中止されました。

I expected like REPL of python

> python
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> +
  File "<stdin>", line 1
    +
     ^
SyntaxError: invalid syntax

Method definition syntax for monomorphic classes

Currently, the syntax for defining class methods is as follows.

Person = Class {.name = Str; .age = Nat}
Person.
    new name, age = Self::__new__ {.name = name; .age = age}

The second line, Person., appears redundant.
The reason why I did it this way is convenient for polymorphic types.

Person Age: Nat = Class {.name = Str}
Person(Age).
    new name = Self::__new__ {.name = name}
    age = Age
Person(10).
    special ref(self) = "this is a special method for ten-years olds"
Person(N | N >= 20).
    drink ref(self) = ...

However, it is still redundant for monomorphic classes. Therefore, I am thinking of a syntax sugar for monophasic types. Do you have any good ideas?

Module not found

Reproducible code

r = import "random"
r.randint!(0, 10)

Expected behavior
get a random number.

Result

Error[#0305]: File <stdin>, line 1, in <module>
1│ r.randint!(0, 10)

     ^^^^^^^^
AttributeError: Module object has no attribute randint!

About the synchronization of each translated version with the English version

This problem needs to be solved very much, otherwise it will create a very confusing situation

Here are my ideas:
1.Each translated version requires 100% coverage (means that the PR for adding a new language should translate all the documents at once)
2.In the process of adding a new language, changes to the content of the English version must be alerted in adding-new-language PR(Finally, translation contributors are asked to carefully review the content of the translation, to prevent it from not tracking the full process of translation in PR)
3.All new content should be added to the English version first
4.Changes to the English version of the content need to be made via PR, and all language translations for the new content must be completed before the PR can be merged

@mtshiba

Calculating variables in square brackets causes panic

Python 3.10.6

>>> [1/2, "a"+"b"]
[0.5, 'ab']

erg 0.2.6

>>> [1.0/2.0, "a"+"b"] 
thread 'main' panicked at 'not yet implemented: [`/`: ({%v12: Float | %v12 == 1.0}, {%v13: Float | %v13 == 2.0}, ) -> Float:
    RatioLit 1.0
    RatioLit 2.0
`+`: ({%v18: Str | %v18 == "a"}, {%v19: Str | %v19 == "b"}, ) -> Str:
    StrLit "a"
    StrLit "b"]', compiler\erg_compiler\effectcheck.rs:66:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<string>", line 17, in <module>
ConnectionAbortedError: [WinError 10053] 確立された接続がホスト コンピューターのソウトウェアによって中止されました。
error: process didn't exit successfully: `target\debug\erg.exe` (exit code: 101)

Is this intended?

Test code

The current Erg test code is very poor.

In particular, tests around type inference are very little implemented, even though they are very important.

Organize crates

Currently, following crates are found:

  • erg_common: /src/erg_common
  • erg_compiler: /src/erg_compiler
  • erg_parser: /src/erg_compiler/erg_paraser

These crates should be organized in a good manner; for example, create /workspaces/ (or /complier/?) and put all crates there.

Also, these crates should be managed by Cargo's workspace feature.

refer to: rust-lang/rust directory structure

Arrow keys are not working in REPL

Left arrow key would be typed ^[[D in REPL.
The other arrow keys are the same, so I cannot enter previous input value with up arrow key.

❯ erg
Starting the REPL server...
Connecting to the REPL server...
Retrying to connect to the REPL server...
Erg interpreter 0.2.2 (tags/?:, 2022/08/14 20:25:00) on x86_64/linux
>>> print!()^[[D

erg v0.2.2 installed on wsl2 on windows11 via rustup-installed cargo 1.62.1

Document synchronization

I am in the process of translating the documents in the doc directory. This will be completed shortly, but I have not yet added a single badge to indicate synchronization.

Function definition is ignored

Describe the bug
Function declaration ignored, i.e. like encountering NameError on f(1) after f x = x.

Reproducible code

f x = x
f
# compiler complains even f is defined.
Error[#0213]: File <stdin>, line 1, in <module>
1│ f(1)
   ^
NameError: f is not defined

Expected behavior
Call f.

Additional context
Actually I found it's originated in Desugarer::desugar_pattern.
Its matching ignores Expr::Def(Def { sig: Signature::Subr(v)..}) like:

while let Some(chunk) = module.lpop() {
    match chunk {
        Expr::Def(def) => {
            if let Signature::Var(v) = def.sig {
                /* desugaring */
            } // if end
        },
        other => new.push(other),
    } // match end
} 

Thus, function parsed as Subr vanishes there.

However just fixing this as

match chunk {
    Expr::Def(Def { sig: Signature::Var(v) .. }) => { /* omit */ }
    other => /* omit */
}

produces stack overflow (eternal recursion) in compile process.
Maybe compiler also have some bug as the eternal recursion is not desireble if it's fatal error, but we have to add desugaring logic for Signature::Subr here first, rather than just passing it through this matching, right?

If so, I'm willing to implement them as it seems to be good first implementation to get used to Erg's syntax.
(And maybe fixing compiler bug is also not difficult and I'm willing to do it too.)

Better error indication

f x =
    ...
    y = foo.try_some(x)?
    ...

g x =
    y = f(x)?
    ...

i = g(1)?

Suppose you get the following error in the above code (including omissions).

Traceback (most recent call first):
    ...
    Foo.try_some, line ..., file "..."
    .... | y = foo.try_some(x)?
    module::f, line ..., file "..."
    .... | y = f(x)?
    module::g, line ..., file "..."
    .... | i = g(1)?
Error: ...

How about displaying the contents and type of the variable to make the error message clearer?
Like this:

Traceback (most recent call first):
    ...
    Foo.try_some, line ..., file "..."
    .... | y = foo.try_some(x)?
               │            └ 1: Int
               └ <Foo object>: Foo
    module::f, line ..., file "..."
    ... | y = f(x)?
                └ 1: Int
    module::g, line ..., file "..."
    ... | i = g(1)?
Error: ...

Erg book navigation links at the bottom (Prev|Next) are broken

The links at the bottom refer to "XX_chaptername.md" while the correct one should be "XX_chaptername.html".

The navigation can still be used via the side-bar chapter links, but it may cause inexperienced people to think that the chapter is missing or not implemented.

do! is not defined

Code from the README:

2.times! do!:
    print! "hello, ", end: ""

Result:

1│ 2.times! do!:
            ^^^
NameError: do! is not defined

erg v0.2.2 installed on macOS 12.5 via rustup-installed cargo 1.63.0

Cannot open multiple REPLs at once

Describe the bug
When we try to open multiple REPL, it reports OSError: [Errno 48] Address already in use.

Reproducible code
Try to run more than one erg at once.

Expected behavior
Different port is automatically assigned and REPL server is up.

Screenshots (optional)
For example, with tmux:
スクリーンショット 2022-08-27 0 59 44

Invalid syntax is not properly handled.

Describe the bug
When some tokens are passed without operator (thus Invalid Syntax), compiler trys to report error upsets.

Reproducible code
Just writing literals without operators in a row:

>>> 1 2 3

produces:

Error[#0000]: File <stdin>
?│ 1 2 3

CompilerSystemError: the number of elements in the stack is invalid (num of elems: 3, block id: 1)
this is a bug of the Erg compiler, please report it (https://github.com/erg-lang/erg)
caused from: erg_compiler::codegen::CodeGenerator::codegen
Traceback (most recent call last):
  File "<string>", line 17, in <module>
ConnectionResetError: [Errno 54] Connection reset by peer

Expected behavior
Expected that REPL just reports Invalid Syntax Error.

Any expression can be placed after the function call

Describe the bug
Same as the title.

Reproducible code

>>> print!(1) 1+1

Expected behavior
A type error must be caused (NoneType (print!'s return type) is not Callable).

Result

1
2

If compiled from a file, the following error occurs.

Error[#0000]: File test.er, line 1, in <module>
1│ print!(1) 1 + 1
             ^^^^^
SyntaxError: the evaluation result of the expression is not used
hint: if you don't use the value, use discard function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.