Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I am not an Economist. I am an honest man! -- Paul McCracken


devel / comp.lang.c / Re: Am I writing C wrong?

SubjectAuthor
* Am I writing C wrong?luser droog
+* Re: Am I writing C wrong?David Brown
|`* Re: Am I writing C wrong?Philipp Klaus Krause
| `* Re: Am I writing C wrong?Ben Bacarisse
|  `* Re: Am I writing C wrong?luser droog
|   `- Re: Am I writing C wrong?Ben Bacarisse
+* Re: Am I writing C wrong?Tim Rentsch
|`* Re: Am I writing C wrong?luser droog
| `- Re: Am I writing C wrong?luser droog
`* Re: Am I writing C wrong?Dave Dunfield
 +- Re: Am I writing C wrong?luser droog
 `* Re: Am I writing C wrong?Bart
  `- Re: Am I writing C wrong?Dave Dunfield

1
Am I writing C wrong?

<f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19203&group=comp.lang.c#19203

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1883:: with SMTP id v3mr2764110qtc.327.1637722080843;
Tue, 23 Nov 2021 18:48:00 -0800 (PST)
X-Received: by 2002:ae9:dc84:: with SMTP id q126mr2450610qkf.128.1637722080667;
Tue, 23 Nov 2021 18:48:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Tue, 23 Nov 2021 18:48:00 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
Subject: Am I writing C wrong?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Wed, 24 Nov 2021 02:48:00 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 19
 by: luser droog - Wed, 24 Nov 2021 02:48 UTC

I'm really hooked on the parser combinator stuff. And I've made several
attempts to implement them in C. But I'm falling into the known trap of
"Greenspun's 10th". It's so tempting to try to turn C into something else.
Twiddle the syntax with macros. Closures and garbage collection and
tag unions. Typedef-ing the pointer.

How do you dig back out of the hole? Like, have shovel, in a hole, what to do?

I found one possibility by going back to the earliest literature from all
the bibs. ie. Budge, "Recursive Programming Techniques", 1975.
And he seems to be saying you don't have to do all that, if I'm reading it
right. You can do all the combinators and build your parser with
function calls so it looks all nice like a grammar. But these combinator
functions don't actually need to return "the parsers" themselves.
They can just build a data structure and then you just write some
more normal looking C functions to tree traverse up and down it,
right?

Does the same strategy extend to other FP stuff that seems cool?
Can I do all the cool stuff in C without implementing half of Lisp?

Re: Am I writing C wrong?

<snksv9$16c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19204&group=comp.lang.c#19204

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Wed, 24 Nov 2021 09:26:16 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <snksv9$16c$1@dont-email.me>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Nov 2021 08:26:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="019743894e53e7f67253b341b7e112b1";
logging-data="1228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+63vZ0YkHD/Z8X67aaBMV0Zl4Th44dl8g="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:B1QYBBGXP/k3HP9yHkbCJYm2c/k=
In-Reply-To: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Wed, 24 Nov 2021 08:26 UTC

On 24/11/2021 03:48, luser droog wrote:
> I'm really hooked on the parser combinator stuff. And I've made several
> attempts to implement them in C. But I'm falling into the known trap of
> "Greenspun's 10th". It's so tempting to try to turn C into something else.
> Twiddle the syntax with macros. Closures and garbage collection and
> tag unions. Typedef-ing the pointer.
>
> How do you dig back out of the hole? Like, have shovel, in a hole, what to do?
>

If you find the code you are trying to write is so far from "normal" or
"idiomatic" C that you are in effect trying to use C as a different
language, then the answer is to use a different language that lets you
write the code the way you want to write it. C is a great language for
some tasks, and so painful as to be practically useless for other tasks.
No one sane uses C for code that involves a great deal of string
manipulation, parsing, and the like unless the code is going to see
massive use and the last drops of performance are important enough to
justify the development time, the unmaintainable results, and the risk
of errors. When you are trying to write code that requires a great deal
of housekeeping, switch to a language that will do the housekeeping for
you so that you can concentrate on the bits that /can't/ be automated.

The choice of language depends on the features you /want/ in the
language (not necessarily what you /need/ - after all, you /can/ write
pretty much anything in C if you spend the effort). It also depends on
available libraries to make life easier, it depends on the languages you
know or can reasonably learn, amongst other things.

And if this is all for fun and interest, then the main concern should be
finding which parts of the whole concept are of most interest to you,
and picking a language that lets you concentrate on that part, and
handles everything lower level automatically. (Unless, of course, the
fun bit for you is implementing hard stuff in C, in which case there is
no wrong C!)

Re: Am I writing C wrong?

<sno3q2$tcr$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19240&group=comp.lang.c#19240

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!reader5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Thu, 25 Nov 2021 14:41:22 +0100
Message-ID: <sno3q2$tcr$1@solani.org>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<snksv9$16c$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 25 Nov 2021 13:41:22 -0000 (UTC)
Injection-Info: solani.org;
logging-data="30107"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:N4I/DLcvOj5Ye4UE1NKTaxT5LCI=
Content-Language: en-US
In-Reply-To: <snksv9$16c$1@dont-email.me>
X-User-ID: eJwFwYkBwCAIBLCV8B6k41Qp+4/QxMyVdyud8njYkwhGtPFsg28h6pR9cT6pMaHbbGFR0T8AAxAn
 by: Philipp Klaus Krause - Thu, 25 Nov 2021 13:41 UTC

Am 24.11.21 um 09:26 schrieb David Brown:

> And if this is all for fun and interest, then the main concern should be
> finding which parts of the whole concept are of most interest to you,
> and picking a language that lets you concentrate on that part, and
> handles everything lower level automatically.
Note that there are also tools, like lex and yacc, that will handle the
parts that are hard to do in C for you, and can be used together with
your C code for the other tasks.

Re: Am I writing C wrong?

<87r1b4cns2.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19241&group=comp.lang.c#19241

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Thu, 25 Nov 2021 14:28:45 +0000
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <87r1b4cns2.fsf@bsb.me.uk>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<snksv9$16c$1@dont-email.me> <sno3q2$tcr$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="2879b5bef7827f13c7d04130ff95025a";
logging-data="25822"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/A1+HRiPmxLI5fFLdamibTjT3rZtPXc0="
Cancel-Lock: sha1:kYZBmR8Wm2Qi/hHzj/g9X9tlOuo=
sha1:9kCSnVWU4JmTvDi8Y4yiz55cGmM=
X-BSB-Auth: 1.2f69de02834df7099b3f.20211125142845GMT.87r1b4cns2.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 25 Nov 2021 14:28 UTC

Philipp Klaus Krause <pkk@spth.de> writes:

> Am 24.11.21 um 09:26 schrieb David Brown:
>
>> And if this is all for fun and interest, then the main concern should be
>> finding which parts of the whole concept are of most interest to you,
>> and picking a language that lets you concentrate on that part, and
>> handles everything lower level automatically.
>
> Note that there are also tools, like lex and yacc, that will handle the
> parts that are hard to do in C for you, and can be used together with
> your C code for the other tasks.

True, but I don't think the objective is to parse anything in articular
but to develop a parsing toolkit based, as closely as C will reasonably
permit, on the combiner model that is popular in functional languages.

--
Ben.

Re: Am I writing C wrong?

<90334f9d-5c53-4a7f-8362-5bdc7155e357n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19251&group=comp.lang.c#19251

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5aeb:: with SMTP id c11mr10580656qvh.69.1637896695705;
Thu, 25 Nov 2021 19:18:15 -0800 (PST)
X-Received: by 2002:ac8:7d46:: with SMTP id h6mr22296870qtb.379.1637896695538;
Thu, 25 Nov 2021 19:18:15 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 25 Nov 2021 19:18:15 -0800 (PST)
In-Reply-To: <87r1b4cns2.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<snksv9$16c$1@dont-email.me> <sno3q2$tcr$1@solani.org> <87r1b4cns2.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <90334f9d-5c53-4a7f-8362-5bdc7155e357n@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Fri, 26 Nov 2021 03:18:15 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 36
 by: luser droog - Fri, 26 Nov 2021 03:18 UTC

On Thursday, November 25, 2021 at 8:28:56 AM UTC-6, Ben Bacarisse wrote:
> Philipp Klaus Krause <p...@spth.de> writes:
>
> > Am 24.11.21 um 09:26 schrieb David Brown:
> >
> >> And if this is all for fun and interest, then the main concern should be
> >> finding which parts of the whole concept are of most interest to you,
> >> and picking a language that lets you concentrate on that part, and
> >> handles everything lower level automatically.
> >
> > Note that there are also tools, like lex and yacc, that will handle the
> > parts that are hard to do in C for you, and can be used together with
> > your C code for the other tasks.
> True, but I don't think the objective is to parse anything in articular
> but to develop a parsing toolkit based, as closely as C will reasonably
> permit, on the combiner model that is popular in functional languages.
>

Yes, no precise goals beyond that except vague dreams of using this
toolkit to write an LCC for the next millennium. A C compiler so amazingly
concise and readable to invite and facilitate further extensions and
experimentation. But, if I lean too far in the traditional C direction, then
there's already https://github.com/orangeduck/mpc

So, I was leaning into the functional side to try to be different.

As a more specific symptom, though. I wrote that C comment remover
with a hefty pinch of lisp-alike gymnastics.

https://codereview.stackexchange.com/questions/254005/removing-c-comments-from-source

And maybe I ought to at least try to re-write it to be more like a normal
C programmer would do it. With a string buffer type or something.
Something other than cons chains.

I really like having the main() code read nicely like a high level pseudocode.
But maybe I can achieve that without the tag unions.

Re: Am I writing C wrong?

<877dcvcgha.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19252&group=comp.lang.c#19252

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Fri, 26 Nov 2021 11:18:41 +0000
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <877dcvcgha.fsf@bsb.me.uk>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<snksv9$16c$1@dont-email.me> <sno3q2$tcr$1@solani.org>
<87r1b4cns2.fsf@bsb.me.uk>
<90334f9d-5c53-4a7f-8362-5bdc7155e357n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="6b80015fbd1b2612aae7dbeecf0082f9";
logging-data="15786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184EriGq1zZvMCtW78SJo8LrSndUW9j4Dk="
Cancel-Lock: sha1:tiQS55RCBWKICAvbIajSmKw5Wls=
sha1:WoGLpkSgVN2tdkiL5kgc8pmLh/I=
X-BSB-Auth: 1.d85201db0c4482356398.20211126111841GMT.877dcvcgha.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 26 Nov 2021 11:18 UTC

luser droog <luser.droog@gmail.com> writes:

> On Thursday, November 25, 2021 at 8:28:56 AM UTC-6, Ben Bacarisse wrote:
>> Philipp Klaus Krause <p...@spth.de> writes:
>>
>> > Am 24.11.21 um 09:26 schrieb David Brown:
>> >
>> >> And if this is all for fun and interest, then the main concern should be
>> >> finding which parts of the whole concept are of most interest to you,
>> >> and picking a language that lets you concentrate on that part, and
>> >> handles everything lower level automatically.
>> >
>> > Note that there are also tools, like lex and yacc, that will handle the
>> > parts that are hard to do in C for you, and can be used together with
>> > your C code for the other tasks.
>> True, but I don't think the objective is to parse anything in
>> > articular
particular!
>> but to develop a parsing toolkit based, as closely as C will reasonably
>> permit, on the combiner model that is popular in functional
combinator!
>> > languages.

> Yes, no precise goals beyond that except vague dreams of using this
> toolkit to write an LCC for the next millennium. A C compiler so amazingly
> concise and readable to invite and facilitate further extensions and
> experimentation.

C's grammar is not particularly regular. That part will always be a bit
messy.

> But, if I lean too far in the traditional C direction, then
> there's already https://github.com/orangeduck/mpc
>
> So, I was leaning into the functional side to try to be different.

But, since C is resolutely procedural, that's a rather artificial
challenge. A clear, easily modifiable C parser, written in C, does not
have to use mocked-up combinators.

> As a more specific symptom, though. I wrote that C comment remover
> with a hefty pinch of lisp-alike gymnastics.

One person's elegant gymnastics is another person's painful contortions!

> https://codereview.stackexchange.com/questions/254005/removing-c-comments-from-source
>
> And maybe I ought to at least try to re-write it to be more like a
> normal C programmer would do it. With a string buffer type or
> something. Something other than cons chains.
>
> I really like having the main() code read nicely like a high level
> pseudocode. But maybe I can achieve that without the tag unions.

The C I write is influenced by my experience with functional languages
but it's mostly superficial because C does not have the fundamental
types needed.

--
Ben.

Re: Am I writing C wrong?

<8635n09645.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19328&group=comp.lang.c#19328

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Fri, 10 Dec 2021 01:11:38 -0800
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <8635n09645.fsf@linuxsc.com>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="94ee63d76223a75d29f96ac519efdd3f";
logging-data="29186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18o5j3VAIeHzrJAOmkwcS4qDibkXqFkMsc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3QQfa2ji1UfjsQ1TWXrV/65U740=
sha1:pzDSgdg5G6Hqpy6l7PLobJGLKWY=
 by: Tim Rentsch - Fri, 10 Dec 2021 09:11 UTC

luser droog <luser.droog@gmail.com> writes:

[...]

> I found one possibility by going back to the earliest literature
> from all the bibs. ie. Budge, "Recursive Programming Techniques",
> 1975. [...]

Is that Burge?

Re: Am I writing C wrong?

<433e1c33-69c9-4fb5-8dbb-022ea485dec0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19346&group=comp.lang.c#19346

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:7d47:: with SMTP id h7mr31000893qtb.486.1639177347491;
Fri, 10 Dec 2021 15:02:27 -0800 (PST)
X-Received: by 2002:a05:620a:1905:: with SMTP id bj5mr23878059qkb.94.1639177347128;
Fri, 10 Dec 2021 15:02:27 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 10 Dec 2021 15:02:26 -0800 (PST)
In-Reply-To: <8635n09645.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2607:fb90:3873:46f2:e5da:d2a0:8a8:697a;
posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 2607:fb90:3873:46f2:e5da:d2a0:8a8:697a
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com> <8635n09645.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <433e1c33-69c9-4fb5-8dbb-022ea485dec0n@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Fri, 10 Dec 2021 23:02:27 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 10
 by: luser droog - Fri, 10 Dec 2021 23:02 UTC

On Friday, December 10, 2021 at 3:11:52 AM UTC-6, Tim Rentsch wrote:
> luser droog <luser...@gmail.com> writes:
>
> [...]
> > I found one possibility by going back to the earliest literature
> > from all the bibs. ie. Budge, "Recursive Programming Techniques",
> > 1975. [...]
>
> Is that Burge?

Yes, W. H. Burge.

Re: Am I writing C wrong?

<f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19347&group=comp.lang.c#19347

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:410:: with SMTP id n16mr31064560qtx.369.1639195878499;
Fri, 10 Dec 2021 20:11:18 -0800 (PST)
X-Received: by 2002:ac8:7d46:: with SMTP id h6mr32613835qtb.379.1639195878302;
Fri, 10 Dec 2021 20:11:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 10 Dec 2021 20:11:18 -0800 (PST)
In-Reply-To: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=142.112.241.86; posting-account=TrQTOgoAAAC2NG571LtljP2OpjnuTN79
NNTP-Posting-Host: 142.112.241.86
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: dave.dun...@gmail.com (Dave Dunfield)
Injection-Date: Sat, 11 Dec 2021 04:11:18 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 16
 by: Dave Dunfield - Sat, 11 Dec 2021 04:11 UTC

On Tuesday, November 23, 2021 at 9:48:06 PM UTC-5, luser droog wrote:
> .. It's so tempting to try to turn C into something else.
> Twiddle the syntax with macros. ...

One of the "most memorable" (to me "worst" :-) cases where I've seen this done
was a linker called "VAL"... basically mostly done in a "language" not much like C.

You can see it through my "Daves Old Computers" site, go to "Download DOS Widgets"
near the bottom:
http://dunfield.classiccmp.org/dos/index.htm

Then grab VAL_SRC[.ZIP]

and have an "interesting" read!

--
Dave Dunfield ::: "Daves Old Computers" -> Personal

Re: Am I writing C wrong?

<73e7e18b-3e6e-46c0-8865-ccf93cdc3349n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19348&group=comp.lang.c#19348

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:453:: with SMTP id o19mr32957923qtx.648.1639198025644;
Fri, 10 Dec 2021 20:47:05 -0800 (PST)
X-Received: by 2002:ac8:5950:: with SMTP id 16mr31889778qtz.462.1639198025438;
Fri, 10 Dec 2021 20:47:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 10 Dec 2021 20:47:05 -0800 (PST)
In-Reply-To: <f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com> <f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <73e7e18b-3e6e-46c0-8865-ccf93cdc3349n@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 11 Dec 2021 04:47:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 41
 by: luser droog - Sat, 11 Dec 2021 04:47 UTC

On Friday, December 10, 2021 at 10:11:24 PM UTC-6, dave.d...@gmail.com wrote:
> On Tuesday, November 23, 2021 at 9:48:06 PM UTC-5, luser droog wrote:
> > .. It's so tempting to try to turn C into something else.
> > Twiddle the syntax with macros. ...
>
> One of the "most memorable" (to me "worst" :-) cases where I've seen this done
> was a linker called "VAL"... basically mostly done in a "language" not much like C.
>
> You can see it through my "Daves Old Computers" site, go to "Download DOS Widgets"
> near the bottom:
> http://dunfield.classiccmp.org/dos/index.htm
>
> Then grab VAL_SRC[.ZIP]
>
> and have an "interesting" read!
>

Wow. Nice example. Goes far beyond the oft cited Bourne shell source.
https://news.ycombinator.com/item?id=22191790
https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh

I think my examples aren't actually that extreme. I mostly use macros for
code generation or what I like to call "aggressive factoring". Stuff like
X-Macros and that ugly/beautiful PP_NARG() macro. I do have a soft spot
for implicit int, and hide as many pointers as possible behind macros
(always with some plausible--to me--rationalization, of course).

Relying on implicit int allows this <adjective> macro which lets you
create C functions that look like Lisp (provided you design the rest
of the program to use ints in some crazy manner that they hold all
the various types you need):

#define defun(NAME,ARGS,...) \
int NAME ARGS { IFDEBUG(2, fprintf(stderr, "%s ", __func__)); return __VA_ARGS__; }

(only tested with gcc where it requires --std=gnu99 or --std=c99 and not -pedantic*.)..
(I take that back. I actually use "-Wno-implicit-int -Wno-implicit-function-declaration -g"
and made up the previous parenthetical.)
(Looking at it now, I have second thoughts about the IFDEBUG() macro. That should
probably be a regular "if(){}".)

And those tag-unions. I friggin' love them. It's my hammer. All over this land.

Re: Am I writing C wrong?

<910a674d-b6cc-44ee-b055-8d1fc4b9768bn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19349&group=comp.lang.c#19349

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:15c6:: with SMTP id p6mr30669870qvz.12.1639198854104;
Fri, 10 Dec 2021 21:00:54 -0800 (PST)
X-Received: by 2002:ac8:6619:: with SMTP id c25mr32062889qtp.390.1639198853902;
Fri, 10 Dec 2021 21:00:53 -0800 (PST)
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 10 Dec 2021 21:00:53 -0800 (PST)
In-Reply-To: <433e1c33-69c9-4fb5-8dbb-022ea485dec0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=97.87.183.68; posting-account=G1KGwgkAAAAyw4z0LxHH0fja6wAbo7Cz
NNTP-Posting-Host: 97.87.183.68
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<8635n09645.fsf@linuxsc.com> <433e1c33-69c9-4fb5-8dbb-022ea485dec0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <910a674d-b6cc-44ee-b055-8d1fc4b9768bn@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: luser.dr...@gmail.com (luser droog)
Injection-Date: Sat, 11 Dec 2021 05:00:54 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 30
 by: luser droog - Sat, 11 Dec 2021 05:00 UTC

On Friday, December 10, 2021 at 5:02:33 PM UTC-6, luser droog wrote:
> On Friday, December 10, 2021 at 3:11:52 AM UTC-6, Tim Rentsch wrote:
> > luser droog <luser...@gmail.com> writes:
> >
> > [...]
> > > I found one possibility by going back to the earliest literature
> > > from all the bibs. ie. Budge, "Recursive Programming Techniques",
> > > 1975. [...]
> >
> > Is that Burge?
> Yes, W. H. Burge.

It is btw an surprisingly excellent book. It's like a proto-SICP where he
just uses a pure subset of Lisp to start with. I only skimmed the sorting
chapter but I read the other 4 pretty thoroughly.

It's like a compiler textbook in reverse or a language primer that's inside
out. He explains control structures by first showing you how to compile
them into SKI combinators or a stack machine or an SECD machine.

Then, he goes into data structures like lists and trees and streams
and even coroutines. And then a whole chapter on parsers. As I said
upthread the combinators are used to build a tree data structure
representing the language grammar and then various parsing
strategies like top-down, bottom-up left-corner, bottom-up right-corner,

Even the sorting chapter has some neat stuff like how to construct
sorting networks for a fixed number of inputs.

It's a forgotten classic IMO. Or at least I wish I'd found it sooner.
Going on the shelf next to the '62 APL book when I'm done with it.

Re: Am I writing C wrong?

<sp2316$qb5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19352&group=comp.lang.c#19352

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Am I writing C wrong?
Date: Sat, 11 Dec 2021 11:45:44 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <sp2316$qb5$1@dont-email.me>
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 11 Dec 2021 11:45:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ea9b54600d74872405bddab5e910fad5";
logging-data="26981"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19039lGrx8/h9F3h7zdqZ9anZHXgXmCAgs="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:tpc2yuEIsDyKfOJRgwXFzQ0ZA44=
In-Reply-To: <f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com>
 by: Bart - Sat, 11 Dec 2021 11:45 UTC

On 11/12/2021 04:11, Dave Dunfield wrote:
> On Tuesday, November 23, 2021 at 9:48:06 PM UTC-5, luser droog wrote:
>> .. It's so tempting to try to turn C into something else.
>> Twiddle the syntax with macros. ...
>
> One of the "most memorable" (to me "worst" :-) cases where I've seen this done
> was a linker called "VAL"... basically mostly done in a "language" not much like C.
>
> You can see it through my "Daves Old Computers" site, go to "Download DOS Widgets"
> near the bottom:
> http://dunfield.classiccmp.org/dos/index.htm
>
> Then grab VAL_SRC[.ZIP]
>
> and have an "interesting" read!

Some of that is reasonable but this is taking it a bit far:

#define LessThanOrEqualTo <=

Re: Am I writing C wrong?

<4c84631f-105a-4c05-ac22-20e649343401n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19365&group=comp.lang.c#19365

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:2b0:: with SMTP id m16mr34183390qvv.116.1639260009389;
Sat, 11 Dec 2021 14:00:09 -0800 (PST)
X-Received: by 2002:a05:620a:a16:: with SMTP id i22mr26562585qka.362.1639260009191;
Sat, 11 Dec 2021 14:00:09 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 11 Dec 2021 14:00:08 -0800 (PST)
In-Reply-To: <sp2316$qb5$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=142.112.241.86; posting-account=TrQTOgoAAAC2NG571LtljP2OpjnuTN79
NNTP-Posting-Host: 142.112.241.86
References: <f1ea6843-cddb-4824-b154-2580fd288407n@googlegroups.com>
<f6031123-8826-4f98-ab37-5e41a3f7b99an@googlegroups.com> <sp2316$qb5$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4c84631f-105a-4c05-ac22-20e649343401n@googlegroups.com>
Subject: Re: Am I writing C wrong?
From: dave.dun...@gmail.com (Dave Dunfield)
Injection-Date: Sat, 11 Dec 2021 22:00:09 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 49
 by: Dave Dunfield - Sat, 11 Dec 2021 22:00 UTC

Re: Macros generating code

I rarely use macros to generate code "just for looks". I'm a strong
believer in "you should be able to tell much what it does by just
looking at it", and "we all know C -As It Is- fairly well". Don't like
to have to "Second guess" what someone is doing - the name might sound
"obvious" but you still have to know the macro to see "for sure".

That being said, one of my long time favorites is for generating
simple "debug output":

#define Debug(a) //printf a;
#define Debug1(a) printf a;

The reason there are TWO macros it lets me easily turn debug on/off
in any location just by adding or removing a single character '1'.
I can add more similar Macros to control it more by numbered "type"
but I find just the two are usually good enough!

I can remove // from the Debug() definition to enable ALL debug
output.

Use is "close" to printf(), just two levels of brackets and no
ending ';' :

Debug1(("Var1=%u Str1='%s'\n", Var1, Str1))

This "generates":
-----
printf ("Var1=%d Str1='%s'\n", Var1, Str1);
-----

If I change it to "Debug((...))" it generates:
-----

-----

So I can sprinkle LOTS of debug output while "working things out",
easily turn it ALL off for production code, and back on if I have
to work on some aspect of it later!

And no excessive extra lines/stuff (#if's etc.) cluttering up the
code visually!

I'm sure most everyone here has come up with "something similar"
but I'm giving detail as it still might be of benefit to newbies!

Dave Dunfield ::: https://dunfield.themindfactory.com
or: "Daves Old Computers" -> Personal (near bottom)

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor