Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #27. Operator methods #29

Merged
merged 2 commits into from
Nov 6, 2017
Merged

Closes #27. Operator methods #29

merged 2 commits into from
Nov 6, 2017

Conversation

faultyserver
Copy link
Member

Most operators are now allowed as method names. The supported list is: +, -, *, /, %,
<, <=, !=, ==, >=, >, [], and []=. The last two are not operators that are recognized by the lexer, but rather operators that the parser infers from the access and access assignment syntaxes.

An interesting effect of the implementation is that the operators can be defined statically or on modules and still have the same effects:

 deftype Foo
  defstatic +(other)
    :called_op_on_type
  end
end

Foo + Foo #=> :called_op_on_type

This has the potential of being used for some type algebra and/or metaprogramming. I don't really understand the extend of what it could do, but I'm glad it works nonetheless.

The interpreter already treated operators as Calls on the receiving objects. This allows user-written code to define overloads for those operators on their own types.
Operator overloading can also be used with `defstatic` or on a module to define operators for things other than instances. This could potentially be used for some type algebra tricks, though it doesn't seem overly useful outside of metaprogramming.
@faultyserver faultyserver merged commit 4c9dc40 into master Nov 6, 2017
@faultyserver faultyserver deleted the 27_operator_methods branch November 6, 2017 00:24
@faultyserver faultyserver added this to the v0.2.0 milestone Nov 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant