[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .ie as target of .if

From: John Gardner
Subject: Re: .ie as target of .if
Date: Wed, 2 Sep 2020 15:19:54 +1000

No, it isn't valid. What .if and .ie do is read one line, then decide
whether it gets processed or skipped, depending on the condition. The real
magic is in the \{ sequence, which is the only thing in the Roff language
resembling a "multi-line" statement.

Troff, in a manner befitting a text processor, processes its input one line
at a time. This is an important thing to wrap your head around, because it
demystifies a lot of the syntax's "weirdness". Here's a dummy program to
illustrate how \{ … \} get interpreted the same as everything else: once
they're reached:

' \}
' ig }
.de IF
' if \\$1 \{'
.IF 1 {
1. Foo
2. Bar
3. Baz
4. Qux

Unless you remove the .BREAK line, the output will be:

1. Foo
2. Bar

On Tue, 1 Sep 2020 at 21:37, Tadziu Hoffmann <>

> > .if COND1 .ie COND2 xxx
> > .          el yyy
> > If this is considered working as designed, however, the
> > documentation ought to mention the restriction.  It currently
> > implies the opposite, by saying the part after the condition
> > in an .if request "is interpreted as though it was on a line
> > by itself."  Were the .ie in fact on a line by itself, groff
> > wouldn't grumble about the .el.
> I think it is working as intended.  "ie" pushes the result
> of the conditional test onto a stack ("if" does not), to be
> popped by a future "el".  So if COND1 is true, that stack
> contains the test result of COND2, which the "el" can use.
> If COND1 is false, the "ie" is never executed, and the stack
> remains empty, so "el" complains.
> Note that if there had been another "ie" before your program
> fragment, then your "el" would be consuming its result.
> So you can create some very interesting code this way.
> The documentation should say that it "is interpreted as
> though it was on a line by itself IF THE CONDITION IS TRUE".
> If not, it is never executed (except perhaps macro expansions
> that take place while the line is being read).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]