Reflection Syntax Options Summary

Document #: P3419
Date: 2024-10-08
Project: Programming Language C++
Audience: EWG
Reply-to: Michael Levine
<>

1 Goals

This paper presents a summary of reflection syntax options. Some of these options are activately under consideration, while others have already been discussed and dismissed. However, the reasons for their dismissal have not necessary been recorded in a central location showcasing their perceived advantages or disadvantages relative to other options. This paper intends to be a reference for such discussions. A specific non-goal of the paper is the promotion of a particular syntax.

2 Some Potential Operator Pairs

#
Get Meta
Splice in Meta
1 @<foo @>foo
2 ^^foo [: foo :]
3 ^^foo ,,foo
4 <-foo ->foo
5 $$foo $foo
6 `foo ,foo
7 ^foo [: foo :]
8 @<<foo >>@foo
9 @<-foo ->@foo
10 <@foo @>foo
11 <@foo >@foo
12 &&foo &&>foo
13 :foo $foo
14 /foo \foo
15 ^^foo $$foo
16 ``foo ,,foo
17 @<<foo @>>foo
18 @<-foo @->foo

3 Get Meta Operator Options

3.1 Summary

#
Syntax
1 ^^foo
2 ^foo
3 @<foo
4 @<<foo
5 @<-foo
6 <@foo
7 |foo
8 /foo
9 %foo
10 `foo
11 :foo
12 ~~foo
13 ^-foo
14 <-foo
15 -<foo
16 ^%foo
17 $$foo
18 &&foo
19 @foo
20 #foo
21 $foo
22 'foo
23 =foo
24 ?foo
25 \foo
26 ^[foo]
27 ${foo}
28 $(foo)
29 /\foo
30 ``foo

3.2 Advantages and Disadvantages

# 1: ^^foo

# 2: ^foo

# 3: @<foo

# 4: @<<foo

# 5: @<-foo

# 7: |foo

# 8: /foo

# 9: %foo

# 10: `foo

# 11: :foo

# 12: ~~foo

# 13: ^-foo

# 14: <-foo

# 18: &&foo

# 19: @foo

# 20: #foo

# 21: $foo

# 23: =foo

# 24: ?foo

# 25: \foo

# 26: ^[foo]

# 27: ${foo}

# 28: $(foo)

# 29: /\foo

# 30: ``foo

4 Splicing in Meta Operator Options

4.1 Summary

#
Syntax
1 [: foo :]
2 @>foo
3 @>>foo
4 @->foo
5 foo@>
6 (: foo :)
7 (^ foo ^)
8 (^_ foo _^)
9 ->foo
10 >-foo
11 $foo
12 $$foo
13 ,foo
14 ,,foo
15 &&>foo
16 foo@
17 [| foo |]
18 ${foo}
19 $(foo)
20 ,@foo
21 foo&&
22 >>@foo
23 ->@foo

4.2 Advantages and Disadvantages

# 6: (: foo :)

# 9: ->foo

# 10: >-foo

# 11: $foo

# 13: ,foo

# 14: ,,foo

# 17: [| foo |]

# 18 ${foo}

# 19 $(foo)

# 20: ,@foo

5 Get Meta Contextual and Function Keywords

5.1 Summary

#
Syntax
1 lift foo
2 lift(foo)
3 reflexpr foo
4 reflexpr(foo)
5 refl foo
6 refl(foo)
7 ref foo
8 ref(foo)
9 meta foo
10 meta(foo)
11 symbol foo
12 symbol(foo)
13 syntax foo
14 syntax(foo)
15 expr foo
16 expr(foo)
17 reflect foo
18 reflect(foo)
19 metafy foo
20 metafy(foo)
21 metify foo
22 metify(foo)
23 inspect foo
24 inspect(foo)
25 reflectof foo
26 reflectof(foo)
27 reflof foo
28 reflof(foo)
29 metaof foo
30 metaof(foo)
31 std::meta::meta(foo)
32 std::meta::get(foo)
33 std::meta::parse(foo)

5.2 Advantages and Disadvantages

# 4: reflexpr(foo)

# 15: expr foo

# 16: expr(foo)

6 Splice in Meta Contextual and Function Keywords

6.1 Summary

#
Syntax
1 splice foo
2 splice(foo)
3 splice_in foo
4 splice_in(foo)
5 eval foo
6 eval(foo)
7 evalmeta foo
8 evalmeta(foo)
9 unlift foo
10 unlift(foo)
11 demeta foo
12 demeta(foo)
13 unmeta foo
14 unmeta(foo)
15 unref foo
16 unref(foo)
17 deref foo
18 deref(foo)
19 unrefl foo
20 unrefl(foo)
21 derefl foo
22 derefl(foo)
23 value foo
24 value(foo)
25 getvalue foo
26 getvalue(foo)
27 unexpr foo
28 unexpr(foo)
29 deexpr foo
30 deexpr(foo)
31 dereflect foo
32 dereflect(foo)
33 unreflect foo
34 unreflect(foo)
35 demetafy foo
36 demetafy(foo)
37 unmetafy foo
38 unmetafy(foo)
39 unmetify foo
40 unmetify(foo)
41 uninspect foo
42 uninspect(foo)
43 deinspect foo
44 deinspect(foo)
45 dump foo
46 dump(foo)
47 unsyntax foo
48 unsyntax(foo)
49 desyntax foo
50 desyntax(foo)
51 desugar foo
52 desugar(foo)
53 unsymbol foo
54 unsymbol(foo)
55 desymbol foo
56 desymbol(foo)
57 unreflexpr foo
58 unreflexpr(foo)

6.2 Advantages and Disadvantages

# 17: deref foo

# 18: deref(foo)

# 58: unreflexpr(foo)

7 General Syntax Types

7.1 Summary

#
Syntax Type
1 Unary prefix operators
2 Bounded splice operators
3 Single character splice operators
4 Function keywords
5 Contextual keywords
6 Library functions

7.2 Advantages and Disadvantages

# 1: Unary prefix operators

# 2: Bounded splice operators

# 3: Single character splice operators

# 4: Function keywords

# 5: Contextual keywords

8 Acknowledgements

Some of the syntax ideas, as well as their respective advantages and disadvantages, are my own, but many others came from discussions with Alisdair Meredith and a number of my other colleagues and peers.

9 References

[CLSpec] Common Lisp HyperSpec: 2.4.6 Backquote.
https://www.lispworks.com/documentation/HyperSpec/Body/02_df.htm
[GoChannels] Go by Example: Channel Directions.
https://gobyexample.com/channel-directions
[JuliaMeta] Julia Programming Language Documentation: Metaprogramming.
https://docs.julialang.org/en/v1/manual/metaprogramming/
[P1240R0] Andrew Sutton, Faisal Vali, and Daveed Vandevoorde. 2018-08-10. Scalable Reflection in C++. (August 2018).
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1240r0.pdf
[P2688R1] Michael Park. 2024-02-15. Pattern Matching: match Expression. (February 2024).
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2688r1.pdf
[P3294R1] Andrei Alexandrescu, Barry Revzin, and Daveed Vandevoorde. 2024-07-16. Code Injection with Token Sequences. (July 2024).
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3294r1.html
[P3381R0] Wyatt Childers, Peter Dimov, Dan Katz, Barry Revzin, Andrew Sutton, Faisal Vali, and Daveed Vandevoorde. 2024-09-16. Syntax for Reflection. (September 2024).
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3381r0.html
[thQuotes] Glasgow Haskell Compiler Documentation: Language Extension: Template Haskell: Quotes Syntax.
https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/template_haskell.html#extension-TemplateHaskellQuotes