Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2002-02-22 17:02:26


>
> > > And nearly anything would be better then m4.
> >
> > "Nearly anything" won't necessarily accomplish what m4 accomplishes.
> > What would be some viable alternatives?
>
> Huh? m4 is just a scripting language that does macro expansion.
> Perl could have been used instead (and actually was considered). Or
> python. Heck, even Java would work for this even though Java isn't a
> scripting language.

What is wrong with m4? I have in the past attempted to replicate
what m4 does with perl and others and other languages really aren't
as elegant as they seem. You end up constantly switching from the
output stream to the programming language.

Ie. What is fairly clear in m4

  define([FOO],[dnl
  // proxy to bar
  template <LOOP(class T%1,$2)>
  $1 foo_function(LOOP(T%1 t%1))
    {
      ifelse($1,void,,return ) bar(LOOP(t%1));
    }
  ])
 
  FOO(int,1)
  FOO(int,2)
  FOO(int,3)
  FOO(void,1)
  FOO(void,2)
  FOO(void,3)

becomes something totally unreadable in perl

  sub expand_FOO
  {
    ($return_type,$args)=@_;
    print "// proxy to bar\n";
    print "template <";
    for ($i=1;i<=$args;$i++)
      { print "class T$i t$i" };
    print ">\n";
    print "$return_type foo_function(";
    for ($i=1;i<=$args;$i++)
      { print "T$i t$i" };
    print ")\n";
    print " {\n";
    print " "; print "return" if ($return_type!="void");
    print "bar(";
    for ($i=1;i<=$args;$i++)
      { print "t$i" };
    print ");\n";
    print "}\n";
  }
  
  expand_FOO("int",1)
  expand_FOO("int",2)
  expand_FOO("int",3)
  expand_FOO("void",1)
  expand_FOO("void",2)
  expand_FOO("void",3)

becomes something totally unreadable in perl. Of course
this is because auto* tools are making shell scripts rather
the directly making scripts so this argument doesn't cleanly
apply to a different system.

Further, m4 is not a scripting language. It is a macro expansion
tool and a more fair comparision would be m4 to cpp. On that
account m4 wins hands down. Maybe better comparision would be php.

--Karl
  (One of the few people on Earth who like m4)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk