Date: Wed, 7 Apr 2021 12:10:59 -0400
You raise an interesting possibility (a "reference" analogue for reflections, discussed below), but first — I’m not quite sure what you mean that reflections are strongly typed, as my understanding is that the type of any reflection is `meta::info`. The term "strongly-typed" is used in P2320, but (I think) to simply refer to the possibility of distinguishing between splices of namespaces vs. templates vs. classes vs. expressions etc (a possibility P2320 rejects in favor of a single splice notation used for all). Or am I missing something?
As to why splice notation is needed more generally, I find it helpful to analogize "reflecting" something to taking its address, and "splicing" to dereferencing that address. Indeed, during constant evaluation, reflections could be used in place of pointers (though note that type information is lost by doing this):
```
constexpr int i;
constexpr int *ip = &i;
constexpr meta::info ir = ^i;
constexpr int *ipp = &ip;
constexpr meta::info irr = ^ir;
constexpr int icopyFromP = *ip;
constexpr int icopyFromPP = **ipp;
constexpr int icopyFromR = [:ir:];
constexpr int icopyFromRR = [:[:ir:]:];
constexpr void change_to_42(int * i) { *i = 42; }
constexpr void change_to_42(meta::info i) { [:i:] = 42; }
// Of course splices can also do many things not possible with pointers:
class Foo {};
template<typename T> class FooTemplate {…};
constexpr meta::info change_to_template(meta::info classrefl) {…}
class Bar : public [:change_to_template(^Foo):]<Bar> {};
```
Nevertheless, this raises an interesting question — if reflection is analogous to creating a pointer to something, which must be explicitly dereferenced, might it be advisable to have an analog of a *reference* for reflections, i.e. something that is automatically dereferenced wherever it is used?
Let’s try it out. Just as a reference to an int would be written `int &`, let’s say a "reference" to a template or a class will be written `template ^` or `class ^` respectively:
```
constexpr template ^change_to_template(class ^classrefl) {...}
class Bar : public change_to_template(^Foo)<Bar> {};
class ^BarRef = Bar;
class Baz : public BarRef {}; //= public Bar
```
This might work against the goal of readability via having [::] "stand out," I’m not sure.
Even if it does though, let's take the pointer/reference analogy even further and try getting rid of `meta::info` altogether, in favor of stronger typing based on pointer notation: just as `int *` refers to a pointer to an int, `[:class:]` or `[:template:]` etc. could refer to a reflection of a class, template etc.:
```
constexpr [:template:] change_to_template([:class:] classrefl) {...}
class Bar : public [:change_to_template(^Foo):]<Bar> {};
[:class:] BarRefl = Bar;
class Baz : public [:BarRefl:] {}; //= public Bar
```
I kinda like that. Definitely an interesting possible extension of the P2320 syntax, worthy of further thought. Unusual reflection kinds (e.g. of expressions) would require some thought, e.g. `[:meta::expr:]` for the pointer analogue and `meta::expr ^` for the reference analogue.
Just for fun, let’s try using $ as the analogy of *, instead of [::]
```
constexpr template $change_to_template(class $classrefl) {...}
class Bar : public ($change_to_template(^Foo))<Bar> {};
class $BarRefl = Bar;
class Baz : public $BarRefl {}; //= public Bar
```
Again I’m not sure how I feel about $ — I do think it is important to not get too cute, to keep in mind readability, which is the goal of [::].
Anyways, this has provoked some interesting thought, hopefully for others as well, thanks!
Dave
> On Apr 7, 2021, at 10:15 AM, René Ferdinand Rivera Morell via SG7 <sg7_at_[hidden]> wrote:
>
> First, sorry for the late reply, I blame slow paper reading :-) Can someone clarify something that I must be missing about the proposed splice syntax. Is there rationale for why one needs any splice syntax at all given that the reflections are strongly typed? At a, probably very ignorant, high level it appears to me that you could just have the reflected names without the "[:R:]". What am I missing?
>
> On Mon, Feb 15, 2021 at 3:26 PM Hana Dusíková via Ext <ext_at_[hidden] <mailto:ext_at_[hidden]>> wrote:
> Hi,
>
> Andrew, Wyatt, and Daveed kindly finished the paper which was mentioned during last SG7 session and because the next SG7 meeting is next week I would like all of you to read the paper and send feedback to SG7 mailing list, so we have as much of information as possible.
>
> The paper is here: https://isocpp.org/files/papers/P2320R0.pdf <https://isocpp.org/files/papers/P2320R0.pdf> and it will be part of the next mailing.
>
> Hana
> _______________________________________________
> Ext mailing list
> Ext_at_[hidden] <mailto:Ext_at_[hidden]>
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/ext <https://lists.isocpp.org/mailman/listinfo.cgi/ext>
> Link to this post: http://lists.isocpp.org/ext/2021/02/15887.php <http://lists.isocpp.org/ext/2021/02/15887.php>
>
>
> --
> -- René Ferdinand Rivera Morell
> -- Don't Assume Anything -- No Supone Nada
> -- Robot Dreams - http://robot-dreams.net <http://robot-dreams.net/>
>
> --
> SG7 mailing list
> SG7_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg7
As to why splice notation is needed more generally, I find it helpful to analogize "reflecting" something to taking its address, and "splicing" to dereferencing that address. Indeed, during constant evaluation, reflections could be used in place of pointers (though note that type information is lost by doing this):
```
constexpr int i;
constexpr int *ip = &i;
constexpr meta::info ir = ^i;
constexpr int *ipp = &ip;
constexpr meta::info irr = ^ir;
constexpr int icopyFromP = *ip;
constexpr int icopyFromPP = **ipp;
constexpr int icopyFromR = [:ir:];
constexpr int icopyFromRR = [:[:ir:]:];
constexpr void change_to_42(int * i) { *i = 42; }
constexpr void change_to_42(meta::info i) { [:i:] = 42; }
// Of course splices can also do many things not possible with pointers:
class Foo {};
template<typename T> class FooTemplate {…};
constexpr meta::info change_to_template(meta::info classrefl) {…}
class Bar : public [:change_to_template(^Foo):]<Bar> {};
```
Nevertheless, this raises an interesting question — if reflection is analogous to creating a pointer to something, which must be explicitly dereferenced, might it be advisable to have an analog of a *reference* for reflections, i.e. something that is automatically dereferenced wherever it is used?
Let’s try it out. Just as a reference to an int would be written `int &`, let’s say a "reference" to a template or a class will be written `template ^` or `class ^` respectively:
```
constexpr template ^change_to_template(class ^classrefl) {...}
class Bar : public change_to_template(^Foo)<Bar> {};
class ^BarRef = Bar;
class Baz : public BarRef {}; //= public Bar
```
This might work against the goal of readability via having [::] "stand out," I’m not sure.
Even if it does though, let's take the pointer/reference analogy even further and try getting rid of `meta::info` altogether, in favor of stronger typing based on pointer notation: just as `int *` refers to a pointer to an int, `[:class:]` or `[:template:]` etc. could refer to a reflection of a class, template etc.:
```
constexpr [:template:] change_to_template([:class:] classrefl) {...}
class Bar : public [:change_to_template(^Foo):]<Bar> {};
[:class:] BarRefl = Bar;
class Baz : public [:BarRefl:] {}; //= public Bar
```
I kinda like that. Definitely an interesting possible extension of the P2320 syntax, worthy of further thought. Unusual reflection kinds (e.g. of expressions) would require some thought, e.g. `[:meta::expr:]` for the pointer analogue and `meta::expr ^` for the reference analogue.
Just for fun, let’s try using $ as the analogy of *, instead of [::]
```
constexpr template $change_to_template(class $classrefl) {...}
class Bar : public ($change_to_template(^Foo))<Bar> {};
class $BarRefl = Bar;
class Baz : public $BarRefl {}; //= public Bar
```
Again I’m not sure how I feel about $ — I do think it is important to not get too cute, to keep in mind readability, which is the goal of [::].
Anyways, this has provoked some interesting thought, hopefully for others as well, thanks!
Dave
> On Apr 7, 2021, at 10:15 AM, René Ferdinand Rivera Morell via SG7 <sg7_at_[hidden]> wrote:
>
> First, sorry for the late reply, I blame slow paper reading :-) Can someone clarify something that I must be missing about the proposed splice syntax. Is there rationale for why one needs any splice syntax at all given that the reflections are strongly typed? At a, probably very ignorant, high level it appears to me that you could just have the reflected names without the "[:R:]". What am I missing?
>
> On Mon, Feb 15, 2021 at 3:26 PM Hana Dusíková via Ext <ext_at_[hidden] <mailto:ext_at_[hidden]>> wrote:
> Hi,
>
> Andrew, Wyatt, and Daveed kindly finished the paper which was mentioned during last SG7 session and because the next SG7 meeting is next week I would like all of you to read the paper and send feedback to SG7 mailing list, so we have as much of information as possible.
>
> The paper is here: https://isocpp.org/files/papers/P2320R0.pdf <https://isocpp.org/files/papers/P2320R0.pdf> and it will be part of the next mailing.
>
> Hana
> _______________________________________________
> Ext mailing list
> Ext_at_[hidden] <mailto:Ext_at_[hidden]>
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/ext <https://lists.isocpp.org/mailman/listinfo.cgi/ext>
> Link to this post: http://lists.isocpp.org/ext/2021/02/15887.php <http://lists.isocpp.org/ext/2021/02/15887.php>
>
>
> --
> -- René Ferdinand Rivera Morell
> -- Don't Assume Anything -- No Supone Nada
> -- Robot Dreams - http://robot-dreams.net <http://robot-dreams.net/>
>
> --
> SG7 mailing list
> SG7_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg7
Received on 2021-04-07 11:11:03