Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The existence of god implies a violation of causality.


devel / comp.lang.misc / String-Based Macro Systems

SubjectAuthor
* String-Based Macro SystemsLawrence D'Oliveiro
`* Re: String-Based Macro SystemsBlue-Maned_Hawk
 +- Re: String-Based Macro SystemsLawrence D'Oliveiro
 `* Escapes (was String-Based Macro Systems)James Harris
  `* Re: Escapes (was String-Based Macro Systems)Stefan Ram
   `- Re: Escapes (was String-Based Macro Systems)Stefan Ram

1
String-Based Macro Systems

<uvcqn3$2pju0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2431&group=comp.lang.misc#2431

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.misc
Subject: String-Based Macro Systems
Date: Sat, 13 Apr 2024 02:29:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <uvcqn3$2pju0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 13 Apr 2024 04:29:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c07c9bb19a0975fd36cf4a2cbd5e0704";
logging-data="2936768"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2fvop800Pf1Djeqvf9uy3"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:sVkClwXkjr7eI1Y7CzC+FKk2tFg=
 by: Lawrence D'Oliv - Sat, 13 Apr 2024 02:29 UTC

I think most of us are familiar with the “#define” preprocessor in C and
C++. There are more powerful macro processors around, like GNU m4. They
all have the same basic concept: pass input text straight through to
output, until something triggers a macro substitution on the text.

The original m4 was created by the Unix folks at Bell Labs, modelled on an
earlier concept called “Macrogenerator” by Christopher Strachey (one of
the brains behind the programming language CPL, which led to BCPL, which
led to B and then C). Macrogenerator had special symbols to indicate macro
definition, and macro and argument expansion:

§DEF,«name»,<«definition»>;

where the “<” and “>” are actual quote symbols in the notation, while I
use “«” and ”»” as metasyntactic brackets. Within the «definition»,
occurrences of “~1”, “~2” etc are replaced with the first, second etc
actual argument specified in the call. You then use this macro as

§«name»,«args»;

where multiple arguments are comma-separated.

Simple example: given

§DEF,greetings,<Hello, ~1!>;

then

I would just like to say, “§greetings,world;” to anybody listening

should expand to

I would just like to say, “Hello, world!” to anybody listening

Here is a moderately interesting example, from the Bryan Higman book where
I first heard about this. It uses a builtin called §UPDATE, which does
assignment to an existing macro name, and also note the occurrence of
§DEFs within §DEFs, for local (temporary) macro definitions (since the
auxiliary macro §Q has to persist between invocations, it cannot be one of
these):

§DEF,Q,A;
§DEF,AORB,<§§Q;;>,§DEF,A,<A§UPDATE,Q,B;>;,§DEF,B,<B§UPDATE,Q,A;>;;

What this does is, each time you write “§AORB;”, it expands to alternately
“A” or “B”.

The big difference with m4 is that it does away with these special
symbols; the mere occurrence of a name matching a defined macro (or an
argument of the macro currently being expanded) is sufficient to trigger
substitution. Do you think this is a good idea?

There are all kinds of pitfalls with such macro systems. The original
Macrogenerator could not cope with substitutions containing unpaired
“< ... >” quote symbols, and even GNU m4 lacks something as simple as a
backslash-style “escape next single character, whatever it is”. While m4
lets you switch the quoting symbols, it still insists that they occur in
pairs.

Would adding such an escape character be useful?

Re: String-Based Macro Systems

<pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2432&group=comp.lang.misc#2432

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemanedhawk@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.misc
Subject: Re: String-Based Macro Systems
Date: Sat, 13 Apr 2024 05:09:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid>
References: <uvcqn3$2pju0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 13 Apr 2024 07:09:27 +0200 (CEST)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="79de885db3f5d959464e542968145ba6";
logging-data="2981041"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Q0cB1D00684Pr8gBBNMWctlDlfsof+n0="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:1xuvRJQuiNd/6+R/UBfvHXLz+/8=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronuku
pokaiwhenuakitanatahu
 by: Blue-Maned_Hawk - Sat, 13 Apr 2024 05:09 UTC

Lawrence D'Oliveiro wrote:

> The big difference with m4 is that it does away with these special
> symbols; the mere occurrence of a name matching a defined macro (or an
> argument of the macro currently being expanded) is sufficient to trigger
> substitution. Do you think this is a good idea?
>
> There are all kinds of pitfalls with such macro systems. The original
> Macrogenerator could not cope with substitutions containing unpaired “<
> ... >” quote symbols, and even GNU m4 lacks something as simple as a
> backslash-style “escape next single character, whatever it is”. While m4
> lets you switch the quoting symbols, it still insists that they occur in
> pairs.
>
> Would adding such an escape character be useful?

Yes, of course.

Whenever a system has a system to escape symbols, there are two ways to go
about it: either the symbol is magic by default, and the escape makes it
normal, or the symbol is normal by default, and the escape makes it magic.

Having both of the systems at once is generally confusing, because it
makes it difficult to remember which symbols are which. It's more
practical to have all of them be one or the other.

One could say that having the symbols only become magic upon escapement is
better, because it clearly indicates when a symbol has magic properties.
This is analogous to the logic used to defend sigils, a form of
disambiguation repeatedly found to be pointless because names already do
that disambiguation. Therefore, the correct choice is magic by default.

One fallacious argument i've heard used to justify magic by default is
that it means that the treatment of the escape symbol itself is consistent
with all the other symbols in that it's magic by default unless escaped by
itself. I consider this fallacious because in a system where magic must
be explicit, the escape symbol would be the _only_ exception, and it would
be _impossible_ to make any others—what i'd say is a worthwhile sacrifice.

Either way, figuring out the solution to the problem of “Magic: by
default or by request?” is almost certainly a lower priority than the
majority of other problems.

--
Blue-Maned_Hawk│shortens to Hawk│/blu.mɛin.dʰak/│he/him/his/himself/Mr.
blue-maned_hawk.srht.site
(?<sigil> [&*\$\@\%])

Re: String-Based Macro Systems

<uvd6gv$2rra8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2433&group=comp.lang.misc#2433

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.misc
Subject: Re: String-Based Macro Systems
Date: Sat, 13 Apr 2024 05:51:27 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uvd6gv$2rra8$1@dont-email.me>
References: <uvcqn3$2pju0$1@dont-email.me>
<pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 13 Apr 2024 07:51:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c07c9bb19a0975fd36cf4a2cbd5e0704";
logging-data="3009864"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/u43bK38q/ri7mHGowDtF/"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:haLJASqUUECgCiCPAb2b9fC2Nvk=
 by: Lawrence D'Oliv - Sat, 13 Apr 2024 05:51 UTC

On Sat, 13 Apr 2024 05:09:26 -0000 (UTC), Blue-Maned_Hawk wrote:

> Whenever a system has a system to escape symbols, there are two ways to
> go about it: either the symbol is magic by default, and the escape
> makes it normal, or the symbol is normal by default, and the escape
> makes it magic.

And here’s another question: is magic iterative? Is text produced by a
macro substitution automatically subject to further macro substitutions?

This is true of Macrogenerator and m4, but perhaps this is a source of a
lot of the problems with string-based macro systems.

On the other hand, if you didn’t do this, then how would you implement the
example I gave?

§DEF,AORB,<§§Q;;>,§DEF,A,<A§UPDATE,Q,B;>;,§DEF,B,<B§UPDATE,Q,A;>;;

If “§A;” expands literally to “A§UPDATE,Q,B;” with no further special
interpretation of the embedded “§”, then how would you explicitly request
invocation of the “UPDATE” function?

The answer would be, the body of the macro would not directly be
interpreted as literal text, but would have to consist of a sequence of
explicit directives, like “insert literal text”, “insert expansion of a
further macro” and so on.

Escapes (was String-Based Macro Systems)

<v12966$euk9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2537&group=comp.lang.misc#2537

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!newsfeed.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Escapes (was String-Based Macro Systems)
Date: Fri, 3 May 2024 10:01:57 +0100
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <v12966$euk9$1@dont-email.me>
References: <uvcqn3$2pju0$1@dont-email.me>
<pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 03 May 2024 11:01:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dd321ca2c5d88d785ae2cfb2ce34d280";
logging-data="490121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H2Cjrrov6v9a/oqvAL59Sy4+a/fiFEm4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zE7P+Db3IVBv75AbThx37itoA6A=
In-Reply-To: <pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid>
Content-Language: en-GB
 by: James Harris - Fri, 3 May 2024 09:01 UTC

On 13/04/2024 06:09, Blue-Maned_Hawk wrote:
> Lawrence D'Oliveiro wrote:
>
>> The big difference with m4 is that it does away with these special
>> symbols; the mere occurrence of a name matching a defined macro (or an
>> argument of the macro currently being expanded) is sufficient to trigger
>> substitution. Do you think this is a good idea?
>>
>> There are all kinds of pitfalls with such macro systems. The original
>> Macrogenerator could not cope with substitutions containing unpaired “<
>> ... >” quote symbols, and even GNU m4 lacks something as simple as a
>> backslash-style “escape next single character, whatever it is”. While m4
>> lets you switch the quoting symbols, it still insists that they occur in
>> pairs.
>>
>> Would adding such an escape character be useful?
>
> Yes, of course.
>
> Whenever a system has a system to escape symbols, there are two ways to go
> about it: either the symbol is magic by default, and the escape makes it
> normal, or the symbol is normal by default, and the escape makes it magic.
>
> Having both of the systems at once is generally confusing, because it
> makes it difficult to remember which symbols are which. It's more
> practical to have all of them be one or the other.
>
> One could say that having the symbols only become magic upon escapement is
> better, because it clearly indicates when a symbol has magic properties.
> This is analogous to the logic used to defend sigils, a form of
> disambiguation repeatedly found to be pointless because names already do
> that disambiguation. Therefore, the correct choice is magic by default.

Interesting points though I am not sure how you got to that conclusion
(or what you mean by "the logic used to defend sigils").

In particular, magic characters are sometimes used in contexts in which
there are no "names" with which to do any disambiguation. For example,
the regular expression to match "parts" and "party" might be

"part[sy]"

I presume you would take that as magic-by-default so any occurrence of a
magic symbol needs to be escaped as in a[b] appearing as

"a\[b\]"

Alternatively, if magic symbols were prefixed with ~ then the above two
strings would appear as

"part~[xy~]"
"a[b]"

Is that really worse?

>
> One fallacious argument i've heard used to justify magic by default is
> that it means that the treatment of the escape symbol itself is consistent
> with all the other symbols in that it's magic by default unless escaped by
> itself. I consider this fallacious because in a system where magic must
> be explicit, the escape symbol would be the _only_ exception, and it would
> be _impossible_ to make any others—what i'd say is a worthwhile sacrifice.

Indeed. In C, backslash does double duty

\n - backslash /gives/ significance to n
\" - backslash /removes/ the significance of the double quote

That inconsistency does seem odd.

>
> Either way, figuring out the solution to the problem of “Magic: by
> default or by request?” is almost certainly a lower priority than the
> majority of other problems.

It's an important issue nonetheless. And aren't there two contexts, as
follows?

(1) A string which has to be converted by the compiler into binary
encodings, e.g.

"Hello\nWorld"

(2) A string which /after any conversions/ means something to a function
which processes it, e.g.

"Hello\:space:world"

where "\:space:" is meant to indicate whitespace to some program which
processes the string and implies that the backslash has to remain in the
encoded string.

--
James Harris

Re: Escapes (was String-Based Macro Systems)

<symbols-20240503103235@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2538&group=comp.lang.misc#2538

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.misc
Subject: Re: Escapes (was String-Based Macro Systems)
Date: 3 May 2024 09:33:16 GMT
Organization: Stefan Ram
Lines: 18
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <symbols-20240503103235@ram.dialup.fu-berlin.de>
References: <uvcqn3$2pju0$1@dont-email.me> <pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid> <v12966$euk9$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de tBaIV86AWAzWSS1tVg4NcgCKbdk1f/IoOy13MyNow0NaKL
Cancel-Lock: sha1:iR8aiNydOUtkfDZ1d1cWEBsCP9E= sha256:zud/s80Je49RzR+yIsLAj3HISzXVYT8zoVG1P13amvU=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
 by: Stefan Ram - Fri, 3 May 2024 09:33 UTC

James Harris <james.harris.1@gmail.com> wrote or quoted:
>Alternatively, if magic symbols were prefixed with ~ then the above two
>strings would appear as
>"part~[xy~]"
>"a[b]"
>Is that really worse?

I reckon it's all about the stats. If a symbol shows up more often in
"regular text" than when used as a magic symbol, you're more inclined
to type more when it's used as a magic symbol, and vice versa.
>\n - backslash /gives/ significance to n
>\" - backslash /removes/ the significance of the double quote
>That inconsistency does seem odd.

This "inconsistency" here only stems from how you've worded
it above. You could phrase it differently, and then the
"inconsistency" would vanish.

Re: Escapes (was String-Based Macro Systems)

<wording-20240503104341@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2539&group=comp.lang.misc#2539

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.misc
Subject: Re: Escapes (was String-Based Macro Systems)
Date: 3 May 2024 09:43:57 GMT
Organization: Stefan Ram
Lines: 15
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <wording-20240503104341@ram.dialup.fu-berlin.de>
References: <uvcqn3$2pju0$1@dont-email.me> <pan$5d552$88135a24$abac79c8$4af1fb67@invalid.invalid> <v12966$euk9$1@dont-email.me> <symbols-20240503103235@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de HEqpyZQaYre/iRtJ25OJQQD7f4FI3o1354AW+lModmmrPR
Cancel-Lock: sha1:LmI8C3iNX1wIX/hGnGMb70EkgjI= sha256:eIdHbDS9xdL/HGy8Lph0nqroIVRE7lJW58GCOJINKdw=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
 by: Stefan Ram - Fri, 3 May 2024 09:43 UTC

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>>\n - backslash /gives/ significance to n
>>\" - backslash /removes/ the significance of the double quote
>>That inconsistency does seem odd.
>This "inconsistency" here only stems from how you've worded
>it above. You could phrase it differently, and then the
>"inconsistency" would vanish.

Take for instance:

The standard meaning of "n" is the letter,
the standard meaning of the quotation mark is delimitation.

The backslash consistently imparts a special meaning deviating
from that standard meaning in each case.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor