Omni Systems, Inc.

  

Mif2Go User's Guide, Version 55

  

Valid HTML 4.01!

 

Made with Mif2Go

28 Working with macros > 28.4 Using multiple-value list variables > 28.4.5 Using pointers to process lists


28.4.5 Using pointers to process lists

The method described in §28.4.4 Using macros to process lists is fine for a single pair of lists. But what if you have many such pairs of lists? Using the actual names of the lists in the macro means including as many copies of the [Sidebar] macro as there are pairs of lists, even though the functionality is identical for all pairs. Instead, you can construct a macro that works for every pair of lists, using pointers (indirect references) to the lists instead of the literal names of the lists.

To create a pointer to a list, assign the list name, in quotes, to a macro variable:

<$$ptr="$$list">

A set-up macro could initialize the pointers, starting index, and ending index for the lists, then invoke the [Sidebar] macro, which is now generalized for any pair of lists:

[SetupMySidebar]

<$$fileptr="$$FM_File">

<$$textptr="$$SideTitle">\

<$$val=2><$$maxval=6>

<$Sidebar>

[Sidebar]

<$_while ($$val <= $$maxval)>\

  <$_if ($$_currbase is *$$fileptr[$$val])>\

    <p class="SidebarTxt"><*$$textptr[$$val]></p>\

    <$_else>\

    <p class="SidebarTxt"><a class="SidebarLnk"\

    href="<*$$fileptr[$$val]>.htm"><*$$textptr[$$val]></a></p>\

    <$_endif>

  <$$val++>

  <$_endwhile>

The asterisks in front of *fileptr[$$val] and *$$txtptr[$$val] indicate that these list variables are actually being used indirectly, as pointers to other lists. When you use the form *$$ptr[$$index], Mif2Go converts the reference internally to $$list[$$index] before retrieving the value.

Process a list of pointers

If you need to access a list of pointers, do it in two steps. Suppose you have a list that contains pointers to the other two lists in the sidebar example:

[PtrList]

1=$$FM_File

2=$$SideTitles

To access an item in [FM_File], first assign to a macro variable the pointer-list item that points to [FM_File]:

<$$ptr=$$PtrList[1]>

Thereafter you can use the macro variable as a pointer to [FM_File]; and so, referring to the [FM_File] list in §28.4.4 Using macros to process lists, <*$$ptr[2]> gets you the second item in the list, descript. You do not use quotes around the value in this case, because you want the actual list item in $$ptr, not a reference to the list.



28 Working with macros > 28.4 Using multiple-value list variables > 28.4.5 Using pointers to process lists