erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Add basic numeric calc and bool type #182

Closed GreasySlug closed 2 years ago

GreasySlug commented 2 years ago

Related #178.

Four arithmetic operations, comparisons, and logical operations were missing, so those were added in Japanese.

Once this has been reviewed, then I' ll translate it into English and add it later.

@mtshiba

mtshiba commented 2 years ago

I think it is unnecessary to bother writing about the arithmetic operations in the syntax documentation.

It is better to write in the documentation under the API what specific operators are defined.

GreasySlug commented 2 years ago

It is better to write in the documentation under the API what specific operators are defined.

Well, that may be true, but four arithmetic operations and comparisons are often used in "quick tour" and "getting started.

like python, ruby

Erg’s type conversion is also strict, but has the flexibility of subtyping by trait or class.

This is exactly the kind of thing that should be explained in detail in the API.

For example, given the operation 1.0 + 1, the 1 on the right-hand side is cast to instance 1.0 in the superclass Float; the addition of Float and Float is defined, but the addition of Int and Float is not directly defined.

so the examples are incorrect and I will fix them

mtshiba commented 2 years ago

Quick tour doc exists: https://github.com/erg-lang/erg/blob/main/doc/EN/syntax/quick_tour.md

GreasySlug commented 2 years ago

I'll move this to the beginning of quick tour.

Is anything wrong with this except for the casting of the type?

mtshiba commented 2 years ago

True and False are singletons of type Bool. Casting them to Int yields 1, 0, but they are not defined as 1, 0. Bool operations are performed with and, or, and not. &&, ||, and ~ are bitwise operators.

GreasySlug commented 2 years ago

Quick Tour link added in the Basics section. I removed the basic four arithmetic operations and comparisons because it is written not to write them if the contents are duplicated in python. However, compile errors due to type are left untouched.

mtshiba commented 2 years ago

Since Bool is a subtype of Int and Int is a subtype of Ratio (although the current implementation is Float), True can be cast to 1.0.

However, Float cannot be compared by ==, so a compile error will occur.

スクリーンショット 2022-09-29 151103

mtshiba commented 2 years ago

Float cannot be compared by ==, so a compile error will occur.

The reason for this is that Float does not satisfy the transitive law, which is the condition for equivalence relations.

スクリーンショット 2022-09-29 151501

GreasySlug commented 2 years ago

Thank you for reviewing

mtshiba commented 2 years ago

Thanks!