Reification for Macros

Showing 1-29 of 29 messages
Reification for Macros Nicolas Cannasse 6/17/12 2:26 PM
Hi,

I have added today reification for macros in Haxe, I'm interested in
tests/feedback, see http://ncannasse.fr/blog/reification_for_macros

Best,
Nicolas
Re: Reification for Macros Stephane Le Dorze 6/17/12 2:33 PM
Won't be able to play with it before a couple of days.
My very first feedback, without thinking about the details, is a big thanks Nicolas; I really think it makes macro usage more approachable so more usefull for a broader audience.
Very neat! :)

Le dimanche 17 juin 2012 22:26:16 UTC+1, Nicolas Cannasse a écrit :
Re: Reification for Macros Stephane Le Dorze 6/17/12 2:39 PM
I think it brings nothing (so is of minor importance) but for homogeneity with 'format', have you though about:

macro foo( ${ <code generating an Expression> } )

as a short cut for:

var myExp = <code generating an Expression>;
macro foo( $myExp )

Stephane


Le dimanche 17 juin 2012 22:26:16 UTC+1, Nicolas Cannasse a écrit :
Hi,
Re: [haxe] Re: Reification for Macros Nicolas Cannasse 6/17/12 2:44 PM
Le 17/06/2012 23:39, Stephane Le Dorze a �crit :
> I think it brings nothing (so is of minor importance) but for
> homogeneity with 'format', have you though about:
>
> macro foo( ${ <code generating an Expression> } )

${} is not a valid expression in Haxe, that would require to add syntax.
Unless you meant $(...) ?

Best,
Nicolas

Re: [haxe] Re: Reification for Macros Stephane Le Dorze 6/17/12 2:46 PM
Indeed!.

Le dimanche 17 juin 2012 22:44:23 UTC+1, Nicolas Cannasse a écrit :
Le 17/06/2012 23:39, Stephane Le Dorze a �crit :
> I think it brings nothing (so is of minor importance) but for
> homogeneity with 'format', have you though about:
>
> macro foo( ${ <code generating an Expression> } )

${} is not a valid expression in Haxe, that would require to add syntax.
Unless you meant $(...) ?

Best,
Nicolas

Re: [haxe] Re: Reification for Macros Juraj Kirchheim 6/17/12 2:49 PM
Don't have time to try it right now, but it sure looks great! :)

A few questions though:

What kind of syntax is "macro <expr>"? Is this somehow directly
embedded into the parser? Or is it a first class expression (that
could in fact itself be generated by a macro - not that that's useful
in any way). Does the change make "macro" a keyword (in your blog post
it says "special word" which is really vague)?

Regards,
Juraj
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
Re: [haxe] Re: Reification for Macros Nicolas Cannasse 6/17/12 3:31 PM
Le 17/06/2012 23:49, Juraj Kirchheim a �crit :
> Don't have time to try it right now, but it sure looks great! :)
>
> A few questions though:
>
> What kind of syntax is "macro <expr>"? Is this somehow directly
> embedded into the parser? Or is it a first class expression (that
> could in fact itself be generated by a macro - not that that's useful
> in any way). Does the change make "macro" a keyword (in your blog post
> it says "special word" which is really vague)?

It's a first class expression EMacro( e : Expr )
I used "special word" because it's not keyword ;)

Best,
Nicolas
Reification for Macros airfoil 6/17/12 6:27 PM
Looks great! I can't wait to play with it!
Re: [haxe] Reification for Macros Rammserker 6/17/12 6:53 PM
Great addition. Kudos Nico!

Maximiliano Fernández do Santos

0 1 0              0 1 0
0 0 1  Rammserker  1 0 0
1 1 1              1 1 1

Re: [haxe] Reification for Macros dlots 6/17/12 8:48 PM
Faurking amazing. Srsly. I had half a mind to start writing this sort of abstraction for macros. Just amazing. Thank you. This is 100 times better.
Re: [haxe] Reification for Macros Jason O'Neil 6/17/12 8:52 PM
Agreed.

I think I'll wait until 2.10 to try them out but I'm excited by these
changes.

On Mon 18 Jun 2012 11:48:19 WST, dlots wrote:
> Faurking amazing. Srsly. I had half a mind to start writing this sort
> of abstraction for macros. Just amazing. Thank you. This is 100 times
> better.
>
> On Sunday, June 17, 2012 9:53:30 PM UTC-4, Rammserker wrote:
>
>     Great addition. Kudos Nico!
>
>     _Maximiliano Fernández do Santos
>     _
>
>     0 *1* 0 0 *1* 0
>     0 0 *1 *Rammserker *1* 0 0
>     *1 1 1 1 1 1*
Re: [haxe] Reification for Macros Simon Krajewski 6/17/12 10:17 PM
Am 17.06.2012 23:26, schrieb Nicolas Cannasse:
> Hi,
>
> I have added today reification for macros in Haxe, I'm interested in
> tests/feedback, see http://ncannasse.fr/blog/reification_for_macros

While I love the feature itself, the "macro" keyword seems somewhat out
of place there. Shouldn't it be "expr" instead?
     return expr "Hello World";
That seems more natural.

Simon
Re: Reification for Macros Yamuu 6/18/12 7:05 AM
Can this be used to call global functions?

Ex (works):
@:macro public static function is(instance:Expr, of_type:Expr):Expr
{
return
{
expr : EUntyped(
{
expr : ECall(
{
expr : EConst(CIdent("__is__")),
pos : pos
},
[
instance,
of_type
]),
pos : pos
}),
pos : pos
};
}

Ex (does not work):
@:macro public static function is(instance:Expr, of_type:Expr):Expr
{
return macro $__is__($instance, $of_type);
}
Re: [haxe] Re: Reification for Macros Nicolas Cannasse 6/18/12 7:44 AM
Le 18/06/2012 16:05, Yamuu a �crit :
> Can this be used to call global functions?
>
> Ex (works):
> @:macro public static function is(instance:Expr, of_type:Expr):Expr
> {
> return
> {
> expr : EUntyped(
> {
> expr : ECall(
> {
> expr : EConst(CIdent("__is__")),
> pos : pos
> },
> [
> instance,
> of_type
> ]),
> pos : pos
> }),
> pos : pos
> };
> }
>
> Ex (does not work):
> @:macro public static function is(instance:Expr, of_type:Expr):Expr
> {
> return macro $__is__($instance, $of_type);
> }

Why using $__is__ here ?

The equivalent to your previous example should be :

reurn macro untyped __is__($instance, $of_type);

Best,
Nicolas
Re: [haxe] Re: Reification for Macros Benjamin Dubois 6/18/12 8:58 AM
Looks I don't have excuse to avoid macro anymore :)

Ben
Re: [haxe] Re: Reification for Macros MarcWeber 6/18/12 9:03 AM
Excerpts from Benjamin Dubois's message of Mon Jun 18 17:58:47 +0200 2012:
> Looks I don't have excuse to avoid macro anymore :)

There was no excuse previously either because tink_macros provided a
similar feature, right?

Marc Weber
Re: Reification for Macros Michiel Crefcoeur 6/18/12 10:13 AM
haxe.awesomeness++;

btw: your website has been down all day :-(
Re: [haxe] Re: Reification for Macros Cauê Waneck 6/18/12 11:00 AM
Whoa, that's great!!! :) :)

2012/6/18 Michiel Crefcoeur <mpc...@gmail.com>
--

Re: [haxe] Re: Reification for Macros Nicolas Cannasse 6/18/12 12:03 PM
Le 18/06/2012 19:13, Michiel Crefcoeur a �crit :
> haxe.awesomeness++;
>
> btw: your website has been down all day :-(

Uhm, looks like we have some router issue, hope it is fixed soon.

Best,
Nicolas
Re: [haxe] Re: Reification for Macros Cauê Waneck 6/18/12 12:14 PM
it was due to the huge traffic generated from this announcement ;)

2012/6/18 Nicolas Cannasse <ncan...@motion-twin.com>
Le 18/06/2012 19:13, Michiel Crefcoeur a écrit :

haxe.awesomeness++;

btw: your website has been down all day :-(

Uhm, looks like we have some router issue, hope it is fixed soon.

Re: [haxe] Re: Reification for Macros Juraj Kirchheim 6/18/12 12:15 PM
You're right, tink_macros already offers that kind of functionality
since quite some time already
(https://github.com/back2dos/tinkerbell/wiki/tink_macros#wiki-ast). I
am very happy to see this become a supported first class language
feature, although it should be noted that currently AST.build is still
more powerful, because you can do things like:

        package ;
        #if macro
                import haxe.macro.Expr;
                import tink.macro.tools.AST;
        #end
        class Main {
                static function main() {
                        var o = { foo: 5 };
                        var f = getter('foo');
                        trace(f(o));//5
                }
                @:macro static function getter(field:String) {
                        return AST.build(function (o) return o.eval__field);
                }
        }

I would very much like to see something like this supported as well,
because it has turned out to be a very powerful feature.

Regards,
Juraj
Re: [haxe] Re: Reification for Macros Nicolas Cannasse 6/18/12 12:26 PM
Le 18/06/2012 21:15, Juraj Kirchheim a �crit :
I made sure that every $-prefix string can be replaced with the
corresponding value, so we a bit more relaxing on the parser we could do
the following :

   return macro function(o) return o.$field;

Best,
Nicolas
Re: [haxe] Re: Reification for Macros Stephane Le Dorze 6/18/12 12:32 PM
uh oh.. :)
and could the identifier be dynamically generated?

Le lundi 18 juin 2012 20:26:42 UTC+1, Nicolas Cannasse a écrit :
Le 18/06/2012 21:15, Juraj Kirchheim a �crit :
Re: [haxe] Re: Reification for Macros Juraj Kirchheim 6/18/12 12:41 PM
On Mon, Jun 18, 2012 at 9:26 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
[...]
> I made sure that every $-prefix string can be replaced with the
> corresponding value, so we a bit more relaxing on the parser we could do the
> following :
>
>  return macro function(o) return o.$field;

That would be really, really cool!
Also it would ideally allow to useTypePaths and ComplexTypes from the
outer context.

Regards,
Juraj
Re: [haxe] Re: Reification for Macros FullOfCaffeine 6/19/12 4:23 PM
Wasn't this somewhat already implemented in tink_macros ?

Looks interesting though,


- Marcelo


Re: [haxe] Re: Reification for Macros Juraj Kirchheim 6/20/12 6:29 AM
It was, but having this as a first class feature is favorable :)

On Wed, Jun 20, 2012 at 1:23 AM, Marcelo de Moraes Serpa
<fullofc...@gmail.com> wrote:
> Wasn't this somewhat already implemented in tink_macros ?
>
> Looks interesting though,
>
>
> - Marcelo
>
> On Monday, June 18, 2012 at 2:41 PM, Juraj Kirchheim wrote:
>
> On Mon, Jun 18, 2012 at 9:26 PM, Nicolas Cannasse
> <ncan...@motion-twin.com> wrote:
> [...]
>
> I made sure that every $-prefix string can be replaced with the
> corresponding value, so we a bit more relaxing on the parser we could do the
> following :
>
>  return macro function(o) return o.$field;
>
>
> That would be really, really cool!
> Also it would ideally allow to useTypePaths and ComplexTypes from the
> outer context.
>
> Regards,
> Juraj
>
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
>
>
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
Re: [haxe] Re: Reification for Macros dlots 7/15/12 12:18 PM
@:macro function object_owner_dao_get(method:String):Expr {
        return macro {
            if(object_owner_dao!=null) {
                var o:Dynamic=object_owner_dao.$method; //<--
                return viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
            }
        }
    }

Is something like the above possible? I am getting:

s:/_flash/shared_haxe/shared/src/nodion/shared/dao/server/Dao_server_s.hx:226: characters 47-54 : Unexpected $method

I'm also not sure whether one needs to use a string or an expression for method (neither way works as the error has to do with :

object_owner_dao_get("get_withId_sql(id,cache,lock,key)");
object_owner_dao_get(get_withId_sql(id,cache,lock,key));

as specified by:


I made sure that every $-prefix string can be replaced with the
corresponding value, so we a bit more relaxing on the parser we could do
the following :

   return macro function(o) return o.$field;

Is the above possible with tink macros? I will be checking that shortly but if anyone knows that would be appreciated :)
Re: [haxe] Re: Reification for Macros back2dos 7/16/12 2:48 AM
This is due to a limitation in the Haxe syntax, although at some point
in this thread Nicolas said it might be lifted.

With tink_macros, there's a workaround, but you'll have to write
`eval__method` instead of `$method`:

        @:macro function object_owner_dao_get(method:String):Expr {
                return AST.build({
                    if(object_owner_dao!=null) {
                        var o:Dynamic=object_owner_dao.eval__method; //<--
                        return
viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
                    }
                });
         }

Documentation is here:
https://github.com/back2dos/tinkerbell/wiki/tink_macros#wiki-ast

Please note that tink doesn't currently work with 2.10 but I'll have
that fixed today. The Haxe team has been busy while I was on holiday
:)

Regards,
Juraj
Re: [haxe] Re: Reification for Macros Nicolas Cannasse 7/16/12 7:11 AM
Le 15/07/2012 21:18, dlots a �crit :
> @:macro function object_owner_dao_get(method:String):Expr {
>          return macro {
>              if(object_owner_dao!=null) {
>                  var o:Dynamic=object_owner_dao.$method; //<--
>                  return
> viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
>              }
>          }
>      }
>
> Is something like the above possible? I am getting:

Not in time for 2.10, but you can fill an issue for a change request.

Best,
Nicolas
More topics »