Jump to page: 1 24  
Page
Thread overview
[phobos] expand for std.metastrings
Oct 31, 2010
kenji hara
Nov 02, 2010
kenji hara
Nov 02, 2010
Robert Jacques
Nov 02, 2010
kenji hara
Nov 02, 2010
Robert Jacques
Nov 02, 2010
kenji hara
Nov 02, 2010
Robert Jacques
Nov 02, 2010
kenji hara
Nov 02, 2010
kenji hara
Nov 02, 2010
spir
Nov 02, 2010
Jimmy Cao
Nov 02, 2010
Jimmy Cao
Nov 02, 2010
Robert Jacques
Nov 04, 2010
kenji hara
Nov 05, 2010
Robert Jacques
Nov 06, 2010
kenji hara
Nov 03, 2010
kenji hara
Nov 04, 2010
Robert Jacques
Nov 04, 2010
kenji hara
Nov 04, 2010
Robert Jacques
Nov 04, 2010
kenji hara
Nov 02, 2010
spir
Nov 02, 2010
kenji hara
Nov 02, 2010
Denis
Nov 02, 2010
kenji hara
Nov 06, 2010
kenji hara
November 01, 2010
I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)

http://github.com/9rnsr/scrap/blob/master/expand/expand.d

Sample:
----
template GenFunc(string name)
{
  mixin(
    mixin(expand!q{
      int ${name}(){ return 10; }
    }));
  // result of expand! is:
  //   q{`int ` ~ name ~ `(){ return 10; }`}
}
mixin GenFunc!("test");   // generates function "test" returns int
unittest{
  assert(test() == 10);
}
----

expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.

do you think?

Kenji
November 01, 2010
This is great. It's funny I was thinking the same this morning before having looked over this message.

As expansion using $xxx is called interpolation in Perl and probably other scripting languages I suggest we call the facility "inter".

We can use it with writeln, which I think will be quite popular:

int a = 2;
string b = "hello";
writeln(mixin(inter!"I told you $a times: $str!"));

As shown above, I also suggest that we don't require {} when the expression is an identifier.

A debatable language change would allow us to eliminate "mixin", as it has been discussed in the newsgroup. A simpler and less dangerous change would be to make the paren optional:

writeln(mixin inter!"I told you $a times: $str!");



Andrei

On 10/31/10 10:50 AM, kenji hara wrote:
> I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)
>
> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>
> Sample:
> ----
> template GenFunc(string name)
> {
>    mixin(
>      mixin(expand!q{
>        int ${name}(){ return 10; }
>      }));
>    // result of expand! is:
>    //   q{`int ` ~ name ~ `(){ return 10; }`}
> }
> mixin GenFunc!("test");   // generates function "test" returns int
> unittest{
>    assert(test() == 10);
> }
> ----
>
> expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.
>
> do you think?
>
> Kenji
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
November 02, 2010
Thanks for your response, Andrei.

I applied improvements that suggested from you.
- Identifier expression currently does not require braces.
- Interpolation expression is converted to string implicitly (with
std.conv.to!string(...)).

It is still not renamed to 'inter' in github, but I would to do it when committing to Phobos.

Kenji Hara

2010/11/2 Andrei Alexandrescu <andrei at erdani.com>:
> This is great. It's funny I was thinking the same this morning before having looked over this message.
>
> As expansion using $xxx is called interpolation in Perl and probably other scripting languages I suggest we call the facility "inter".
>
> We can use it with writeln, which I think will be quite popular:
>
> int a = 2;
> string b = "hello";
> writeln(mixin(inter!"I told you $a times: $str!"));
>
> As shown above, I also suggest that we don't require {} when the expression is an identifier.
>
> A debatable language change would allow us to eliminate "mixin", as it has been discussed in the newsgroup. A simpler and less dangerous change would be to make the paren optional:
>
> writeln(mixin inter!"I told you $a times: $str!");
>
>
>
> Andrei
>
> On 10/31/10 10:50 AM, kenji hara wrote:
>>
>> I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)
>>
>> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>>
>> Sample:
>> ----
>> template GenFunc(string name)
>> {
>> ? mixin(
>> ? ? mixin(expand!q{
>> ? ? ? int ${name}(){ return 10; }
>> ? ? }));
>> ? // result of expand! is:
>> ? // ? q{`int ` ~ name ~ `(){ return 10; }`}
>> }
>> mixin GenFunc!("test"); ? // generates function "test" returns int
>> unittest{
>> ? assert(test() == 10);
>> }
>> ----
>>
>> expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.
>>
>> do you think?
>>
>> Kenji
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
November 02, 2010
Thanks, Kenji. All - ideas for a better name? "interp"? Full "interpolate"? Leave it as "expand"?

Andrei

On 11/2/10 5:40 AM, kenji hara wrote:
> Thanks for your response, Andrei.
>
> I applied improvements that suggested from you.
> - Identifier expression currently does not require braces.
> - Interpolation expression is converted to string implicitly (with
> std.conv.to!string(...)).
>
> It is still not renamed to 'inter' in github, but I would to do it when committing to Phobos.
>
> Kenji Hara
>
> 2010/11/2 Andrei Alexandrescu<andrei at erdani.com>:
>> This is great. It's funny I was thinking the same this morning before having looked over this message.
>>
>> As expansion using $xxx is called interpolation in Perl and probably other scripting languages I suggest we call the facility "inter".
>>
>> We can use it with writeln, which I think will be quite popular:
>>
>> int a = 2;
>> string b = "hello";
>> writeln(mixin(inter!"I told you $a times: $str!"));
>>
>> As shown above, I also suggest that we don't require {} when the expression is an identifier.
>>
>> A debatable language change would allow us to eliminate "mixin", as it has been discussed in the newsgroup. A simpler and less dangerous change would be to make the paren optional:
>>
>> writeln(mixin inter!"I told you $a times: $str!");
>>
>>
>>
>> Andrei
>>
>> On 10/31/10 10:50 AM, kenji hara wrote:
>>>
>>> I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)
>>>
>>> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>>>
>>> Sample:
>>> ----
>>> template GenFunc(string name)
>>> {
>>>    mixin(
>>>      mixin(expand!q{
>>>        int ${name}(){ return 10; }
>>>      }));
>>>    // result of expand! is:
>>>    //   q{`int ` ~ name ~ `(){ return 10; }`}
>>> }
>>> mixin GenFunc!("test");   // generates function "test" returns int
>>> unittest{
>>>    assert(test() == 10);
>>> }
>>> ----
>>>
>>> expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.
>>>
>>> do you think?
>>>
>>> Kenji
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
November 02, 2010
One more thing - for efficiency, instead of using to!string, I suggest you use formattedWrite with "%s" as format string and an appender as writer.

Andrei

On 11/2/10 5:40 AM, kenji hara wrote:
> Thanks for your response, Andrei.
>
> I applied improvements that suggested from you.
> - Identifier expression currently does not require braces.
> - Interpolation expression is converted to string implicitly (with
> std.conv.to!string(...)).
>
> It is still not renamed to 'inter' in github, but I would to do it when committing to Phobos.
>
> Kenji Hara
>
> 2010/11/2 Andrei Alexandrescu<andrei at erdani.com>:
>> This is great. It's funny I was thinking the same this morning before having looked over this message.
>>
>> As expansion using $xxx is called interpolation in Perl and probably other scripting languages I suggest we call the facility "inter".
>>
>> We can use it with writeln, which I think will be quite popular:
>>
>> int a = 2;
>> string b = "hello";
>> writeln(mixin(inter!"I told you $a times: $str!"));
>>
>> As shown above, I also suggest that we don't require {} when the expression is an identifier.
>>
>> A debatable language change would allow us to eliminate "mixin", as it has been discussed in the newsgroup. A simpler and less dangerous change would be to make the paren optional:
>>
>> writeln(mixin inter!"I told you $a times: $str!");
>>
>>
>>
>> Andrei
>>
>> On 10/31/10 10:50 AM, kenji hara wrote:
>>>
>>> I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)
>>>
>>> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>>>
>>> Sample:
>>> ----
>>> template GenFunc(string name)
>>> {
>>>    mixin(
>>>      mixin(expand!q{
>>>        int ${name}(){ return 10; }
>>>      }));
>>>    // result of expand! is:
>>>    //   q{`int ` ~ name ~ `(){ return 10; }`}
>>> }
>>> mixin GenFunc!("test");   // generates function "test" returns int
>>> unittest{
>>>    assert(test() == 10);
>>> }
>>> ----
>>>
>>> expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.
>>>
>>> do you think?
>>>
>>> Kenji
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
November 02, 2010
On Tue, 02 Nov 2010 10:03:23 -0400, Andrei Alexandrescu <andrei at erdani.com> wrote:

> Thanks, Kenji. All - ideas for a better name? "interp"? Full "interpolate"? Leave it as "expand"?
>
> Andrei

Well, "interpolate" and "interp" have mathematical connotations to me, so vote-- for those. Note that functionality of this seems very similar to both format and text:

enum int a = 10;
enum string op = "+";
static assert(mixin(expand!q{ ${a*2} ${op} 2 }) == q{ 20 + 2 });
vs.
static assert(Format!(" %s %s 2 ",a*2,op)) == q{ 20 + 2 });
vs.
static assert(text(" ",a*2," ",op," 2 ") == q{ 20 + 2 };

So maybe some variant of format would be appropriate: MixinFormat, mFormat, mText, FormatInPlace, etc, though these all seem clunky. MixinFormat would make a lot of sense if you could declare a template that's always a mixin, and could simply write MixinFormat!q{ ${a*2} ${op} 2 } instead of mixin(MixinFormat!q{ ${a*2} ${op} 2 }). As this syntax comes from perl, we could use that as a prefix: perlFormat / pFormat / perlText / pText.

Also, am I missing something with regard to the use cases of expand/inter? All the examples given in the documentation seem to be better served by either text or Format.
November 02, 2010
On Tue, 02 Nov 2010 09:03:23 -0500
Andrei Alexandrescu <andrei at erdani.com> wrote:

> Thanks, Kenji. All - ideas for a better name? "interp"? Full "interpolate"? Leave it as "expand"?

In my opinion, "inter" is far to vague. I would vote for full word if I had to vote ;-); at least with "interp" one has a chance to guess right...
By the way, some call these strings "variable strings": indeed, they have variable parts -- most commonly denoted by variable names.

Denis
-- -- -- -- -- -- --
vit esse estrany ?

spir.wikidot.com

November 03, 2010
I like some short name on clear meaning.

I googled "variable expansion" and "interpolation|interp" with some
language names.
There was no significant difference in result.

(I'm not a native English speaker. Please read follows with a grain of salt.)

"interp" may remind us "interpolation(=variable expansion)",
"interpolation(math)", and "interpreter".
On the other hand, "expand" is more general word than "interp".
So, I think that "interp" will be more better .

Kenji

2010/11/2 Andrei Alexandrescu <andrei at erdani.com>:
> Thanks, Kenji. All - ideas for a better name? "interp"? Full "interpolate"? Leave it as "expand"?
>
> Andrei
>
> On 11/2/10 5:40 AM, kenji hara wrote:
>>
>> Thanks for your response, Andrei.
>>
>> I applied improvements that suggested from you.
>> - Identifier expression currently does not require braces.
>> - Interpolation expression is converted to string implicitly (with
>> std.conv.to!string(...)).
>>
>> It is still not renamed to 'inter' in github, but I would to do it when committing to Phobos.
>>
>> Kenji Hara
>>
>> 2010/11/2 Andrei Alexandrescu<andrei at erdani.com>:
>>>
>>> This is great. It's funny I was thinking the same this morning before
>>> having
>>> looked over this message.
>>>
>>> As expansion using $xxx is called interpolation in Perl and probably
>>> other
>>> scripting languages I suggest we call the facility "inter".
>>>
>>> We can use it with writeln, which I think will be quite popular:
>>>
>>> int a = 2;
>>> string b = "hello";
>>> writeln(mixin(inter!"I told you $a times: $str!"));
>>>
>>> As shown above, I also suggest that we don't require {} when the
>>> expression
>>> is an identifier.
>>>
>>> A debatable language change would allow us to eliminate "mixin", as it
>>> has
>>> been discussed in the newsgroup. A simpler and less dangerous change
>>> would
>>> be to make the paren optional:
>>>
>>> writeln(mixin inter!"I told you $a times: $str!");
>>>
>>>
>>>
>>> Andrei
>>>
>>> On 10/31/10 10:50 AM, kenji hara wrote:
>>>>
>>>> I wrote a trivial utility template for generating code string. This provides some easiness and viewability of metaprogramming. (This is currently used in my adaptTo.)
>>>>
>>>> http://github.com/9rnsr/scrap/blob/master/expand/expand.d
>>>>
>>>> Sample:
>>>> ----
>>>> template GenFunc(string name)
>>>> {
>>>> ? mixin(
>>>> ? ? mixin(expand!q{
>>>> ? ? ? int ${name}(){ return 10; }
>>>> ? ? }));
>>>> ? // result of expand! is:
>>>> ? // ? q{`int ` ~ name ~ `(){ return 10; }`}
>>>> }
>>>> mixin GenFunc!("test"); ? // generates function "test" returns int
>>>> unittest{
>>>> ? assert(test() == 10);
>>>> }
>>>> ----
>>>>
>>>> expand!q{ codes... } parses D code string, and expands ${ expr } for embedding expr that is expression evaluated as string in compile-time.
>>>>
>>>> do you think?
>>>>
>>>> Kenji
>>>> _______________________________________________
>>>> phobos mailing list
>>>> phobos at puremagic.com
>>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>
>>> _______________________________________________
>>> phobos mailing list
>>> phobos at puremagic.com
>>> http://lists.puremagic.com/mailman/listinfo/phobos
>>>
>> _______________________________________________
>> phobos mailing list
>> phobos at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/phobos
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
November 02, 2010
The definition of inter -- to bury a dead body in the ground :)

I don't think inter is right.

I like expand, it has precedence (e.g. expanding environment variables).

-Steve



----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> 
> Thanks, Kenji. All - ideas for a better name? "interp"? Full "interpolate"?  Leave it as "expand"?




November 02, 2010
hm... I swore I saw inter, not interp.

I still think expand sounds better.  Interpolate to me doesn't sound right, it reminds me of image enhancement, not substitution.

-Steve



----- Original Message ----
> From: Steve Schveighoffer <schveiguy at yahoo.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Tue, November 2, 2010 11:57:10 AM
> Subject: Re: [phobos] expand for std.metastrings
> 
> The definition of inter -- to bury a dead body in the ground :)
> 
> I don't  think inter is right.
> 
> I like expand, it has precedence (e.g. expanding  environment variables).
> 
> -Steve
> 
> 
> 
> ----- Original Message  ----
> > From: Andrei Alexandrescu <andrei at erdani.com>
> > 
> >  Thanks, Kenji. All - ideas for a better name? "interp"? Full
> >  "interpolate"?  Leave it as "expand"?
> 
> 
> 
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> 



« First   ‹ Prev
1 2 3 4