error on using $# and m4wrap

Hyunho Cho <[email protected]>
Newsgroups gmane.comp.gnu.m4.bugs
Message-ID <CAMMw4704TWD+K4Zsq-2s1R4ERLUS96uJn1xSQ+n1QSb5ds24AA@mail.gmail.com>
m4 (GNU M4) 1.4.18
Operating System: Ubuntu 20.04 LTS
Kernel: Linux 5.4.0-33-generic
Architecture: x86-64

### 1. if i define $# as macro body then error occurred

$ m4 <<\@
define(`foo', $2)
foo(100,200,300)
@

200                          # OK
---------------------

$ m4 <<\@
define(`foo', $#)
foo(100,200,300)
@
m4:stdin:1: ERROR: end of file in argument list
-----------------------

$ m4 <<\@
define(`foo', `$#')         # must quote `$#'
foo(100,200,300)
@

3                            # OK

###################################################

### 2. if i invocate m4wrap just once then return macro body

$ m4 <<\@
define(`foo', 11111)dnl
define(`bar', 22222)dnl
define(`zoo', 33333)dnl
m4wrap(`zoo')dnl
99999
@
99999
33333      <---- not zoo but 33333

$ m4 <<\@
define(`foo', 11111)dnl
define(`bar', 22222)dnl
define(`zoo', 33333)dnl
m4wrap(`foo')dnl
m4wrap(`bar')dnl
m4wrap(`zoo')dnl
99999
@
99999
zoobarfoo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.