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

Import functions as operators to sym blocks #435

Open
bvssvni opened this issue Jan 17, 2017 · 2 comments
Open

Import functions as operators to sym blocks #435

bvssvni opened this issue Jan 17, 2017 · 2 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Jan 17, 2017

An idea to import functions as operators, but only allowed inside a sym block. This makes it possible to experiment with syntax and create an ad-hoc DSL, without colliding with other operators or affecting how it is used in other projects.

The order of import defines the precedence.

With optional namespaces this could look like this:

use math::{add as ."+"., mul_scalar as ."*"., mul_comp as ."**".}

sym {[2] + [4, 5] * 3 + [6, 7] ** [8, 9]}

Unary and list arguments could be supported. No newline is needed after an expression.

use io::println as ">>".
use math::min as ."◁".. // Expand as array

a := 2
b := 3
c := 4
d := 5
// println(min([2, b, c]))
// println(d)
sym {>> 2 ◁ b ◁ c >> d}

One could bind variables in scope and function calls to arguments of an operator.

a := []
use std::push as (mut a)"<<"some(.)
sym {
    << 1 << 2 << 3
}
// prints `[some(1), some(2), some(3)]`
println(a)

Operators works as language sugar that rewrites meta data before passing it to lifetime/type checker and constructing the AST.

@bvssvni
Copy link
Member Author

bvssvni commented Jan 17, 2017

One problem with this approach is that you can't parse a source file with the meta syntax.

@bvssvni
Copy link
Member Author

bvssvni commented Jun 20, 2018

An alternative:

// Use `add` and `mul` from shared alias `matrix`.
sym matrix { a + b * c }

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