Topic: Proposal for a built-in macro system for C++


Author: t-ly@directbox.com
Date: Fri, 1 Jan 2016 16:10:24 -0800 (PST)
Raw View
------=_Part_7473_1472219656.1451693424420
Content-Type: multipart/alternative;
 boundary="----=_Part_7474_990991272.1451693424420"

------=_Part_7474_990991272.1451693424420
Content-Type: text/plain; charset=UTF-8

Hey guys,

In the last year I often stumbled upon problems with the awful preprocessor
and macros. I would really like to be able to generate code using c++. This
is why i put together some ideas how a built-in macro system could look
like. Its far from professional or finished, just wanted to what you think
about the idea in general :) I made a markdown file, the link is down below.

Some of the ideas include:

- making it  impossible for macros to accidentally replace identifiers
- writing a macro as a constexpr function that returns a string of code
- explicit operator for expanding a macro to disambiguate the grammar

heres the link:
https://gist.github.com/tly000/4b762f22d1dc950078f7

greetings

tly

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_7474_990991272.1451693424420
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hey guys,<div><br></div><div>In the last year I often stum=
bled upon problems with the awful preprocessor and macros. I would really l=
ike to be able to generate code using c++. This is why i put together some =
ideas how a built-in macro system could look like. Its far from professiona=
l or finished, just wanted to what you think about the idea in general :) I=
 made a markdown file, the link is down below.</div><div><br></div><div>Som=
e of the ideas include:</div><div><br></div><div>- making it =C2=A0impossib=
le for macros to accidentally replace identifiers</div><div>- writing a mac=
ro as a constexpr function that returns a string of code</div><div>- explic=
it operator for expanding a macro to disambiguate the grammar</div><div><br=
></div><div>heres the link:</div><div>https://gist.github.com/tly000/4b762f=
22d1dc950078f7<br></div><div><br></div><div>greetings=C2=A0</div><div><br><=
/div><div>tly</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_7474_990991272.1451693424420--
------=_Part_7473_1472219656.1451693424420--

.


Author: =?UTF-8?Q?Germ=C3=A1n_Diago?= <germandiago@gmail.com>
Date: Fri, 1 Jan 2016 21:59:25 -0800 (PST)
Raw View
------=_Part_113_126013915.1451714365990
Content-Type: multipart/alternative;
 boundary="----=_Part_114_321353940.1451714365990"

------=_Part_114_321353940.1451714365990
Content-Type: text/plain; charset=UTF-8


I read the proposal but I do not have much time now, just a bit of
brainstorming:

Questions:

1- how would you implement a  @scope(exit), etc. from D language?

2- how does it compare to string mixins from D? http://dlang.org/mixin.html

3- can you include the contents of a file at compile-time and replace in a
macro? (useful in many contexts :D)

4- could a safe printf with variable name interpolation (such as python 3
format("{variable}" be implemented on top of this?


Thank you.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_114_321353940.1451714365990
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br>I read the proposal but I do not have much time now, j=
ust a bit of brainstorming:<div><br></div><div>Questions:</div><div><br></d=
iv><div>1- how would you implement a =C2=A0@scope(exit), etc. from D langua=
ge?</div><div><br></div><div>2- how does it compare to string mixins from D=
?=C2=A0http://dlang.org/mixin.html</div><div><br></div><div>3- can you incl=
ude the contents of a file at compile-time and replace in a macro? (useful =
in many contexts :D)</div><div><br></div><div>4- could a safe printf with v=
ariable name interpolation (such as python 3 format(&quot;{variable}&quot; =
be implemented on top of this?</div><div><br></div><div><br></div><div>Than=
k you.</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_114_321353940.1451714365990--
------=_Part_113_126013915.1451714365990--

.


Author: snk_kid <korcan.hussein@googlemail.com>
Date: Sat, 2 Jan 2016 02:58:03 -0800 (PST)
Raw View
------=_Part_8357_778570201.1451732283822
Content-Type: multipart/alternative;
 boundary="----=_Part_8358_1868848446.1451732283822"

------=_Part_8358_1868848446.1451732283822
Content-Type: text/plain; charset=UTF-8

Macro systems based on strings are cumbersome and highly error prone. A
better solution is one based on manipulating the abstract syntax tree (AST)
in a type-safe manner.

On Saturday, January 2, 2016 at 12:10:24 AM UTC, t-...@directbox.com wrote:
>
> Hey guys,
>
> In the last year I often stumbled upon problems with the awful
> preprocessor and macros. I would really like to be able to generate code
> using c++. This is why i put together some ideas how a built-in macro
> system could look like. Its far from professional or finished, just wanted
> to what you think about the idea in general :) I made a markdown file, the
> link is down below.
>
> Some of the ideas include:
>
> - making it  impossible for macros to accidentally replace identifiers
> - writing a macro as a constexpr function that returns a string of code
> - explicit operator for expanding a macro to disambiguate the grammar
>
> heres the link:
> https://gist.github.com/tly000/4b762f22d1dc950078f7
>
> greetings
>
> tly
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_8358_1868848446.1451732283822
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Macro systems based on strings are cumbersome and highly e=
rror prone. A better solution is one based on manipulating the abstract syn=
tax tree (AST) in a type-safe manner.<br><br>On Saturday, January 2, 2016 a=
t 12:10:24 AM UTC, t-...@directbox.com wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;"><div dir=3D"ltr">Hey guys,<div><br></div><div>In the last ye=
ar I often stumbled upon problems with the awful preprocessor and macros. I=
 would really like to be able to generate code using c++. This is why i put=
 together some ideas how a built-in macro system could look like. Its far f=
rom professional or finished, just wanted to what you think about the idea =
in general :) I made a markdown file, the link is down below.</div><div><br=
></div><div>Some of the ideas include:</div><div><br></div><div>- making it=
 =C2=A0impossible for macros to accidentally replace identifiers</div><div>=
- writing a macro as a constexpr function that returns a string of code</di=
v><div>- explicit operator for expanding a macro to disambiguate the gramma=
r</div><div><br></div><div>heres the link:</div><div><a href=3D"https://gis=
t.github.com/tly000/4b762f22d1dc950078f7" target=3D"_blank" rel=3D"nofollow=
" onmousedown=3D"this.href=3D&#39;https://www.google.com/url?q\75https%3A%2=
F%2Fgist.github.com%2Ftly000%2F4b762f22d1dc950078f7\46sa\75D\46sntz\0751\46=
usg\75AFQjCNHQ8DgSbzadzdnRN4-IXLDRi1PdaA&#39;;return true;" onclick=3D"this=
..href=3D&#39;https://www.google.com/url?q\75https%3A%2F%2Fgist.github.com%2=
Ftly000%2F4b762f22d1dc950078f7\46sa\75D\46sntz\0751\46usg\75AFQjCNHQ8DgSbza=
dzdnRN4-IXLDRi1PdaA&#39;;return true;">https://gist.github.com/<wbr>tly000/=
4b762f22d1dc950078f7</a><br></div><div><br></div><div>greetings=C2=A0</div>=
<div><br></div><div>tly</div></div></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_8358_1868848446.1451732283822--
------=_Part_8357_778570201.1451732283822--

.


Author: t-ly@directbox.com
Date: Sat, 2 Jan 2016 03:54:31 -0800 (PST)
Raw View
------=_Part_16_1381160318.1451735671407
Content-Type: multipart/alternative;
 boundary="----=_Part_17_1083416047.1451735671407"

------=_Part_17_1083416047.1451735671407
Content-Type: text/plain; charset=UTF-8


>
> 1- how would you implement a  @scope(exit), etc. from D language?
>

I would create a class, that calls a lambda in the destructor. this can be
wrapped inside a macro function:
https://gist.github.com/tly000/121ee654cf3b5ee652a9.

This is of course a unsafe macro, it only works if a compound-statement is
put behind it. you could also create a "safer" macro, that takes the code
block as a parameter.


>
> 2- how does it compare to string mixins from D?
> http://dlang.org/mixin.html
>

my proposal is not as strict as mixins, because the macros could be
expanded everywhere. one could restrict them further of course. To make it
work anyway, i limited macro expansions inside macro functions to
expressions. this way the compiler could parse any macro function without
any problems.


>
> 3- can you include the contents of a file at compile-time and replace in a
> macro? (useful in many contexts :D)
>

the macro functions can only be constexpr functions, everything else would
be impossible to expand before the compilation. but a built-in @include
macro could be provided ;) if the expanded macro (in this case the "macro
include(macro filename)" function) itself has macro expansions in it, they
should be expanded recursively.


> 4- could a safe printf with variable name interpolation (such as python 3
> format("{variable}" be implemented on top of this?
>
>
well kind of, but it could be a bit hard...
since the macro expansion will be put inside the scope of the macro
function call, the returned string can of course use the local variables.
heres a sketch of the function:
https://gist.github.com/tly000/dab2d24de2ab0aba3649


> Thank you.
>

Thanks for reading my proposal :)

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_17_1083416047.1451735671407
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div>1- how would you implement a =C2=A0@scope(exit), etc. from D langu=
age?<br></div></div></blockquote><div><br></div><div>I would create a class=
, that calls a lambda in the destructor. this can be wrapped inside a macro=
 function:</div><div>https://gist.github.com/tly000/121ee654cf3b5ee652a9.</=
div><div><br></div><div>This is of course a unsafe macro, it only works if =
a compound-statement is put behind it. you could also create a &quot;safer&=
quot; macro, that takes the code block as a parameter.</div><div>=C2=A0</di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div>=
<div><br></div><div>2- how does it compare to string mixins from D?=C2=A0<a=
 href=3D"http://dlang.org/mixin.html" target=3D"_blank" rel=3D"nofollow" on=
mousedown=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fdl=
ang.org%2Fmixin.html\46sa\75D\46sntz\0751\46usg\75AFQjCNFn31QGItqUZ9-V6A3rm=
55H__mYhA&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.google.=
com/url?q\75http%3A%2F%2Fdlang.org%2Fmixin.html\46sa\75D\46sntz\0751\46usg\=
75AFQjCNFn31QGItqUZ9-V6A3rm55H__mYhA&#39;;return true;">http://dlang.org/mi=
xin.html</a></div></div></blockquote><div><br></div><div>my proposal is not=
 as strict as mixins, because the macros could be expanded everywhere. one =
could restrict them further of course. To make it work anyway, i limited ma=
cro expansions inside macro functions to expressions. this way the compiler=
 could parse any macro function without any problems.=C2=A0</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div=
><br></div><div>3- can you include the contents of a file at compile-time a=
nd replace in a macro? (useful in many contexts :D)</div></div></blockquote=
><div><br></div><div>the macro functions can only be constexpr functions, e=
verything else would be impossible to expand before the compilation. but a =
built-in @include macro could be provided ;) if the expanded macro (in this=
 case the &quot;macro include(macro filename)&quot; function) itself has ma=
cro expansions in it, they should be expanded recursively.</div><div>=C2=A0=
</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>4-=
 could a safe printf with variable name interpolation (such as python 3 for=
mat(&quot;{variable}&quot; be implemented on top of this?</div><div><br></d=
iv></div></blockquote><div><br></div><div>well kind of, but it could be a b=
it hard...</div><div>since the macro expansion will be put inside the scope=
 of the macro function call, the returned string can of course use the loca=
l variables.</div><div>heres a sketch of the function:=C2=A0</div><div>http=
s://gist.github.com/tly000/dab2d24de2ab0aba3649<br></div><div>=C2=A0</div><=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><di=
v>Thank you.</div></div></blockquote><div><br></div><div>Thanks for reading=
 my proposal :)=C2=A0</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_17_1083416047.1451735671407--
------=_Part_16_1381160318.1451735671407--

.


Author: t-ly@directbox.com
Date: Sat, 2 Jan 2016 04:03:57 -0800 (PST)
Raw View
------=_Part_7642_1618377356.1451736237811
Content-Type: multipart/alternative;
 boundary="----=_Part_7643_937810154.1451736237812"

------=_Part_7643_937810154.1451736237812
Content-Type: text/plain; charset=UTF-8

On Saturday, January 2, 2016 at 11:58:04 AM UTC+1, snk_kid wrote:
>
> Macro systems based on strings are cumbersome and highly error prone. A
> better solution is one based on manipulating the abstract syntax tree (AST)
> in a type-safe manner.
>

This is true. Your idea would  be possible, if the parameters for a macro
function are parsed and put inside AST objects, that somehow manage types
and scope. These new AST classes could be constructed at compile-time. I
fear that these macro functions could get very complicated and bloated with
C++...

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_7643_937810154.1451736237812
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, January 2, 2016 at 11:58:04 AM UTC+1, snk_kid=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Macro =
systems based on strings are cumbersome and highly error prone. A better so=
lution is one based on manipulating the abstract syntax tree (AST) in a typ=
e-safe manner.<br></div></blockquote><div><br></div><div>This is true. Your=
 idea would =C2=A0be possible, if the parameters for a macro function are p=
arsed and put inside AST objects, that somehow manage types and scope. Thes=
e new AST classes could be constructed at compile-time. I fear that these m=
acro functions could get very complicated and bloated with C++...</div></di=
v>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_7643_937810154.1451736237812--
------=_Part_7642_1618377356.1451736237811--

.


Author: snk_kid <korcan.hussein@googlemail.com>
Date: Sat, 2 Jan 2016 04:52:40 -0800 (PST)
Raw View
------=_Part_8763_658655634.1451739160958
Content-Type: multipart/alternative;
 boundary="----=_Part_8764_1613416198.1451739160965"

------=_Part_8764_1613416198.1451739160965
Content-Type: text/plain; charset=UTF-8

Not my idea, pretty common solution in other languages. I'm not sure what
you mean by parsing macro parameters to generate ASTs but how it's usually
done is you have a few operators such as a quotation operator which tells
the compiler to convert normal code fragments into AST objects that a macro
can use to process. The macro parameter should look like a normal function
parameter which has a type, it might look something like this:

template < typename Tp >
constexpr auto my_macro(const Expr<Tp>& expr) -> Expr<Tp>
{ /* ... * }
/* ... */
/* using *[< **c++-expr* *>]* as a made up syntax for a quotation operator,
that syntax doesn't matter here */
my_macro([< 1 + 2 * 3 >]);

Expr<T> would be some sort of C++ constexpr parametric class or variant
type exposed by a compiler C++ API. Definitely not a trivial thing to
standardize and implement for C++ but would be great to have and you could
take it much further later on.

On Saturday, January 2, 2016 at 12:03:58 PM UTC, t-...@directbox.com wrote:
>
> On Saturday, January 2, 2016 at 11:58:04 AM UTC+1, snk_kid wrote:
>>
>> Macro systems based on strings are cumbersome and highly error prone. A
>> better solution is one based on manipulating the abstract syntax tree (AST)
>> in a type-safe manner.
>>
>
> This is true. Your idea would  be possible, if the parameters for a macro
> function are parsed and put inside AST objects, that somehow manage types
> and scope. These new AST classes could be constructed at compile-time. I
> fear that these macro functions could get very complicated and bloated with
> C++...
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_8764_1613416198.1451739160965
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Not my idea, pretty common solution in other languages. I&=
#39;m not sure what you mean by parsing macro parameters to generate ASTs b=
ut how it&#39;s usually done is you have a few operators such as a quotatio=
n operator which tells the compiler to convert normal code fragments into A=
ST objects that a macro can use to process. The macro parameter should look=
 like a normal function parameter which has a type, it might look something=
 like this:<br><br><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bo=
rder-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">template</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Tp</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> my_macro</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #606;" class=3D"styled-by-prettify">Expr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Tp</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&gt;&amp;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> expr</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">-&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Expr<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: #606;" class=3D"styled-by-prettify">Tp</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">/* ... * }<br>/* ... */</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">/* using </span><b><span style=3D"color: #800;" =
class=3D"styled-by-prettify">[&lt;</span><i><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify"> </span></i></b><i><span style=3D"color: #800;" =
class=3D"styled-by-prettify">c++-expr</span></i><b><span style=3D"color: #8=
00;" class=3D"styled-by-prettify"> </span></b><b><span style=3D"color: #800=
;" class=3D"styled-by-prettify">&gt;]</span></b><span style=3D"color: #800;=
" class=3D"styled-by-prettify"> as a made up syntax for a quotation operato=
r, that syntax doesn&#39;t matter here */</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>my_macro</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">([&lt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">1</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">3</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&gt;]);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span></div></code></div><br>Expr&lt;T&gt; would be some sort of C+=
+ constexpr parametric class or variant type exposed by a compiler C++ API.=
 Definitely not a trivial thing to standardize and implement for C++ but wo=
uld be great to have and you could take it much further later on.<br><br>On=
 Saturday, January 2, 2016 at 12:03:58 PM UTC, t-...@directbox.com wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Saturday, Ja=
nuary 2, 2016 at 11:58:04 AM UTC+1, snk_kid wrote:<blockquote class=3D"gmai=
l_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr">Macro systems based on strings are cumberso=
me and highly error prone. A better solution is one based on manipulating t=
he abstract syntax tree (AST) in a type-safe manner.<br></div></blockquote>=
<div><br></div><div>This is true. Your idea would =C2=A0be possible, if the=
 parameters for a macro function are parsed and put inside AST objects, tha=
t somehow manage types and scope. These new AST classes could be constructe=
d at compile-time. I fear that these macro functions could get very complic=
ated and bloated with C++...</div></div></blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_8764_1613416198.1451739160965--
------=_Part_8763_658655634.1451739160958--

.


Author: t-ly@directbox.com
Date: Sat, 2 Jan 2016 05:43:00 -0800 (PST)
Raw View
------=_Part_7562_1035362962.1451742180281
Content-Type: multipart/alternative;
 boundary="----=_Part_7563_2138242737.1451742180282"

------=_Part_7563_2138242737.1451742180282
Content-Type: text/plain; charset=UTF-8

this Expr<T> syntax almost looks like my macro<T> idea, where the string
inside the macro<T> value must be an expression of type T. Combining this
idea with typesafe operators to compose new statements and code fragments
seems reasonable.

On Saturday, January 2, 2016 at 1:52:41 PM UTC+1, snk_kid wrote:
>
> Not my idea, pretty common solution in other languages. I'm not sure what
> you mean by parsing macro parameters to generate ASTs but how it's usually
> done is you have a few operators such as a quotation operator which tells
> the compiler to convert normal code fragments into AST objects that a macro
> can use to process. The macro parameter should look like a normal function
> parameter which has a type, it might look something like this:
>
> template < typename Tp >
> constexpr auto my_macro(const Expr<Tp>& expr) -> Expr<Tp>
> { /* ... * }
> /* ... */
> /* using *[< **c++-expr* *>]* as a made up syntax for a quotation
> operator, that syntax doesn't matter here */
> my_macro([< 1 + 2 * 3 >]);
>
> Expr<T> would be some sort of C++ constexpr parametric class or variant
> type exposed by a compiler C++ API. Definitely not a trivial thing to
> standardize and implement for C++ but would be great to have and you could
> take it much further later on.
>
> On Saturday, January 2, 2016 at 12:03:58 PM UTC, t-...@directbox.com
> wrote:
>>
>> On Saturday, January 2, 2016 at 11:58:04 AM UTC+1, snk_kid wrote:
>>>
>>> Macro systems based on strings are cumbersome and highly error prone. A
>>> better solution is one based on manipulating the abstract syntax tree (AST)
>>> in a type-safe manner.
>>>
>>
>> This is true. Your idea would  be possible, if the parameters for a macro
>> function are parsed and put inside AST objects, that somehow manage types
>> and scope. These new AST classes could be constructed at compile-time. I
>> fear that these macro functions could get very complicated and bloated with
>> C++...
>>
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_7563_2138242737.1451742180282
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">this Expr&lt;T&gt; syntax almost looks like my macro&lt;T&=
gt; idea, where the string inside the macro&lt;T&gt; value must be an expre=
ssion of type T. Combining this idea with typesafe operators to compose new=
 statements and code fragments seems reasonable.<div><br>On Saturday, Janua=
ry 2, 2016 at 1:52:41 PM UTC+1, snk_kid wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr">Not my idea, pretty common solution in oth=
er languages. I&#39;m not sure what you mean by parsing macro parameters to=
 generate ASTs but how it&#39;s usually done is you have a few operators su=
ch as a quotation operator which tells the compiler to convert normal code =
fragments into AST objects that a macro can use to process. The macro param=
eter should look like a normal function parameter which has a type, it migh=
t look something like this:<br><br><div style=3D"background-color:rgb(250,2=
50,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;w=
ord-wrap:break-word"><code><div><span style=3D"color:#008">template</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">typename</span><=
span style=3D"color:#000"> </span><span style=3D"color:#606">Tp</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#660">&gt;</span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#008">constexpr</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><sp=
an style=3D"color:#000"> my_macro</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#008">const</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">Expr</span><span style=3D"color:#660">&lt;</span>=
<span style=3D"color:#606">Tp</span><span style=3D"color:#660">&gt;&amp;</s=
pan><span style=3D"color:#000"> expr</span><span style=3D"color:#660">)</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">-&gt;</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">Expr</span>=
<span style=3D"color:#660">&lt;</span><span style=3D"color:#606">Tp</span><=
span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#800">/* ... * }<br>/* ... */</span><span style=3D"color:#0=
00"><br></span><span style=3D"color:#800">/* using </span><b><span style=3D=
"color:#800">[&lt;</span><i><span style=3D"color:#800"> </span></i></b><i><=
span style=3D"color:#800">c++-expr</span></i><b><span style=3D"color:#800">=
 </span></b><b><span style=3D"color:#800">&gt;]</span></b><span style=3D"co=
lor:#800"> as a made up syntax for a quotation operator, that syntax doesn&=
#39;t matter here */</span><span style=3D"color:#000"><br>my_macro</span><s=
pan style=3D"color:#660">([&lt;</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">+</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">2</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">*</span><span style=3D"color:#000"> </span><span style=3D"color:=
#066">3</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>&gt;]);</span><span style=3D"color:#000"><br></span></div></code></div><br=
>Expr&lt;T&gt; would be some sort of C++ constexpr parametric class or vari=
ant type exposed by a compiler C++ API. Definitely not a trivial thing to s=
tandardize and implement for C++ but would be great to have and you could t=
ake it much further later on.<br><br>On Saturday, January 2, 2016 at 12:03:=
58 PM UTC, <a>t-...@directbox.com</a> wrote:<blockquote class=3D"gmail_quot=
e" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr">On Saturday, January 2, 2016 at 11:58:04 AM UTC+1=
, snk_kid wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-=
left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Ma=
cro systems based on strings are cumbersome and highly error prone. A bette=
r solution is one based on manipulating the abstract syntax tree (AST) in a=
 type-safe manner.<br></div></blockquote><div><br></div><div>This is true. =
Your idea would =C2=A0be possible, if the parameters for a macro function a=
re parsed and put inside AST objects, that somehow manage types and scope. =
These new AST classes could be constructed at compile-time. I fear that the=
se macro functions could get very complicated and bloated with C++...</div>=
</div></blockquote></div></blockquote></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_7563_2138242737.1451742180282--
------=_Part_7562_1035362962.1451742180281--

.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Mon, 04 Jan 2016 09:56:58 -0500
Raw View
On 2016-01-02 00:59, Germ=C3=A1n Diago wrote:
> 4- could a safe printf with variable name interpolation (such as python 3=
=20
> format("{variable}" be implemented on top of this?

Probably off-topic, but you don't need macros for that:

  safe_print(string_view format_str,
             std::map<std::string, std::any> values);

Yes, it looks a little like overkill, but that's *exactly* how Python
does it.

p.s. It's not new in Python 3 either:
https://docs.python.org/2/library/string.html#formatspec

If you're thinking of something more streamlined and C++-ish, you should
probably clarify what it would look like.

--=20
Matthew

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.

.


Author: FrankHB1989 <frankhb1989@gmail.com>
Date: Mon, 4 Jan 2016 08:18:23 -0800 (PST)
Raw View
------=_Part_12660_823833449.1451924303587
Content-Type: multipart/alternative;
 boundary="----=_Part_12661_790503538.1451924303587"

------=_Part_12661_790503538.1451924303587
Content-Type: text/plain; charset=UTF-8

There were several proposals about scoped macros, like N1614
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1614.pdf> and
N1710 <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1740.pdf>.
But I don't know the current status.

To be honest, I think it can hardly be fixed by adding standalone features.
And even it is "fixed" in several aspects, it would be still too weak
comparing to macro systems in Lisp dialects, even the latter may have some
nastier problems <http://www.phyast.pitt.edu/~micheles/scheme/scheme20.html>
which does not "available" in C++.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_12661_790503538.1451924303587
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There were several proposals about scoped macros, like <a =
href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1614.pdf">=
N1614</a> and <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers=
/2004/n1740.pdf">N1710</a>. But I don&#39;t know the current status.<br><br=
>To be honest, I think it can hardly be fixed by adding standalone features=
.. And even it is &quot;fixed&quot; in several aspects, it would be still to=
o weak comparing to macro systems in Lisp dialects, even the latter may hav=
e <a href=3D"http://www.phyast.pitt.edu/~micheles/scheme/scheme20.html">som=
e nastier problems</a> which does not &quot;available&quot; in C++.<br><br>=
</div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_12661_790503538.1451924303587--
------=_Part_12660_823833449.1451924303587--

.