I have an (excerpted) macro that looks like this:

  $ cat x
  #! /bin/bash

  m4 -P <<'eof!'
  m4_define(LINKS, `hrf(flquotes-m4_eval($1 + 1).html, m4_eval($1 + 1))')
  LINKS(2025)
  eof!

  $

It works fine

  $ ./x

  hrf(flquotes-2026.html, 2026)

  $

except in the full macro I call hrf() all over the place and I'd like to
replace that detailed structure with a call to a macro (and I'd like to avoid
repeating the call to m4_eval()).  Done easily enough:

  $ cat ./x
  #! /bin/bash

  m4 -P <<'eof!'
  m4_define(LNK, `hrf(flquotes-$1.html, $1)')
  m4_define(LINKS, `LNK(m4_eval($1 + 1))')
  LINKS(2025)
  eof!

  $ ./x


  hrf(flquotes-2026.html, 2026)

  $

But LNK() is scoped to LINKS() and I'd like the code to reflect that.  Seems
easy too:

  $ cat x
  #! /bin/bash

  m4 -P <<'eof!'
  m4_define(LINKS,
    `m4_define(LNK, `hrf(flquotes-$1.html, $1)')
     LNK(m4_eval($1 + 1))
     m4_undefine(`LNK')
    ')

  LINKS(2025)
  eof!

  $ ./x



     hrf(flquotes-2025.html, 2025)



  $

except it doesn't work.  It seems $1 in LNK() is being bound at definition
time, and I can't figure out a quoting structure to delay the binding to call
time.  Is that sort of thing possible, and if so, how do I do it?

  $ m4 --version
  m4 (GNU M4) 1.4.19
  Copyright (C) 2021 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later 
<https://gnu.org/licenses/gpl.html>.
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.

  Written by René Seindal.

  $ 


Reply via email to