Thread overview
Bolts 0.4 meta programming library
Aug 02, 2018
aliak
Aug 02, 2018
John Colvin
Aug 02, 2018
John Colvin
Aug 02, 2018
aliak
Aug 02, 2018
Patrick Schluter
Aug 02, 2018
aliak
Aug 02, 2018
Patrick Schluter
August 02, 2018
Hi, just a release of a meta programming library (https://bolts.dub.pm) that has utilities that I use in personal projects, and that I find in phobos, and or in the forums. A notable difference is that functions here try to operate on any compile time entities if they can be resolved.

I.e.:

int i;
void g0(int) {}
struct S { void g1(int) {} }
alias g2 = (int a) => a;
static assert(isFunctionOver!(g0, int));
static assert(isFunctionOver!(S.g1, 3));
static assert(isFunctionOver!(g2, i));

And there's a "doth" super template that tries to contain most things under what I feel is a nicer api ("is" was taken, so i looked to Shakespearian gibberish :p) and also allows for easier use with meta functions:

E.g.:

int *pi = null;
static assert( doth!3.of!int);
static assert(!doth!pi.nullable);
static assert( doth!((a, b, c, d) => a).functionOver!(int, int, int, int));

int i;
import std.meta: allSatisfy;
static assert(allSatisfy!(doth!int.of, 3, 4, int, i));

Here's an example of a gem adapted from inside the forms/phobos sources as well:

alias a = AliasPack!(1, 2, 3);
alias b = AliasPack!(4, 5, 6);
alias c = AliasPack!(7, 8, 9);

alias d = staticZip!(a, b, c);

static assert(d.length == 3);

static assert(d.Unpack[0].equals!(1, 4, 7));
static assert(d.Unpack[1].equals!(2, 5, 8));
static assert(d.Unpack[2].equals!(3, 6, 9))

static assert(AliasPack!(d.UnpackDeep).equals!(1, 4, 7, 2, 5, 8, 3, 6, 9));

Cheers,
- Ali
August 02, 2018
On Thursday, 2 August 2018 at 07:47:19 UTC, aliak wrote:
> Hi, just a release of a meta programming library (https://bolts.dub.pm) that has utilities that I use in personal projects, and that I find in phobos, and or in the forums. A notable difference is that functions here try to operate on any compile time entities if they can be resolved.
>
> I.e.:
>
> int i;
> void g0(int) {}
> struct S { void g1(int) {} }
> alias g2 = (int a) => a;
> static assert(isFunctionOver!(g0, int));
> static assert(isFunctionOver!(S.g1, 3));
> static assert(isFunctionOver!(g2, i));
>
> And there's a "doth" super template that tries to contain most things under what I feel is a nicer api ("is" was taken, so i looked to Shakespearian gibberish :p) and also allows for easier use with meta functions:
>
> E.g.:
>
> int *pi = null;
> static assert( doth!3.of!int);
> static assert(!doth!pi.nullable);
> static assert( doth!((a, b, c, d) => a).functionOver!(int, int, int, int));
>
> int i;
> import std.meta: allSatisfy;
> static assert(allSatisfy!(doth!int.of, 3, 4, int, i));
>
> Here's an example of a gem adapted from inside the forms/phobos sources as well:
>
> alias a = AliasPack!(1, 2, 3);
> alias b = AliasPack!(4, 5, 6);
> alias c = AliasPack!(7, 8, 9);
>
> alias d = staticZip!(a, b, c);
>
> static assert(d.length == 3);
>
> static assert(d.Unpack[0].equals!(1, 4, 7));
> static assert(d.Unpack[1].equals!(2, 5, 8));
> static assert(d.Unpack[2].equals!(3, 6, 9))
>
> static assert(AliasPack!(d.UnpackDeep).equals!(1, 4, 7, 2, 5, 8, 3, 6, 9));
>
> Cheers,
> - Ali

This looks cool. Lots of things that lots of people have reimplemented lots of times over the years, but all in one place and documented.

2 points:

1) Are you aware of this: https://github.com/dlang/phobos/blob/master/std/meta.d ? I think if a bunch of good motivating examples are given, making this public would be possible. Then everyone would be using the same one and your library would truly just be utilities.
August 02, 2018
On Thursday, 2 August 2018 at 08:40:55 UTC, John Colvin wrote:
> On Thursday, 2 August 2018 at 07:47:19 UTC, aliak wrote:
>> Hi, just a release of a meta programming library (https://bolts.dub.pm) that has utilities that I use in personal projects, and that I find in phobos, and or in the forums. A notable difference is that functions here try to operate on any compile time entities if they can be resolved.
>>
>> I.e.:
>>
>> int i;
>> void g0(int) {}
>> struct S { void g1(int) {} }
>> alias g2 = (int a) => a;
>> static assert(isFunctionOver!(g0, int));
>> static assert(isFunctionOver!(S.g1, 3));
>> static assert(isFunctionOver!(g2, i));
>>
>> And there's a "doth" super template that tries to contain most things under what I feel is a nicer api ("is" was taken, so i looked to Shakespearian gibberish :p) and also allows for easier use with meta functions:
>>
>> E.g.:
>>
>> int *pi = null;
>> static assert( doth!3.of!int);
>> static assert(!doth!pi.nullable);
>> static assert( doth!((a, b, c, d) => a).functionOver!(int, int, int, int));
>>
>> int i;
>> import std.meta: allSatisfy;
>> static assert(allSatisfy!(doth!int.of, 3, 4, int, i));
>>
>> Here's an example of a gem adapted from inside the forms/phobos sources as well:
>>
>> alias a = AliasPack!(1, 2, 3);
>> alias b = AliasPack!(4, 5, 6);
>> alias c = AliasPack!(7, 8, 9);
>>
>> alias d = staticZip!(a, b, c);
>>
>> static assert(d.length == 3);
>>
>> static assert(d.Unpack[0].equals!(1, 4, 7));
>> static assert(d.Unpack[1].equals!(2, 5, 8));
>> static assert(d.Unpack[2].equals!(3, 6, 9))
>>
>> static assert(AliasPack!(d.UnpackDeep).equals!(1, 4, 7, 2, 5, 8, 3, 6, 9));
>>
>> Cheers,
>> - Ali
>
> This looks cool. Lots of things that lots of people have reimplemented lots of times over the years, but all in one place and documented.
>
> 2 points:
>
> 1) Are you aware of this: https://github.com/dlang/phobos/blob/master/std/meta.d ? I think if a bunch of good motivating examples are given, making this public would be possible. Then everyone would be using the same one and your library would truly just be utilities.

woops, pressed send too early:

2) I don't think "doth" is synonymous with "is" how you're using it. "doth" is for doing, e.g.

"Methinks he doth protest too much" or "This code doth stink" is OK

"Green doth a colour" or "strstr doth a function" is not OK.
August 02, 2018
On Thursday, 2 August 2018 at 08:45:33 UTC, John Colvin wrote:
> On Thursday, 2 August 2018 at 08:40:55 UTC, John Colvin wrote:
>> This looks cool. Lots of things that lots of people have reimplemented lots of times over the years, but all in one place and documented.
>>
>> 2 points:
>>
>> 1) Are you aware of this: https://github.com/dlang/phobos/blob/master/std/meta.d ? I think if a bunch of good motivating examples are given, making this public would be possible. Then everyone would be using the same one and your library would truly just be utilities.

Thanks! And yes, totally aware of that. I have tried to link to relevant forum posts and will try to add more as I go along to where the usages were concocted. So I guess those could be the motivations?

But it'd also be nice to just use it for a while and get feedback and experience with the names/APIs/functionalities/etc before adding it to std.meta. Though being in std would be ideal of course.

>
> woops, pressed send too early:
>
> 2) I don't think "doth" is synonymous with "is" how you're using it. "doth" is for doing, e.g.
>
> "Methinks he doth protest too much" or "This code doth stink" is OK
>
> "Green doth a colour" or "strstr doth a function" is not OK.

Dammit! You're right! Thank you for pointing that out.

Art! It's Art! ... or maybe i can use a hipster "is" ... i.e. "iz" :p

Cheers,
- Ali
August 02, 2018
On Thursday, 2 August 2018 at 08:45:33 UTC, John Colvin wrote:
> On Thursday, 2 August 2018 at 08:40:55 UTC, John Colvin wrote:
>> [...]
>
> woops, pressed send too early:
>
> 2) I don't think "doth" is synonymous with "is" how you're using it. "doth" is for doing, e.g.
>
> "Methinks he doth protest too much" or "This code doth stink" is OK
>
> "Green doth a colour" or "strstr doth a function" is not OK.

Isn't "doth" just an antiquated orthography of "does"?
August 02, 2018
On Thursday, 2 August 2018 at 10:31:02 UTC, aliak wrote:
> On Thursday, 2 August 2018 at 08:45:33 UTC, John Colvin wrote:
>>> [...]
>
> Thanks! And yes, totally aware of that. I have tried to link to relevant forum posts and will try to add more as I go along to where the usages were concocted. So I guess those could be the motivations?
>
> But it'd also be nice to just use it for a while and get feedback and experience with the names/APIs/functionalities/etc before adding it to std.meta. Though being in std would be ideal of course.
>
>> [...]
>
> Dammit! You're right! Thank you for pointing that out.
>
> Art! It's Art! ... or maybe i can use a hipster "is" ... i.e. "iz" :p
>

’tis like in "’Tis the season to be jolly."

https://en.wiktionary.org/wiki/'tis
Ok, Unicode (’ U+2019) in a symbol is not nice but works normally in D. :-)


August 02, 2018
On Thursday, 2 August 2018 at 12:06:16 UTC, Patrick Schluter wrote:
> On Thursday, 2 August 2018 at 10:31:02 UTC, aliak wrote:
>> On Thursday, 2 August 2018 at 08:45:33 UTC, John Colvin wrote:
>>>> [...]
>>
>> Thanks! And yes, totally aware of that. I have tried to link to relevant forum posts and will try to add more as I go along to where the usages were concocted. So I guess those could be the motivations?
>>
>> But it'd also be nice to just use it for a while and get feedback and experience with the names/APIs/functionalities/etc before adding it to std.meta. Though being in std would be ideal of course.
>>
>>> [...]
>>
>> Dammit! You're right! Thank you for pointing that out.
>>
>> Art! It's Art! ... or maybe i can use a hipster "is" ... i.e. "iz" :p
>>
>
> ’tis like in "’Tis the season to be jolly."
>
> https://en.wiktionary.org/wiki/'tis
> Ok, Unicode (’ U+2019) in a symbol is not nice but works normally in D. :-)

Hehe,  I went with iz, and now the docs for iz reads:

"Iz is is - reason for choosing iz is because is is a keyword"

:-D

Are you sure about being able to use U+2019? I get: Error: character 0x2019 is not a valid token