Re: another C-like language? was Compilers :)

Kaz Kylheku <864-117-4973@kylheku.com>
Wed, 11 Jan 2023 11:02:56 -0000 (UTC)

          From comp.compilers

Related articles
[11 earlier articles]
Re: another C-like language? was Compilers :) DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2023-01-09)
Re: another C-like language? was Compilers :) 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-09)
Re: another C-like language? was Compilers :) Keith.S.Thompson+u@gmail.com (Keith Thompson) (2023-01-09)
Re: another C-like language? was Compilers :) david.brown@hesbynett.no (David Brown) (2023-01-10)
Re: another C-like language? was Compilers :) gah4@u.washington.edu (gah4) (2023-01-10)
Re: another C-like language? was Compilers :) tkoenig@netcologne.de (Thomas Koenig) (2023-01-11)
Re: another C-like language? was Compilers :) 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-11)
Re: another C-like language? was Compilers :) findlaybill@blueyonder.co.uk (Bill Findlay) (2023-01-11)
Re: another C-like language? was Compilers :) david.brown@hesbynett.no (David Brown) (2023-01-11)
Re: Scheme is not another C-like language? was Compilers :) gneuner2@comcast.net (George Neuner) (2023-01-12)
Re: another C-like language? was Compilers :) laguest@archeia.com (Luke A. Guest) (2023-01-13)
Re: another C-like language? was Compilers :) gneuner2@comcast.net (George Neuner) (2023-01-13)
Re: another C-like language? was Compilers :) 864-117-4973@kylheku.com (Kaz Kylheku) (2023-01-14)
[3 later articles]
| List of all articles for this month |

From: Kaz Kylheku <864-117-4973@kylheku.com>
Newsgroups: comp.compilers
Date: Wed, 11 Jan 2023 11:02:56 -0000 (UTC)
Organization: A noiseless patient Spider
References: 23-01-001 23-01-002 23-01-003 23-01-008 23-01-016 23-01-029 23-01-033
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="94550"; mail-complaints-to="abuse@iecc.com"
Keywords: C, design
Posted-Date: 11 Jan 2023 18:09:11 EST

On 2023-01-10, David Brown <david.brown@hesbynett.no> wrote:
> On 09/01/2023 18:41, Kaz Kylheku wrote:
>> On 2023-01-06, David Brown <david.brown@hesbynett.no> wrote:
>> A block like this can be repeated with copy and paste:
>>
>> {
>> int yes = 1;
>> setsockopt(fd, SO_WHATEVER, &yes);
>> }
>>
>> This cannot: you will get redefinition errors:
>>
>> int yes = 1;
>> setsockopt(fd, SO_WHATEVER, &yes);
>>
>> you have to think about ensuring that "int yes" occurs in one place
>> that is before the first use, and the other places assign to it.
>> Or invent different names.
>
> This is something that I would prefer C and C++ to allow. I think it
> would improve the structure of some of my code, precisely as you describe.


It seems that Scheme, with its ugly (define ...) that can be used inside
block scopes, has the same restriction!


I tried (lambda () (define x 42) (define x 43)) in a Scheme
implementation and got an error about the duplicate variable.


That's completely silly since it breaks the idea that the block scoped
define can just be desugared to nested lets.


On a related topic, the CLISP implementation of Common Lisp, whose
history goes back to the 1980s, availed itself of mixing variable
declarations and statements even in C90. Its source files are named with
a .d suffix, and are preproced by a "varbrace" tool which spits out
the brace-enclosed blocks. I seem to recall that variables are prefixed
with a "var" specifier, which probably makes it easy for the tool to
recognize declarations.


It may likely be the case that under CLISP's "varbrace" you can repeat
variable names.


... and searching for varbrace, I see a 2017 thread in the CLISP
mailing list by someone who posted a patch to rid CLISP of varbrace,
and just use C99. The patch submmitter mentions that he had to rename
some instances of repeated variables, making this remark:


      Another issue is conflicting definitions of the same variable. Example:


        var type1 foo;
        // some code
        var type2 foo;


    This is solved by renaming one of them, if possible. In two places, I
    manually added braces (like varbrace would've done)


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.