emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] babel: ob-C with Visual C++ and compilation-mode


From: Thierry Banel
Subject: Re: [O] babel: ob-C with Visual C++ and compilation-mode
Date: Thu, 14 Aug 2014 22:40:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

Le 13/08/2014 22:58, Ernesto Durante a écrit :
> Thank you Thierry for your answer and all the details. I really want to be a 
> contributor
> and help ob-C to improve (as well as can do a modest lisper).

Any help is welcome !

> I tried to find a way to master Cx11 and babel is helping me a lot.
> I think babel can really accelerate learning and dissimation of C++.
>
> In this perspective, I have another very simple idea that I want to share
> with you. I find C++ too noisy. 

Yes, indeed.

> In the following piece of code
> I really find the presence of the main call and the return statement really 
> annoying and useless.
>
> #+begin_src C++ :includes '(<iostream> <cassert>) :results silent
> template <typename T1, typename T2>
> auto compose(T1 t1, T2 t2) -> decltype(t1 + t2) { return t1+t2; }
>
> int main() {
>  auto d=compose(std::string("ola"),std::string("ciao")); //d's type is 
> std::string
>  auto i=compose(4,2);
>  assert(d== std::string("olaciao") && i==6);
> return 0
> }
> #+end_src
>
> We can remove it by letting ob-C do the work by modifying the function
> org-babel-C-ensure-main-wrap. Now the code looks (according to me) easier to 
> read
>
> #+begin_src C++ :includes '(<iostream> <cassert>) :results silent
> template <typename T1, typename T2>
> auto compose(T1 t1, T2 t2) -> decltype(t1 + t2) { return t1+t2; }
>
> template <>
> int compose(int t1,int t2) { return t1+t2; }
>
> ////main////
> auto d=compose(std::string("ola"),std::string("ciao")); //d's type is 
> std::string
> auto i=compose(4,2);
> assert(d== std::string("olaciao") && i==6);
> #+end_src
>
> What do you think ?
>
>
Well... In this example, we go down from 9 lines to 7 lines. Ok fair.
But the price is a new syntax to learn:
 ////main////
Is it wise to add an org-mode specific syntax to C++ (which already has
a lot) ?

Being noisy is a weakness of C++.
I think it is not the responsibility of org-mode to fix that.

Now, org-mode is already able to process main()-less blocks in simple cases.

#+BEGIN_SRC C++
printf("hello\n");
#+END_SRC

If we can find a way to extend this feature to more cases,
without needing a long documentation,
then, sure, it would be a nice improvement.

Regards
Thierry




reply via email to

[Prev in Thread] Current Thread [Next in Thread]