|Anonymous | Login||2021-05-08 06:49 UTC|
|Main | My View | View Issues | Change Log | Docs|
|Viewing Issue Simple Details|
|ID||Category||Severity||Type||Date Submitted||Last Update|
|0001072||[1003.1(2013)/Issue7+TC1] Shell and Utilities||Comment||Clarification Requested||2016-08-27 01:18||2019-10-28 10:31|
|Priority||normal||Resolution||Accepted As Marked|
|Page Number||2899, 2901|
|Line Number||95625, 95733|
|Final Accepted Text||see Note: 0003919|
|Summary||0001072: m4 ifelse argument expansion clarification|
The description of the m4 ifelse macro includes the following sentence:
If the first two arguments compare as equal strings (after macro expansion of both arguments), the defining text shall be the third argument.
The parenthetical remark is presumably intended to be a reminder that all arguments are expanded as they are collected, but it can also be interpreted to mean that these two particular arguments are expanded a second time. It is difficult to refute this interpretation because this section provides little explanation of how arguments are expanded and generally uses the word "argument" to refer to an argument that has already been expanded as it was collected.
To illustrate, consider the following example:
define(`foo', `bad')dnl define(`bar', `bad')dnl ifelse(foo, bar, `hello')`'dnl ifelse(`foo', `bar', ` world')`'dnl ifelse(``foo'', ``bar'', ` never')
It is clear that the first comparison is true and the third is false, but what about the second? Should the output of this example be "hello", or should it be "hello world"? The expectation is that it should be "hello", but the parenthetical remark raises the concern that it may be "hello world". The output is indeed "hello" on several implementations: GNU M4 1.4.17, FreeBSD 10.3, and OpenIndiana Hipster 2016.04.
On line 95625, add the following sentence to the end of the paragraph to provide some explanation of how arguments are expanded:
Macro expansion is performed on the arguments as they are collected.
On line 95733, remove the following parenthetical remark to maintain consistency with the general use of the word "argument" to refer to an argument that has already been expanded as it was collected:
(after macro expansion of both arguments)
The formatting in my original example didn't work properly. I used br elements instead of newline characters inside the pre element to try to ensure that double spacing would not occur from newline characters possibly being decorated with br elements, but the br elements ended up being removed, joining the lines together. Here's the example again, this time with newline characters:
define(`foo', `baz')dnl define(`bar', `baz')dnl ifelse(foo, bar, `hello')`'dnl ifelse(`foo', `bar', ` world')`'dnl ifelse(``foo'', ``bar'', ` never')
Don Cragun (manager)
|"br" tags in Description replaced by literal <newline> characters (as suggested in Note: 0003366).|
edited on: 2018-02-09 15:02
The standard is unclear on this issue, and no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor.
All known m4 implementations perform macro expansion and argument collection in the same manner; but the wording used in the standard did not give enough details on how this occurs.
Notes to the Editor (not part of this interpretation):
All page and line numbers are for the 2016 edition.
On page 2934 lines 97081-97090 change:
The m4 utility shall compare each token from the input against the set of built-in and user-defined macros. If the token matches the name of a macro, then the token shall be replaced by the macro’s defining text, if any, and rescanned for matching macro names. Once no portion of the token matches the name of a macro, it shall be written to standard output. Macros may have arguments, in which case the arguments shall be substituted into the defining text before it is rescanned.to:
The m4 utility shall compare each token from the input against the set of built-in and user-defined macros. If the token matches the name of a macro, then the token shall be replaced by the macro’s defining text, if any, then scanning for tokens shall resume at the start of the macro's defining text concatenated with the subsequent input. If a token does not match the name of a macro, it shall be written to standard output. Macros may have arguments, in which case the arguments shall be substituted into the defining text before it is rescanned.
On page 2934 lines 97094-97106 change:
If a macro name is followed by a <left-parenthesis>, its arguments are the <comma>-separated tokens between the <left-parenthesis> and the matching <right-parenthesis>. Unquoted white-space characters preceding each argument shall be ignored. All other characters, including trailing white-space characters, are retained. <comma> characters enclosed between <left-parenthesis> and <right-parenthesis> characters do not delimit arguments.to:
If a macro name is followed by a <left-parenthesis>, the subsequent text shall be tokenized and expanded until a token is encountered that is not a quoted string and whose expansion includes a matching unquoted <right-parenthesis>. The expanded text between the <left-parenthesis> and the matching unquoted <right-parenthesis> is the macro's argument text. An unquoted <comma> character within the macro's argument text shall mark the end of one argument and the beginning of the next argument unless the unquoted <comma> is enclosed within a nested unquoted <left-parenthesis>, <right-parenthesis> pair. The unquoted <comma> characters that separate the arguments, and any unquoted whitespace characters at the beginning of each argument, shall be discarded. All other characters in the macro's argument text, including any whitespace characters at the end of an argument and any nested parenthesized text, shall be retained. The input text containing the macro name, the following <left-parenthesis>, and all tokens up to and including the token whose expansion contained the matching unquoted <right-parenthesis> shall be replaced, and tokenization shall resume on the result of performing argument substition on the macro's defining text followed by any expanded text that followed the matching unquoted <right-parenthesis>. Otherwise, the macro name was not followed by a <left-parenthesis>, and tokenization shall resume on the result of performing argument substitution with zero arguments on the macro's defining text.
On page 2934, delete lines 97110-97116:
No special meaning is given to any characters enclosed between matching left and right quoting strings, but the quoting strings are themselves discarded. By default, the left quoting string consists of a grave accent (backquote) and the right quoting string consists of an acute accent (single-quote); see also the changequote macro.(as these lines were moved and reworded in the earlier changeset at line 97081)
On page 2935 line 97129 (changecom), change:
The behavior is unspecified if either argument is provided but null.to:
The behavior is unspecified if either argument is provided but null, or if either argument includes letters, digits, underscore, or <left-parenthesis>.
On page 2935 line 97133 (changequote), change:
The behavior is unspecified if there is a single argument or either argument is null.to:
The behavior is unspecified if there is a single argument, or if either argument is null or includes letters, digits, underscore, or <left-parenthesis>.
On page 2936 line 97206 (ifelse), remove the following parenthetical remark:
(after macro expansion of both arguments)
On page 2940, in the EXAMPLES section, after line 97369, add the following (note to editor: feel free to use bullets or other list identifiers instead of numbers, if that is better):
In the following six examples, an additional line is evaluated after this prologue of three definitions:
|Interpretation Proposed: 30 September 2018|
|Interpretation approved: 12 November 2018|
|2016-08-27 01:18||quinngrier||New Issue|
|2016-08-27 01:18||quinngrier||Name||=> Quinn Grier|
|2016-08-27 01:18||quinngrier||Section||=> m4 (utility)|
|2016-08-27 01:18||quinngrier||Page Number||=> 2899, 2901|
|2016-08-27 01:18||quinngrier||Line Number||=> 95625, 95733|
|2016-08-29 03:01||quinngrier||Note Added: 0003366|
|2016-08-29 03:28||Don Cragun||Interp Status||=> ---|
|2016-08-29 03:28||Don Cragun||Note Added: 0003367|
|2016-08-29 03:28||Don Cragun||Description Updated|
|2016-08-29 03:29||Don Cragun||Description Updated|
|2018-02-09 14:47||eblake||Note Added: 0003919|
|2018-02-09 14:47||eblake||Note Edited: 0003919|
|2018-02-09 14:50||eblake||Note Edited: 0003919|
|2018-02-09 14:51||eblake||Note Edited: 0003919|
|2018-02-09 14:55||eblake||Note Edited: 0003919|
|2018-02-09 15:00||eblake||Note Edited: 0003919|
|2018-02-09 15:02||eblake||Note Edited: 0003919|
|2018-02-09 15:03||eblake||Interp Status||--- => Pending|
|2018-02-09 15:03||eblake||Final Accepted Text||=> see Note: 0003919|
|2018-02-09 15:03||eblake||Status||New => Interpretation Required|
|2018-02-09 15:03||eblake||Resolution||Open => Accepted As Marked|
|2018-02-09 15:31||geoffclare||Tag Attached: tc3-2008|
|2018-09-30 18:41||ajosey||Interp Status||Pending => Proposed|
|2018-09-30 18:41||ajosey||Note Added: 0004142|
|2018-11-12 19:47||ajosey||Interp Status||Proposed => Approved|
|2018-11-12 19:47||ajosey||Note Added: 0004164|
|2019-10-28 10:31||geoffclare||Status||Interpretation Required => Applied|
|Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group|