m4-discuss
[Top][All Lists]
Advanced

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

safe define


From: Werner LEMBERG
Subject: safe define
Date: Mon, 11 May 2015 12:08:46 +0200 (CEST)

Folks,


has someone ever written a `safe define' macro that makes the defined
macro expands to itself if called without any argument?

  sdefine({foo}, {bar})

  foo    =>  foo
  foo()  =>  bar

I tried the following, and I failed (due to lack of experience
w.r.t. quoting tricks, I think) – I have difficulties to delay the
expansion of `$#'...

Below, I've marked the problematic spots with (nonexisting)
pseudo-functions.

  define({sdefine},
    {define({$1},
       {ifelse(delay_expansion_of({$#}),
               {0},
               {{$1}},
               {expand_at_definition_time(shift($@))})})})


    Werner

reply via email to

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