July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | On 2010-07-11 08:47:26 -0400, "Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> said: > On Sun, 11 Jul 2010 14:26:51 +0200, Philippe Sigaud wrote: > >> That's interesting. Do you have a link or any text I could read on that? >> String mixins sure are powerful, but I can't get ird of a feeling of >> 'cheating' when using them. Maybe with some kind of string interpolation >> they could be made more palatable to some? > > I find that using token strings, q{ ... }, rather than ordinary "..." > strings, sometimes makes string mixins feel less like a hack. Especially > considering that my editor (vim) highlights token strings like ordinary > code -- or, more likely, it doesn't recognise them as strings. ;) Personally, I find it *more* like a hack. q{...} is just a way to disguise a string as not being one, it's like using a second hack to better hide the first hack. But it's too hacks instead of one, and thus it's more obscure. That said, I don't feel like I'm cheating when using string mixins. I find them a quite good substitute to AST macros. And perhaps string mixins are simpler too: you don't have to learn a new macro syntax, you just manipulate strings. Though I'm still waiting for the day we can use string mixins in expressions to do things like this: int num = 1; string result = substitute!"Number: $num"; assert(result == "Number: 1"); -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin <michel.fortin@michelf.com> wrote:
> On 2010-07-11 08:47:26 -0400, "Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> said:
>
>> On Sun, 11 Jul 2010 14:26:51 +0200, Philippe Sigaud wrote:
>>
>>> That's interesting. Do you have a link or any text I could read on that?
>>> String mixins sure are powerful, but I can't get ird of a feeling of
>>> 'cheating' when using them. Maybe with some kind of string interpolation
>>> they could be made more palatable to some?
>> I find that using token strings, q{ ... }, rather than ordinary "..."
>> strings, sometimes makes string mixins feel less like a hack. Especially
>> considering that my editor (vim) highlights token strings like ordinary
>> code -- or, more likely, it doesn't recognise them as strings. ;)
>
> Personally, I find it *more* like a hack. q{...} is just a way to disguise a string as not being one, it's like using a second hack to better hide the first hack. But it's too hacks instead of one, and thus it's more obscure.
>
> That said, I don't feel like I'm cheating when using string mixins. I find them a quite good substitute to AST macros. And perhaps string mixins are simpler too: you don't have to learn a new macro syntax, you just manipulate strings. Though I'm still waiting for the day we can use string mixins in expressions to do things like this:
>
> int num = 1;
> string result = substitute!"Number: $num";
> assert(result == "Number: 1");
>
someone already made something like that, I forget where it was. Its old now.
|
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Attachments:
| On Sun, Jul 11, 2010 at 18:58, Rory McGuire <rmcguire@neonova.co.za> wrote:
> On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin < michel.fortin@michelf.com> wrote:
>
>>
>> int num = 1;
>> string result = substitute!"Number: $num";
>> assert(result == "Number: 1");
>>
>>
> someone already made something like that, I forget where it was. Its old now.
>
Doesn't Format (in std.metastrings) cover part of this?
string result = Format!("Numbers: %s", to!string(num));
I remember finding it cumbersome to use. For one, it could easily take any
type for argument, and call to!string on them internally. Why bothering me
with this?
But maybe I wasn't using it the right way.
Hmm, I think what I'd like is some numbered substituting scheme:
string result = Substitute!("static if (is (typeof(%1) t == %2!U, U)) {
alias U Result;
else
alias typeof(%1)
Result;",
a,b);
I agree with Rory than someone already did something similar. But I guess now it can be done with CTFE on strings. A CT replace.
Philippe
|
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Attachments:
| On Sun, 11 Jul 2010 21:55:30 +0200, Philippe Sigaud <philippe.sigaud@gmail.com> wrote: > On Sun, Jul 11, 2010 at 18:58, Rory McGuire <rmcguire@neonova.co.za> wrote: >> On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin <michel.fortin@michelf.com> wrote: >>> >>> int num = 1; >>> string result = substitute!"Number: $num"; >>> assert(result == "Number: 1"); >>> >> >> someone already made something like that, I forget where it was. Its old now. > > Doesn't Format (in std.metastrings) cover part of this? > > string result = Format!("Numbers: %s", to!string(num)); > > I remember finding it cumbersome to use. For one, it could easily take any type for argument, and call to!string on them internally. Why > >bothering me with this? > But maybe I wasn't using it the right way. > > Hmm, I think what I'd like is some numbered substituting scheme: > > string result = Substitute!("static if (is (typeof(%1) t == %2!U, U)) { > alias U Result; > else > alias typeof(%1) > Result;", a,b); > > > I agree with Rory than someone already did something similar. But I guess now it can be done with CTFE on strings. A CT replace. > > > Philippe > I think I found what I was thinking of (not sure its the same one): http://www.digitalmars.com/d/archives/digitalmars/D/PHP-style_embedded_variables_print_statements_54053.html -Rory |
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rory McGuire | On 07/11/2010 12:58 PM, Rory McGuire wrote: > On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin <michel.fortin@michelf.com> wrote: > >> On 2010-07-11 08:47:26 -0400, "Lars T. Kyllingstad" <public@kyllingen.NOSPAMnet> said: >> >>> On Sun, 11 Jul 2010 14:26:51 +0200, Philippe Sigaud wrote: >>> >>>> That's interesting. Do you have a link or any text I could read on >>>> that? >>>> String mixins sure are powerful, but I can't get ird of a feeling of >>>> 'cheating' when using them. Maybe with some kind of string >>>> interpolation >>>> they could be made more palatable to some? >>> I find that using token strings, q{ ... }, rather than ordinary "..." >>> strings, sometimes makes string mixins feel less like a hack. >>> Especially >>> considering that my editor (vim) highlights token strings like ordinary >>> code -- or, more likely, it doesn't recognise them as strings. ;) >> >> Personally, I find it *more* like a hack. q{...} is just a way to disguise a string as not being one, it's like using a second hack to better hide the first hack. But it's too hacks instead of one, and thus it's more obscure. >> >> That said, I don't feel like I'm cheating when using string mixins. I find them a quite good substitute to AST macros. And perhaps string mixins are simpler too: you don't have to learn a new macro syntax, you just manipulate strings. Though I'm still waiting for the day we can use string mixins in expressions to do things like this: >> >> int num = 1; >> string result = substitute!"Number: $num"; >> assert(result == "Number: 1"); >> > > someone already made something like that, I forget where it was. Its old now. I doubt it. Not unless they did something more like this: int num = 1; string result = mixin(substitute!"Number: $num"); assert(result == "Number: 1"); It'd be really nice to have some sugar for string mixin usage. It could be tied into templates to do some really awesome things. Some prior discussion: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=105781 |
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chad J | "Chad J" <chadjoan@__spam.is.bad__gmail.com> wrote in message news:i1d8j4$1347$1@digitalmars.com... > On 07/11/2010 12:58 PM, Rory McGuire wrote: >> On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin <michel.fortin@michelf.com> wrote: >>> int num = 1; >>> string result = substitute!"Number: $num"; >>> assert(result == "Number: 1"); >>> >> >> someone already made something like that, I forget where it was. Its old now. > > I doubt it. Not unless they did something more like this: > > int num = 1; > string result = mixin(substitute!"Number: $num"); > assert(result == "Number: 1"); > > It'd be really nice to have some sugar for string mixin usage. It could > be tied into templates to do some really awesome things. > Some prior discussion: > http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=105781 Yea, I was really disappointed the only thing that came out of that was an improvement in instantiating template mixins, but not string mixins. I use string mixins so much more than template ones. |
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don | == Quote from Don (nospam@nospam.com)'s article > Philippe Sigaud wrote: [...] > > String mixins sure are powerful, but I can't get ird of a feeling of 'cheating' when using them. Maybe with some kind of string interpolation they could be made more palatable to some? > There's little doubt that it's the part of the language which needs the most attention in the long term. But the way forward is not at all obvious. So it's been deferred. I'm not clear on how one is supposed to go about making the equivalent of hygienic macros using just string mixins and CTFE. Cheers, Pillsy |
July 11, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to pillsy | Sun, 11 Jul 2010 22:03:56 +0000, pillsy wrote:
> == Quote from Don (nospam@nospam.com)'s article
>
>> Philippe Sigaud wrote:
> [...]
>> > String mixins sure are powerful, but I can't get ird of a feeling of 'cheating' when using them. Maybe with some kind of string interpolation they could be made more palatable to some?
>
>> There's little doubt that it's the part of the language which needs the most attention in the long term. But the way forward is not at all obvious. So it's been deferred.
>
> I'm not clear on how one is supposed to go about making the equivalent of hygienic macros using just string mixins and CTFE.
You can create a trial-and-error gensym function with compile time introspection and CTFE/templates. :o) It's very elegant. CTFE solves all your AST macro use cases.
|
July 12, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to retard | On 07/11/2010 06:57 PM, retard wrote:
> Sun, 11 Jul 2010 22:03:56 +0000, pillsy wrote:
>
>> == Quote from Don (nospam@nospam.com)'s article
>>
>>> Philippe Sigaud wrote:
>> [...]
>>>> String mixins sure are powerful, but I can't get ird of a feeling of
>>>> 'cheating' when using them. Maybe with some kind of string
>>>> interpolation they could be made more palatable to some?
>>
>>> There's little doubt that it's the part of the language which needs the
>>> most attention in the long term. But the way forward is not at all
>>> obvious. So it's been deferred.
>>
>> I'm not clear on how one is supposed to go about making the equivalent
>> of hygienic macros using just string mixins and CTFE.
>
> You can create a trial-and-error gensym function with compile time
> introspection and CTFE/templates. :o) It's very elegant. CTFE solves all
> your AST macro use cases.
Wrong. The correct answer is magic.
|
July 12, 2010 Re: What are AST Macros? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | Ellery Newcomer wrote:
> On 07/11/2010 06:57 PM, retard wrote:
>> Sun, 11 Jul 2010 22:03:56 +0000, pillsy wrote:
>>
>>> == Quote from Don (nospam@nospam.com)'s article
>>>
>>>> Philippe Sigaud wrote:
>>> [...]
>>>>> String mixins sure are powerful, but I can't get ird of a feeling of
>>>>> 'cheating' when using them. Maybe with some kind of string
>>>>> interpolation they could be made more palatable to some?
>>>
>>>> There's little doubt that it's the part of the language which needs the
>>>> most attention in the long term. But the way forward is not at all
>>>> obvious. So it's been deferred.
>>>
>>> I'm not clear on how one is supposed to go about making the equivalent
>>> of hygienic macros using just string mixins and CTFE.
>>
>> You can create a trial-and-error gensym function with compile time
>> introspection and CTFE/templates. :o) It's very elegant. CTFE solves all
>> your AST macro use cases.
>
> Wrong. The correct answer is magic.
Yes, and it has to be that way. The AST macros which people have been talking about are magical.
|
Copyright © 1999-2021 by the D Language Foundation