can we use Context.parsing using existing macro Expr ?

classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

can we use Context.parsing using existing macro Expr ?

sledorze
Hi!
I'm trying to achieve this.. I think it is not possible but as some of you proved to know the api possibilities better than me.. I ask.
Simple example:

  @:macro public static function foo(a : Expr) : Expr {
   
    var exp = Context.parse("
      {
        function foo() {
          return a;              ////// <<------ generates an error, and that what I would like to achieve.
        }
      }
      ",
      Context.currentPos()
    );

    return exp;
  }


Thanks,
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

Cauê W.
Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>
Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>
Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

Cauê W.
what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>
Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?

Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
Will answer with a real keyboard later but no this wasn't that use case. I want to simplify writing my macros.. (look at nemerle)

Sent from my iPhone

On 1 nov. 2011, at 17:01, "Cauê W. [via Haxe]" <[hidden email]> wrote:

what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>
Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952154.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

Cauê W.
Ok, you want var a = Macro.foo(x) to be var a = function() return x; ?

Context.parse won't help you with that, you'll have to write the AST by hand, but it's easy enough for you:

@:macro function foo(a:Expr)
{
return {expr:EFunction({args:[], expr:{expr:EReturn(a), pos:a.pos}, ret:null, params:[]}), pos:a.pos};
}
2011/11/1 sledorze <[hidden email]>
Will answer with a real keyboard later but no this wasn't that use case. I want to simplify writing my macros.. (look at nemerle)

Sent from my iPhone

On 1 nov. 2011, at 17:01, "Cauê W. [via Haxe]" <[hidden email]> wrote:

what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>

Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952154.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
The usage is broader. Before leaving i write a macro which enable me to substitue identifiers by expressions into an expression so i am pretty close.
Best example to show you the intend (nemerle):
macro for (init, cond, change, body)
{
  <[ 
    $init;
    def loop () : void {
      if ($cond) { $body; $change; loop() } 
      else ()
    };
    loop ()
  ]>
}


Sent from my iPhone

On 1 nov. 2011, at 17:35, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Ok, you want var a = Macro.foo(x) to be var a = function() return x; ?

Context.parse won't help you with that, you'll have to write the AST by hand, but it's easy enough for you:

@:macro function foo(a:Expr)
{
return {expr:EFunction({args:[], expr:{expr:EReturn(a), pos:a.pos}, ret:null, params:[]}), pos:a.pos};
}
2011/11/1 sledorze <[hidden email]>
Will answer with a real keyboard later but no this wasn't that use case. I want to simplify writing my macros.. (look at nemerle)

Sent from my iPhone

On 1 nov. 2011, at 17:01, "Cauê W. [via Haxe]" <[hidden email]> wrote:

what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>

Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952154.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952315.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Cauê W.
In other way.. I want to make expr a monad by building the bind operator (aka flatmap).

Sent from my iPhone

On 1 nov. 2011, at 17:35, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Ok, you want var a = Macro.foo(x) to be var a = function() return x; ?

Context.parse won't help you with that, you'll have to write the AST by hand, but it's easy enough for you:

@:macro function foo(a:Expr)
{
return {expr:EFunction({args:[], expr:{expr:EReturn(a), pos:a.pos}, ret:null, params:[]}), pos:a.pos};
}
2011/11/1 sledorze <[hidden email]>
Will answer with a real keyboard later but no this wasn't that use case. I want to simplify writing my macros.. (look at nemerle)

Sent from my iPhone

On 1 nov. 2011, at 17:01, "Cauê W. [via Haxe]" <[hidden email]> wrote:

what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>

Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952154.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952315.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Cauê W.
Intentional parallel .. Expr is not parametric.

Sent from my iPhone

On 1 nov. 2011, at 17:56, Stephane Le Dorze <[hidden email]> wrote:

In other way.. I want to make expr a monad by building the bind operator (aka flatmap).

Sent from my iPhone

On 1 nov. 2011, at 17:35, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Ok, you want var a = Macro.foo(x) to be var a = function() return x; ?

Context.parse won't help you with that, you'll have to write the AST by hand, but it's easy enough for you:

@:macro function foo(a:Expr)
{
return {expr:EFunction({args:[], expr:{expr:EReturn(a), pos:a.pos}, ret:null, params:[]}), pos:a.pos};
}
2011/11/1 sledorze <[hidden email]>
Will answer with a real keyboard later but no this wasn't that use case. I want to simplify writing my macros.. (look at nemerle)

Sent from my iPhone

On 1 nov. 2011, at 17:01, "Cauê W. [via Haxe]" <[hidden email]> wrote:

what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:

var a = Macro.foo(x);

will return:

var a = {expr:EConst(CIdent("x")), pos:...}

is that what you want? what you mean by return a; ?



2011/11/1 sledorze <[hidden email]>

Afk, not sure i understand it but Will try... Thanks

Sent from my iPhone

On 1 nov. 2011, at 15:39, "Cauê W. [via Haxe]" <[hidden email]> wrote:

Oh, you should want to look at Context.makeExpr()

it will look like this:

@:macro public static function foo(a : Expr) : Expr {
return Context.makeExpr(a, a.pos);
}

2011/11/1 sledorze <[hidden email]>

Hi!
I'm trying to achieve this.. I think it is not possible but as some of you
proved to know the api possibilities better than me.. I ask.
Simple example:

 @:macro public static function foo(a : Expr) : Expr {

   var exp = Context.parse("
     {
       function foo() {
         return a;              ////// <<------ generates an error, and
that what I would like to achieve.
       }
     }
     ",
     Context.currentPos()
   );

   return exp;
 }


Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951178.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6951896.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.


View this message in context: Re: can we use Context.parsing using existing macro Expr ?
--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952154.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952315.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

Johann Borck
In reply to this post by Cauê W.
On 11/01/2011 04:59 PM, Cauê Waneck wrote:

> what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:
>
> var a = Macro.foo(x);
>
> will return:
>
> var a = {expr:EConst(CIdent("x")), pos:...}
>
> is that what you want? what you mean by return a; ?
>
I think he wants to use the expression a passed to the macro function inside the String that is
given to Context.parse, by name. While I think it would be unclean to make the evaluation of the
string depend on values that may or may not exist in the local scope of the macro function, a useful
addition to Context.parse would be an optional argument that takes a mapping from names to
expressions, i.e. an anon object, so you could do something like what sledorze suggested as follows:

@:macro public static function foo(a : Expr) : Expr {

    var exp = Context.parseReplace("{ function foo() { return $a; }}",
                                                         Context.currentPos(),
                                                         {a : a} );
...

Another and generally very useful feature that made this possible would be an  Expr->String
function. There are a number of similar use cases where additional functionality for macros could
help the programmer making them more concise. Maybe we should collect ideas and create a library
with the most-often requested macro-helpers.
What I'd also like to see (and hope to propose a patch as soon as I find the time) is the ability to
write macros in ocaml. While haxe is good, it still is no match for ocamls pattern matching
capabilities. I know there are many valid objections to this (e.g. haxe not depending on haxe-only
code anymore), but I think it would be better to have a well-defined interface for such
compiler-plugins than everyone rolling their own (for some value of 'everyone', obviously).

regards,
Johann


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
Thé extra param technique is what  i have done.
Now i think about doing a first macro which takes à string and returns a call to this substitution macro with an objectdecl owning the mapping.
I am away from computer for some hours but am really impatient to test it out. This two pass macro could bring à very easy way to build some macros.

Sent from my iPhone

On 1 nov. 2011, at 18:27, "Johann Borck [via Haxe]" <[hidden email]> wrote:

On 11/01/2011 04:59 PM, Cauê Waneck wrote:

> what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:
>
> var a = Macro.foo(x);
>
> will return:
>
> var a = {expr:EConst(CIdent("x")), pos:...}
>
> is that what you want? what you mean by return a; ?
>
I think he wants to use the expression a passed to the macro function inside the String that is
given to Context.parse, by name. While I think it would be unclean to make the evaluation of the
string depend on values that may or may not exist in the local scope of the macro function, a useful
addition to Context.parse would be an optional argument that takes a mapping from names to
expressions, i.e. an anon object, so you could do something like what sledorze suggested as follows:

@:macro public static function foo(a : Expr) : Expr {

    var exp = Context.parseReplace("{ function foo() { return $a; }}",
                                                         Context.currentPos(),
                                                         {a : a} );
...

Another and generally very useful feature that made this possible would be an  Expr->String
function. There are a number of similar use cases where additional functionality for macros could
help the programmer making them more concise. Maybe we should collect ideas and create a library
with the most-often requested macro-helpers.
What I'd also like to see (and hope to propose a patch as soon as I find the time) is the ability to
write macros in ocaml. While haxe is good, it still is no match for ocamls pattern matching
capabilities. I know there are many valid objections to this (e.g. haxe not depending on haxe-only
code anymore), but I think it would be better to have a well-defined interface for such
compiler-plugins than everyone rolling their own (for some value of 'everyone', obviously).

regards,
Johann


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952536.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Johann Borck
Not sure about ocaml macros.. Or it should be packageable with libs.. 

Sent from my iPhone

On 1 nov. 2011, at 18:27, "Johann Borck [via Haxe]" <[hidden email]> wrote:

On 11/01/2011 04:59 PM, Cauê Waneck wrote:

> what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:
>
> var a = Macro.foo(x);
>
> will return:
>
> var a = {expr:EConst(CIdent("x")), pos:...}
>
> is that what you want? what you mean by return a; ?
>
I think he wants to use the expression a passed to the macro function inside the String that is
given to Context.parse, by name. While I think it would be unclean to make the evaluation of the
string depend on values that may or may not exist in the local scope of the macro function, a useful
addition to Context.parse would be an optional argument that takes a mapping from names to
expressions, i.e. an anon object, so you could do something like what sledorze suggested as follows:

@:macro public static function foo(a : Expr) : Expr {

    var exp = Context.parseReplace("{ function foo() { return $a; }}",
                                                         Context.currentPos(),
                                                         {a : a} );
...

Another and generally very useful feature that made this possible would be an  Expr->String
function. There are a number of similar use cases where additional functionality for macros could
help the programmer making them more concise. Maybe we should collect ideas and create a library
with the most-often requested macro-helpers.
What I'd also like to see (and hope to propose a patch as soon as I find the time) is the ability to
write macros in ocaml. While haxe is good, it still is no match for ocamls pattern matching
capabilities. I know there are many valid objections to this (e.g. haxe not depending on haxe-only
code anymore), but I think it would be better to have a well-defined interface for such
compiler-plugins than everyone rolling their own (for some value of 'everyone', obviously).

regards,
Johann


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952536.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Johann Borck
Ok just gave it a try;

    function myExpression(x) return x+1;
    
    var res =
      MetaMacro.mk("
        function () {
          return $myExpression(1);
        }
      ");
    
    trace("result " + res()); // prints 1

so the poc works :)

Got to take care of family, I'll be back on it later.. to implement some parts of it (word extraction hacked for the purpose of validating the approach)..

I also think that a version that do not requiers a string as a parameter is also achievable.. (would be step 2).

Stephane


On Tue, Nov 1, 2011 at 6:43 PM, Stephane Le Dorze <[hidden email]> wrote:
Not sure about ocaml macros.. Or it should be packageable with libs.. 

Sent from my iPhone

On 1 nov. 2011, at 18:27, "Johann Borck [via Haxe]" <[hidden email]> wrote:

On 11/01/2011 04:59 PM, Cauê Waneck wrote:

> what exactly do you want to do? I thought you wanted to return the Expr you've sent, for example:
>
> var a = Macro.foo(x);
>
> will return:
>
> var a = {expr:EConst(CIdent("x")), pos:...}
>
> is that what you want? what you mean by return a; ?
>
I think he wants to use the expression a passed to the macro function inside the String that is
given to Context.parse, by name. While I think it would be unclean to make the evaluation of the
string depend on values that may or may not exist in the local scope of the macro function, a useful
addition to Context.parse would be an optional argument that takes a mapping from names to
expressions, i.e. an anon object, so you could do something like what sledorze suggested as follows:

@:macro public static function foo(a : Expr) : Expr {

    var exp = Context.parseReplace("{ function foo() { return $a; }}",
                                                         Context.currentPos(),
                                                         {a : a} );
...

Another and generally very useful feature that made this possible would be an  Expr->String
function. There are a number of similar use cases where additional functionality for macros could
help the programmer making them more concise. Maybe we should collect ideas and create a library
with the most-often requested macro-helpers.
What I'd also like to see (and hope to propose a patch as soon as I find the time) is the ability to
write macros in ocaml. While haxe is good, it still is no match for ocamls pattern matching
capabilities. I know there are many valid objections to this (e.g. haxe not depending on haxe-only
code anymore), but I think it would be better to have a well-defined interface for such
compiler-plugins than everyone rolling their own (for some value of 'everyone', obviously).

regards,
Johann


--
haXe - an open source web programming language
http://haxe.org



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6952536.html
To unsubscribe from can we use Context.parsing using existing macro Expr ?, click here.



--
Stéphane Le Dorze


Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Johann Borck
I have no solution to solve this problem right now.

I've only been able to substitue some AST parts based on identfiers names.

From that I though I could do it in a two passe macros; the first capturings the argument expressions, and calling the second one with the actual interesting code using those expressions and the (already) expressions passed in an anonymous dictionnary.

So the second macro receives the code as an expression and the dictionnary as an expression (so the expression it contains are encoded as "Expr of Expr").

The trick I though about was the arguments from "Expr of Expr" to simple Expr but I can't resolve the identifiers to flatten them.. either it is not possible or I miss something in the API...

So in the end, either we need to be able to:
- passe untouched anonymous objects to macros even if they hold ASTs. (perhaps the easier one).
- resolve an expression from an identifier (but I think it would requier a compiler phase).
- have the proposed new parsing method with expressions arguments. (preferred coz faster).

Too bad, was looking handy..
Stéphane
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In fact I can prevent the arguments to become Expr of Expr by serializing / unserializing the anonymous object holding them for the second macro call..

Doing so, the serializer stopped on the serialization of position information, commenting the failure case I stumbled on a possible Bug I've reported into another post where it appears that in the second nested call the string passed is considered as an Expression.. not sure about it..
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
In reply to this post by Johann Borck
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

Juraj Kirchheim
Ok, now I have understood what this is about :)
In fact, I have already implemented it (or something equivalent to be
more exact).
Just needs a little cleanup. Will try to release it tomorrow.

On Tue, Nov 1, 2011 at 10:53 PM, sledorze <[hidden email]> wrote:

> I've filled out the proposal:
> http://code.google.com/p/haxe/issues/detail?id=562
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6953391.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
Just came out with a working solution (some hack behind the hoods)..

So here's a macro built with it:


  @:macro public static function forExample(init : Expr, cond : Expr, inc : Expr, body : Expr) : Expr {
    Stagged.setMappings({ // sets the mappings
      init : init,
      cond : cond,
      inc : inc,
      body : body
    });
    Stagged.make(function () { // the actual macro being defined
      var i;
      init;
      function oneTime() {
        if (cond) {
          body;
          inc;
          oneTime();
        }
      }
      oneTime();        
    });
    return Stagged.get(); // returns the result
  }

Now the usage:


 StaggedTestMacros.forExample(i = 0, i < 10, i++, trace(i))();

And obviously, it works!
(note this example is a bit contrivied due to the implicit definition of 'i' but anyway, you have the taste!

I'l release it soon on my github repo as part of my macros library.

Thanks for having helped! :)

Stephane


Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

sledorze
New version  will make it ridiculous :) :

  @:macro public static function forExample2(init : Expr, cond : Expr, inc : Expr, body : Expr) : Expr return
    "{
      var i;
      $init;
      function oneTime() {
        if ($cond) {
          $body;
          $inc;
          oneTime();
        }
      }
      oneTime();
    }".stagged()

Reply | Threaded
Open this post in threaded view
|

Re: can we use Context.parsing using existing macro Expr ?

go2ghana
Am 02.11.2011 00:47, schrieb sledorze:

> New version  will make it ridiculous :) :
>
>    @:macro public static function forExample2(init : Expr, cond : Expr, inc :
> Expr, body : Expr) : Expr return
>      "{
>        var i;
>        $init;
>        function oneTime() {
>          if ($cond) {
>            $body;
>            $inc;
>            oneTime();
>          }
>        }
>        oneTime();
>      }".stagged()
>
>
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/can-we-use-Context-parsing-using-existing-macro-Expr-tp6951178p6953663.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
Looks like I don't get how to use it - compilation fails with:

String has no field stagged

Hi, Could you provide a working example?

Cordially,
Axel


--
haXe - an open source web programming language
http://haxe.org
12