Re: m4 recursive macro help

From: Erik Max Francis (max_at_alcyone.com)
Date: 09/10/03

  • Next message: Bill Marcum: "Re: Compile error: wrong machine type"
    Date: Wed, 10 Sep 2003 14:41:42 -0700
    
    

    Jason Sinnamon wrote:

    > I need to search a list of values such that I can do something like
    > this:
    >
    > define(`match', `index(:word1:word2:, :$1:)')
    >
    > define(`rmatch', ?????)
    >
    > rmatch(word1, word2, word3,
    >
    > line1
    > line2
    >
    > )
    >
    > The lines should be printed if one of the words matches a word in the
    > colon-separated list. The macro for matching a single word from the
    > list
    > works, I am just really stuck on the recursive match macro.

    So do the following (pseudocode):

    1. if there is only one argument in the list (the lines to print), then
       exit
    2. search for the first word in the table
    3. if it is present, print the last argument in the list and exit
    4. if it is not present, call recursively with the first argument
       removed

    The only tricky part here is printing the last argument to a macro,
    since there is no builtin way to do this in m4 (that I'm aware of), and
    if there are more than 9 arguments to the list it can get ugly. So,
    write a support macro which recurses through its argument list to find
    the last argument:

    1. if the number of arguments is 1, print it and exit
    2. if it is not 1, then call recursively with the first argument removed

    -- 
       Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
     __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    /  \ I want to know God's thought; the rest are details.
    \__/  Albert Einstein
    

  • Next message: Bill Marcum: "Re: Compile error: wrong machine type"

    Relevant Pages

    • Re: calculate on exit/macro exit
      ... I can't see any good reason for an 'on exit' macro and 'calculate on exit' not to happily co-exist. ... In your original post you said "I also had an exit macro on one formfield to hide/unhide some text below the table depending upon ... Dim Toggle As Boolean ...
      (microsoft.public.word.vba.general)
    • Re: Adding Multiple Rows to a Table in a Word Form
      ... last row regardless how I exit the field. ... my End Sub statement to an Exit Sub statement. ... Whenever I TAB out of the last cell, ... exit" macro. ...
      (microsoft.public.word.vba.general)
    • Re: calculate on exit/macro exit
      ... Why does calculate on exit and macro exit not work together? ... If I have 'calc on exit checked' and NHB macro on exit to run, ... In your original post you said "I also had an exit macro on one formfield to hide/unhide some text below the table depending upon ... Dim Toggle As Boolean ...
      (microsoft.public.word.vba.general)
    • Re: calculate on exit/macro exit
      ... I can't see any good reason for an 'on exit' macro and 'calculate on exit' not to happily co-exist. ... Dim Toggle As Boolean ... > ' ActiveDocument.Protect wdAllowOnlyFormFields, NoReset ...
      (microsoft.public.word.vba.general)
    • Re: Number of check boxes checked
      ... instead of "run on exit". ... I did this on every checkbox and now the ... I can see what the macro does but how do I actually make the "macro ... Dim Count As Long ...
      (microsoft.public.word.vba.general)