Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #74717

Re: CAlive to introduce flowofs

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: CAlive to introduce flowofs
Date 2015-11-03 12:05 +1300
Message-ID <d9q8h6F7v31U9@mid.individual.net> (permalink)
References (3 earlier) <n18jjk$heh$1@dont-email.me> <d9q30lF7v31U5@mid.individual.net> <n18ljs$qqt$1@dont-email.me> <d9q5tpF7v31U7@mid.individual.net> <e230eed4-6047-472c-8fc9-76869c68b352@googlegroups.com>

Show all headers | View raw


Rick C. Hodgin wrote:
> On Monday, November 2, 2015 at 5:20:57 PM UTC-5, Ian Collins wrote:
>> Bartc wrote:
>>> On 02/11/2015 21:31, Ian Collins wrote:
>>>> Bartc wrote:
>>>>> On 02/11/2015 21:13, Ian Collins wrote:
>>>>>> Bartc wrote:
>>>
>>>>>>> This is one of your ideas that I like, and have implemented my own
>>>>>>> version.
>>>>>>
>>>>>> It is also one which (as discussed last year) already available in
>>>>>> C++ :)
>>>>>
>>>>> I don't remember the C++ version. What's the feature called there?
>>>>
>>>> A function object (functor).
>>>
>>> OK. My initial reading suggests that the concept is rather more
>>> elaborate and general purpose than what is being discussed here, which
>>> is a way of getting from X in a function to Y in the same function, then
>>> returning to just after X. I believe that what I've implemented is very
>>> easy to understand.
>>>
>>> (I've looked at the link to last year's thread, I couldn't see any
>>> examples of functors there. What would my version of Rick's example look
>>> like using functors? (The fact that I have to ask doesn't bode well!). A
>>> link to one of last year's posts will do.)
>>
>> One form would be:
>>
>> struct my_function
>> {
>>     int result;
>>     int count;
>>     int value;
>>
>>     void five_count()
>>     {
>>       result = 5*value;
>>     }
>>
>>     void ten_count()
>>     {
>>       result = 10*value;
>>     }
>>
>>     void greater_than_ten_count()
>>     {
>>       result = 42*value;
>>     }
>>
>>     int operator()( int c, int v )
>>     {
>>       count = c;
>>       value = v;
>>
>>       if (count < 5)         five_count();
>>       else if (count < 10)   ten_count();
>>       else                   greater_than_ten_count();
>>
>>       return result;
>>     }
>> };
>
> You're calling functions.  You cannot do what flowofs do with
> functors.  They can take the blocks shown in my posts, which
> contain un-mated { and } portions of flow control logic, and
> handle them.

They were on a different sub-thread I hadn't read.  I was referring to 
the original post.

The structure above is essentially the same as your original example.  I 
find the unmated { and } portions of flow control logic horrid and hard 
to read.  Programmers are used to reading syntactically correct blocks 
of code.

> In addition, because it's C/C++, everything has to be defined
> BEFORE it is used, which means now I'm on a hunt-for-the-actual-
> source-code mission to try to find where the logic that actually
> uses the five_count() function is.

Rather than having to search for five_count from where it is called? 
Anyway, my C++ aware GUI editor can find it for me :)

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:20 -0800
  Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:27 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:34 -0800
  Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 11:57 -0800
  Re: CAlive to introduce flowofs supercat@casperkitty.com - 2015-11-02 12:18 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:24 -0800
      Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:48 -0800
    Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 12:40 -0800
  Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:08 +0000
    Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 10:13 +1300
      Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:14 +0000
        Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 10:31 +1300
          Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-02 21:48 +0000
            Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 11:20 +1300
              Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 14:33 -0800
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 15:03 -0800
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 12:05 +1300
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 15:08 -0800
                Re: CAlive to introduce flowofs supercat@casperkitty.com - 2015-11-02 16:44 -0800
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 17:20 -0800
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-03 17:06 +1300
                Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 20:13 -0800
              Re: CAlive to introduce flowofs Bartc <bc@freeuk.com> - 2015-11-03 12:43 +0000
                Re: CAlive to introduce flowofs David Brown <david.brown@hesbynett.no> - 2015-11-03 14:20 +0100
                Re: CAlive to introduce flowofs Ian Collins <ian-news@hotmail.com> - 2015-11-04 08:57 +1300
      Re: CAlive to introduce flowofs "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-02 14:31 -0800

csiph-web