On 12/28/2018 11:39 AM, Bart wrote:
> On 28/12/2018 14:06, Rick C. Hodgin wrote:
>>
>> int i {
>> start { i++ };
>> len { i - start };
>> };
>>
>> for (i = 0; i < maxlen; )
>> {
>> if (something[i] == whatever)
>> {
>> for (i.start(); something[i] == whatever; )
>> ++i;
>> printf("%d bytes\n", i.len());
>>
>> } else {
>> ++i;
>> }
>> }
>
> So here:
>
> int i { fred{++i}}; // declare special function fred
> i = 10;
> i.fred(); // call fred(), evaluate and store
> // ++i, ie. 11
> i = 20;
> i.fred; // retrieve the value 11
The use of "i.fred;" would be the same as "i;" on a line by itself.
It has no impacting operation.
> i.fred(); // evaluate ++i (21) and store.
>
> ?
Your example would be unfurled as you indicate:
> If so, what is the advantage to just doing this:
>
> int i, i_fred;
> i=10;
> i_fred=++i;
> i=20;
> i_fred;
> i_fred=++i;
Encapsulation, in that "fred" relates to i, and is contextual to i.
It has a direct relationship there, and is encapsulated thusly. It's
also a simple syntax easily conveyed right there at use. It doesn't
require use of #defines to do things. It's not a class defined else-
where. It's for short, local encapsulation of things that are rele-
vant or needed only there in the immediate vicinity.
> This seems to be mixing up several concepts: lambdas, function pointers (if
> i.start() calls a function, i.start is usually a pointer), local functions
> and, I think, closures. For example what happens here:
>
> int a=6;
> int i {fred {i+a}};
> { a=8;
> double a=9876;
> i=10;
> i.fred();
> ....
>
> Does i.fred store 16,18, or 9886.0?
Whatever's most local in scope to each instance use, so it would
store:
fred = (int)((double)i + a/*9876.0*/);
--
Rick C. Hodgin