[Top][All Lists]

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

Re: iterating over arguments

From: Eric Blake
Subject: Re: iterating over arguments
Date: Mon, 14 Sep 2009 18:09:32 +0000 (UTC)
User-agent: Loom/3.14 (

Sam Steingold <sds <at>> writes:

> thanks a lot for your clear explanations!
> (sorry about copying your whole message, I want to preserve it in my mail 
> archives, it would be nice if you kept me in CC).

I wish I could - gmane is lousy at preserving cc.

> yes, now, with this patch:

> +test $cl_cv_clisp_]cl_feat[ = no && AC_MSG_ERROR([no ]CL_FEAT[ in CLISP])

> is converted to
> test $cl_cv_clisp_cl_feat = no && { { $as_echo "$as_me:$LINENO: error: no FFI 
> in CLISP" >&5

Ah.  This one is a case of underquotation - cl_feat was expanded too early.  
(Both Ralf and I did say that our first attempts were untested, after all ;)  
So, the next try is this.

m4_foreach_w([cl_feat], [$1],
[m4_pushdef([CL_FEAT], m4_toupper(cl_feat))dnl
AC_CACHE_CHECK([for CL_FEAT in CLISP], [cl_cv_clisp_]cl_feat,
   [[#+]]cl_feat[[ "yes" #-]]cl_feat[[ "no"]])])
test $cl_cv_clisp_[]cl_feat = no && AC_MSG_ERROR([no ]CL_FEAT[ in CLISP])

See the difference?  "$cl_cv_clisp_]cl_feat[" said to expand cl_feat prior to 
the body of the m4_foreach_w (and cl_feat was not defined as a macro at that 
point); whereas the new "$cl_cv_clisp_[]cl_feat" says that cl_feat is still 
quoted as part of the m4_foreach_w body, but separated by empty quotes from the 
rest of the text of the body so as to expand at the right point in time.

And if clisp ever comes up with a feature that resembles an m4 macro name, or 
contains (), ',', [], or $, (for example, if you added a "dnl" feature to 
clisp), then you should consider a more robust solution (again, untested, but 
hopefully this time I've learned from the thread what needs to happen).  If you 
aren't willing to rely on m4_toupper having its quoting fix that I will be 
adding in autoconf 2.65, you can use a raw m4_translit instead of m4_toupper 
for safety across older autoconf:

m4_foreach_w([cl_feat], [$1],
[m4_pushdef([CL_FEAT], m4_translit(m4_dquote(m4_defn([cl_feat])),
  [a-z], [A-Z]))dnl
AC_CACHE_CHECK([for m4_defn([CL_FEAT]) in CLISP],
   [[#+]]m4_dquote(m4_defn([cl_feat]))[[ "yes" #-]]m4_dquote(
      m4_defn([cl_feat]))[[ "no"]])])
test $cl_cv_clisp_[]m4_defn([cl_feat]) = no \
  && AC_MSG_ERROR([no ]m4_defn([CL_FEAT])[ in CLISP])

See how hairy it gets with all the extra m4_defn for safety?  Which is why I 
like my m4_map_args_w interface better (using $1 instead of m4_defn([varname]) 
is less typing, and more efficient use of m4); too bad I wasn't developing 
autoconf back in the 2.59 days ;)

Eric Blake

reply via email to

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