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

Introducing Operator Declaration #68

Open
Alexius-Huang opened this issue May 21, 2020 · 0 comments
Open

Introducing Operator Declaration #68

Alexius-Huang opened this issue May 21, 2020 · 0 comments

Comments

@Alexius-Huang
Copy link
Owner

Alexius-Huang commented May 21, 2020

What?
Declaring new type of operator.

Why?
Extended innovation and usage of operators.

How?
Important Rules:

  1. New kind of operator should be declared in the beginning of the file.
  2. Operator should be restricted in these characters: +, -, *, /, >, <, =, $, &, |, !, ?, _, \, ~, @, ^
  3. Operator cannot be redeclared: +, -, *, /, >, <, =, ==, |> (See Introducing Pipe Operator #67 )
  4. Operator without declaration specified in Operator Overloading and Overriding #66 is useless, since no input pattern is introduced
  5. Operator can only be maximum length of 3, long operators are forbidden

Sample Wyrd Code

declare operator "<~"

def <~(op1: Str, op2: Str): Str do
  op1.concat(op2)
end

foo = "hello" <~ " world" |> Str.upcase()

Compiled Result

function OP_1(op1, op2) {
  return op1.concat(op2);
}

const foo = (OP_1("hello", " world")).toUpperCase();
@Alexius-Huang Alexius-Huang changed the title Operator Declaration Introducing Operator Declaration May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant