Reification for Macros

157 visualizzazioni
Passa al primo messaggio da leggere

Nicolas Cannasse

da leggere,
17 giu 2012, 17:26:1617/06/12
a haxe...@googlegroups.com
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

Stephane Le Dorze

da leggere,
17 giu 2012, 17:33:5617/06/12
a haxe...@googlegroups.com
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! :)

Stephane Le Dorze

da leggere,
17 giu 2012, 17:39:5817/06/12
a haxe...@googlegroups.com
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 :

Nicolas Cannasse

da leggere,
17 giu 2012, 17:44:2317/06/12
a haxe...@googlegroups.com
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

Stephane Le Dorze

da leggere,
17 giu 2012, 17:46:1817/06/12
a haxe...@googlegroups.com
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 :

Juraj Kirchheim

da leggere,
17 giu 2012, 17:49:1117/06/12
a haxe...@googlegroups.com
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

On Sun, Jun 17, 2012 at 11:44 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
> 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
>
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en

Nicolas Cannasse

da leggere,
17 giu 2012, 18:31:0017/06/12
a haxe...@googlegroups.com
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

airfoil

da leggere,
17 giu 2012, 21:27:2317/06/12
a haxe...@googlegroups.com
Looks great! I can't wait to play with it!

Maximiliano Fernández

da leggere,
17 giu 2012, 21:53:3017/06/12
a haxe...@googlegroups.com
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

dlots

da leggere,
17 giu 2012, 23:48:1917/06/12
a haxe...@googlegroups.com
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.

Jason O'Neil

da leggere,
17 giu 2012, 23:52:5017/06/12
a haxe...@googlegroups.com
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*

Simon Krajewski

da leggere,
18 giu 2012, 01:17:3218/06/12
a haxe...@googlegroups.com
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

Yamuu

da leggere,
18 giu 2012, 10:05:2618/06/12
a haxe...@googlegroups.com
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);
}

Nicolas Cannasse

da leggere,
18 giu 2012, 10:44:2618/06/12
a haxe...@googlegroups.com
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

Benjamin Dubois

da leggere,
18 giu 2012, 11:58:4718/06/12
a haxe...@googlegroups.com
Looks I don't have excuse to avoid macro anymore :)

Ben

Marc Weber

da leggere,
18 giu 2012, 12:03:5318/06/12
a haxelang
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

Michiel Crefcoeur

da leggere,
18 giu 2012, 13:13:3918/06/12
a haxe...@googlegroups.com
haxe.awesomeness++;

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

Cauê Waneck

da leggere,
18 giu 2012, 14:00:5918/06/12
a haxe...@googlegroups.com
Whoa, that's great!!! :) :)

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

Nicolas Cannasse

da leggere,
18 giu 2012, 15:03:5518/06/12
a haxe...@googlegroups.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.

Best,
Nicolas

Cauê Waneck

da leggere,
18 giu 2012, 15:14:0318/06/12
a haxe...@googlegroups.com
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.


Best,
Nicolas

Juraj Kirchheim

da leggere,
18 giu 2012, 15:15:0318/06/12
a haxe...@googlegroups.com
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

Nicolas Cannasse

da leggere,
18 giu 2012, 15:26:4218/06/12
a haxe...@googlegroups.com
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

Stephane Le Dorze

da leggere,
18 giu 2012, 15:32:1918/06/12
a haxe...@googlegroups.com
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 :

Juraj Kirchheim

da leggere,
18 giu 2012, 15:41:2318/06/12
a haxe...@googlegroups.com
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

Marcelo de Moraes Serpa

da leggere,
19 giu 2012, 19:23:2319/06/12
a haxe...@googlegroups.com
Wasn't this somewhat already implemented in tink_macros ?

Looks interesting though,


- Marcelo

Juraj Kirchheim

da leggere,
20 giu 2012, 09:29:3620/06/12
a haxe...@googlegroups.com
It was, but having this as a first class feature is favorable :)

dlots

da leggere,
15 lug 2012, 15:18:3315/07/12
a haxe...@googlegroups.com
@: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 :)

Juraj Kirchheim

da leggere,
16 lug 2012, 05:48:2116/07/12
a haxe...@googlegroups.com
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

Nicolas Cannasse

da leggere,
16 lug 2012, 10:11:0816/07/12
a haxe...@googlegroups.com
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
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi