What are AST Macros?
Chad J
chadjoan at __spam.is.bad__gmail.com
Sun Jul 11 13:12:18 PDT 2010
On 07/11/2010 12:58 PM, Rory McGuire wrote:
> On Sun, 11 Jul 2010 15:29:36 +0200, Michel Fortin
> <michel.fortin at michelf.com> wrote:
>
>> On 2010-07-11 08:47:26 -0400, "Lars T. Kyllingstad"
>> <public at 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
More information about the Digitalmars-d
mailing list