Macro Substitution

Jim Ault JimAultWins at
Mon Oct 9 20:45:41 CDT 2006

On 10/9/06 1:38 PM, "Robert Sneidar" <bobs at> wrote:

> Lemme cite an example of Macro Substitution:
> put "/sbt/apdata1/apmast" into m0apmast
> put "02" into m0company
> now referring to &m0apmast.&m0company. would yield "/sbt/apdata1/
> apmast02"
> The ampersand is the Macro Substitution operator in Foxpro.

Try thinking custom properties for a moment
no declarations needed, as opposed to globals
working code just ahead....

function gcp whichcp  --getCustProp
--eg.       put gcp(m0company) into partVar

on scp whatVal, whichcp  --setCustProp
               scp "02", m0company
               scp "/sbt/apdata1/apmast", m0apmast

--one-line version
      scp "02", m0company;  scp "/sbt/apdata1/apmast", m0apmast

----------------------------start code copy here --------------
on scp whatVal, whichcp
  put quote into q
  get merge ("set the [[whichcp ]] of this stack to [[q& whatVal &q]]")
  do it
  save this stack --persistent in the IDE
end scp

function gcp whichcp
  get merge("get the [[whichcp ]] of this stack")
  do it
  return it
end gcp

-----------sample script useage
on operatingScript
  scp "/sbt/apdata1/apmast", m0apmast
  scp "02", m0company
  answer gcp(m0apmast)&gcp(m0company)
end operatingScript
--no globals were maimed in this exercise

-------- end code copy here ---------------------------------------------

> I think I can code around this. It's just that I am finding I am
> going to have to do a lot of recoding to make this port work.
---Try this code-morphing script FP>Rev
Each line of code will have the replacement
  &m0company.  >  gp(m0company)

fld input ---->
FOR each &m0apmast.&m0company.
SORT &m0apmast.&m0company. AND tbleOne

fld output ---------->
FOR each gp(m0apmast)&gp(m0company)
SORT gp(m0apmast)&gp(m0company) AND tbleOne

on cpTest
  put fld input into textBlock
  repeat for each line LNN in textBlock
    put LNN into codeLine
    replace "&" with cr&"&" in codeLine
    repeat for each line LNN2 in codeLine
      if char 1 of LNN2 is "&" then --morph this macro
        get LNN2
        replace "." with ")" in it
        replace "&" with "gp(" in it
        replace cr with empty in it
        put it after thisCodeLine
        replace ")gp(" with ")&gp(" in thisCodeLine
        put LNN2 after thisCodeLine
      end if
    end repeat
    put thisCodeLine & cr after newCodeLines
    put empty into thisCodeLine
  end repeat
  put newCodeLines into fld output
end cpTest

Try this form of using a global array
global mA --macro array storage

put "/sbt/apdata1/apmast" into mA[m0apmast]
put "02" into mA[ m0company]

answer mA[m0apmast]&mA[m0company]
using custom properties, that don't have to be declared

set the m0apmast of this stack to "/sbt/apdata1/apmast"
set the m0company of this stack to "02"

If you are thinking of multi-line macro substitution (which would be the
same as a subroutine call with no parameters), which is more than one line
in the Macro, then Rev's equivalent would be a library of handlers or

Hope this gets you a little closer to your goal

Jim Ault
Las Vegas

More information about the use-livecode mailing list