Git Product home page Git Product logo

astranaut's People

Contributors

slepher avatar

Stargazers

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

Watchers

 avatar  avatar

astranaut's Issues

unique var name generate in quote support.

-use_macro({macro/0, [unique_var]}).
macro() ->
  quote(
    fun(A) ->
      B = A + 1
      B  = A + 3
      {C, +B} = {A  + 5, A +3}
      {B, C}
   end). 

hello(A) ->
  B = A + 5,
  macro().
=>
hello(A) ->
  B = A + 5,
  fun(A_1@Q_1) ->
      B_1@Q_1 = A_1@Q_1 + 1
      B_2@Q_1 = A_1@Q_1 + 3
      {C_1@Q_1, B_2@Q_1} = {A_1@Q_1  + 5, A_1@Q_1 + 3}
      {B_2@Q_1, C_1@Q_1}
   end.

+before Var is pin operator.
just behaviours like pattern matching and pin operator in elixir
https://elixir-lang.org/getting-started/pattern-matching.html

add strict mode

usually pepole dont bind variable in fuction call, tuple, etc such as

hello(begin A = A +1, A end, begin A = A+ 2, A end).
{begin A = A +1, A end, begin A = A+ 2, A end}

add rebinding option strict to enable rebinding in such cases.
strict is default to false.

macro error and exception handle

macro could return error and warning to let compiler know
exception throwed by macro should be catched by parse_transform and let compiler know.

macro expand order

macro expand order should be the same order of -use_macro
add parameter {order => pre | post} for -use_macro
it means which order is used for expand nested macro such as

do([state_m || 
       B <- do([reader_m ||
                      R <- monad_reader:ask(),
                      return(A + R)
            ]),
      return(B)
]).

Contributing to syntax tools?

Just opening an issue here to have a little chat. You seem to have some interesting features here, and I'm wondering if you have at all considered submitting some PRs to make some of those features directly available as part of syntax_tools?

hygienic macro support

-module(macro_example).
macro_with_vars_1(Ast) ->
    quote(
      begin
          A = 10,
          B = unquote(Ast),
          A + B
      end
     ).
macro_with_vars_2(Ast) ->
    quote(
      begin
          A = 10,
          B = unquote(Ast),
          A + B
      end
     ).
test_macro_with_vars(N) ->
    A1 = macro_with_vars_1(N),
    A2 = macro_with_vars_2(A1),
    A3 = macro_with_vars_2(N),
    A4 = macro_with_vars_1(A1),
    A1 + A2.

=>

test_macro_with_vars(N) ->
A1 =
begin
  A@macro_example@_1 = 10,
  B@macro_example@_1 = N,
  A@macro_example@_1 + B@macro_example@_1
end,
A2 = 
begin
  A@macro_example@_3 = 10,
  B@macro_example@_3 = A1,
  A@macro_example@_3 + B@macro_example@_3
end,
A3 = 
begin
  A@macro_example@_4 = 10,
  B@macro_example@_4 = N,
  A@macro_example@_4 + B@macro_example@_4
end
A4 =
begin
  A@macro_example@_2 = 10,
  B@macro_example@_2 = A1,
  A@macro_example@_2 + B@macro_example@_2
end
A1 + A2 + A3 + A4.

add -export_macro attribute

-export_macro({[macro_1/0, macro_2/0], Options}).

macro_1() ->
  quote(ok).
macro_2() ->
  quote(ok).

Options will be merged to -use_macro options.

add attrs for -use_macro

while import attributes is imported to macro
extra argument Attributes is added to macro function while called.
it includes all attributes of module mentioned in proplist key attrs

special attrs:

module: module use_macro

line: line where macro used

-module(a).
-behaviour(gen_server).
-use_macro({macro_a, macro/2, [{attrs, [module, line, behaviour]}]}).

hello() ->
  macro_a:macro(world).
-module(macro_a).
-export([macro/2]).

macro(Ast, #{module => Module, line => Line, behaviour => Behaviours} = Attributes) ->
   io:format("module is ~p, behaviour is ~p", [Module, Behaviours]),
   Ast.

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.