Deutsch   English   Français   Italiano  
<672BF0F9.1010702@grunge.pl>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: fir <fir@grunge.pl>
Newsgroups: comp.lang.c
Subject: Re: on named blocks concept
Date: Wed, 06 Nov 2024 23:43:05 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <672BF0F9.1010702@grunge.pl>
References: <4b9a47d628677882c26b2518a78571043ef1bdb9@i2pn2.org> <vggdhl$27v1j$1@dont-email.me> <vggecf$27v1j$2@dont-email.me> <672BC788.6030100@grunge.pl> <vggjag$28gt1$1@dont-email.me> <672BD56E.2010901@grunge.pl> <vggo9t$29kl7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: i2pn2.org;
	logging-data="1280580"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
To: Bart <bc@freeuk.com>
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <vggo9t$29kl7$1@dont-email.me>
Bytes: 8955
Lines: 249

Bart wrote:
> On 06/11/2024 20:45, fir wrote:
>> Thiago Adams wrote:
>>> On 06/11/2024 16:46, fir wrote:
>>>> Thiago Adams wrote:
>>>>> On 06/11/2024 15:46, Thiago Adams wrote:
>>>>>> On 06/11/2024 13:04, fir wrote:
>>>>>>> if c would have something that i name as named block
>>>>>>> much more interesting options in coding in c would be
>>>>>>> imo avaliable..
>>>>>>> by named block i understood something like
>>>>>>>
>>>>>>> foo {
>>>>>>>    //code here
>>>>>>> }
>>>>>>>
>>>>>>> whiuch resembles function , as can be placed in 'global'
>>>>>>> (module level) space but also could be placed locally in
>>>>>>> functions
>>>>>>>
>>>>>>> int foo() {
>>>>>>>    a { }
>>>>>>>    b { }
>>>>>>> }
>>>>>>>
>>>>>>> then it could be called internally
>>>>>>>
>>>>>>> int foo() {
>>>>>>>    a { }
>>>>>>>    b { }
>>>>>>>
>>>>>>>    int x = a()*a()*b(); //though imo () probab;ly should be
>>>>>>> optionall
>>>>>>> }
>>>>>>>
>>>>>>> or externally
>>>>>>>
>>>>>>> foo.a()
>>>>>>>
>>>>>>> those blocks probably should have acces to local variables of
>>>>>>> parent functions or parant block so it yelds imo to conclusion
>>>>>>> that local variables and arguments should be by default static
>>>>>>> (those stack variables by default are bad idea imo.. its kinda
>>>>>>> optimisation
>>>>>>> needed whan you got 4kb RAM but on bigger machines this optimisation
>>>>>>> is bad imo)
>>>>>>>
>>>>>>> if so mant things can be done with this blocks probably, im not
>>>>>>> exactly
>>>>>>> sure what exactly
>>>>>>>
>>>>>>> ona assembly label blocks by defauld probably be done by
>>>>>>>
>>>>>>> name:
>>>>>>>    //...
>>>>>>>    ret
>>>>>>>
>>>>>>>   so then can be reused though some version to call it in place
>>>>>>>   of definitions could be also avaliable imo (something like
>>>>>>>   a{}() in a sense but better looking (this looks to bad)
>>>>>>>
>>>>>>>   overally those named block should be also united with function
>>>>>>>   so they become the same if use on them the functionality of
>>>>>>>   passing arguments and returning variables
>>>>>>>
>>>>>>>   foo {
>>>>>>>     a {}
>>>>>>>
>>>>>>>     int x, y = a(1,2)
>>>>>>>   }
>>>>>>>
>>>>>>>   though i maybe not sure how to add this mechanism
>>>>>>>   possibly som,ething liek this (until something better could be
>>>>>>> found)
>>>>>>>
>>>>>>>   a
>>>>>>>   {
>>>>>>>    in int c;
>>>>>>>    in int d;
>>>>>>>    out int x = c+d;
>>>>>>>    out int y = c-d;
>>>>>>>   }
>>>>>>>
>>>>>>>   or
>>>>>>>   a( int c, int d)
>>>>>>>   {
>>>>>>>    out int x = c+d;
>>>>>>>    out int y = c-d;
>>>>>>>   }
>>>>>>>
>>>>>>> as all c d x y are static you may call a() without any or
>>>>>>> with any set int x, y = a(1) int x = a(1,2) and compiler
>>>>>>> would generate the assigments (how to call it on assembly level us
>>>>>>> wuite clear, not fully clear is what syntax in language to use
>>>>>>>
>>>>>>> this concept is yet not fully build yet but what i descrbed her i
>>>>>>> guess is okay
>>>>>>
>>>>>>
>>>>>> Names loops (only loops) were proposed to C2Y.
>>>>>>
>>>>>> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm
>>>>>>
>>>>>>
>>>>>
>>>>> Sorry I thought your motivation was exit blocks.
>>>>> I am not sure what is your motivation now, maybe lambdas? local
>>>>> functions? long jump?
>>>>> local jumps?
>>>>>
>>>>
>>>> as to lambdas /closures im not sure as i never learned that concepts
>>>> (seem wierd and uglt) but maybe
>>>> as if you have blocks you could eventually pass blocks to functions
>>>>
>>>> a {printf("\n %d", i)}
>>>>
>>>> void foo(int n, block p)
>>>> {
>>>>    for(int i=0; i<n; i++) p();
>>>> }
>>>>
>>>> foo(10,a);
>>>>
>>>>
>>>> its different than pointers as possibly block could have acces to
>>>> parent variables..but that would need to be rethinked as it generate
>>>> problems (like you eventually cant compile block a above as i is just
>>>> a name so this is more liek piece of text not a real code here
>>>>
>>>> eventualy some coud do
>>>>
>>>> a(int i) {printf("\n %d", i)}
>>>>
>>>> void foo(int n, block p)
>>>> {
>>>>    for(int i=0; i<n; i++) p(i);
>>>> }
>>>>
>>>> foo(10,a);
>>>
>>>
>>> This is one of the lambda motivations.
>>>
>>
>>
>> maybe , but thsi is just a kinda detail here, as it is not so much
>> difference than passing pointer though it is a difference
>>
>> (liek when you pass pointer code takes pointer and here if you pass blck
>> it acan be simpli compiled in in compile time (and thus it is possible
>> it can have acces to its all parent fuunction variables).. or may be
>> called in this "lambda " way as far as i remember that
>>
>> repeat(10, {printf("zzz")} ); //when reepat is a functin that takes block
>>
>> but as i said probbaly those blocks could be used for some more things
>
> Some of this stuff, like local functions, is in gnu C.
>
> Most other complex stuff, passing lamda functions, you will find in C++.
>
> But unless it is already in gnu, or has been added to C23 (which may
> take a decade to become common), C is not going to acquire any random
> proposals that you make in threads like this.
>
> At best you might modify one implementation to try out an idea.
>
> I'm not really into either, but I have tried anonymous functions
> (without closures) in my scripting language. Your example looks like
> this (using near-identical syntax):
>
>    proc myrepeat(n, body) =
>        to n do
>            body()
>        end
>    end
>
>    proc main =
========== REMAINDER OF ARTICLE TRUNCATED ==========