Macro? 
Author Message
 Macro?

Hi Folks!

Is there a good way to use REXX as a macro language to write other
REXX statements -- all in the same program?

I use SAS a lot at work (SAS is very REXX like) and do this all the
time for repetitive code.

For example, if I have:

field1 field2 ... fieldn

somewhere in the code, I don't have to type them all in, I can just
use a SAS macro to generate this code. Same is true of any piece of
repetitive code, even stuff much more complex.

In the above, 1, 2, ... n would be a SAS macro variable and done with
a macro do loop. Of course, the macro stuff must be processed first
and put into memory prior to actual execution of the final code

This allows me to for example have one program that rewrites itself
500 times making changes each time to generate up 500 different
graphs.

I've read the groups on deja, looked through my REXX lit, etc. It
seems that REXX might allow me to do the same, but I'm unsure as to
how. Looks like INTERPRET or VALUE would be part of the process.

Anyhoo, if this makes any sense to you and you have any thoughts that
might make my little light come on, please gently shove me in the
right direction. :->

Thanks,

JVB
--



Mon, 20 Dec 2004 19:45:57 GMT  
 Macro?

Quote:

> Is there a good way to use REXX as a macro language to write other
> REXX statements -- all in the same program?

> I use SAS a lot at work (SAS is very REXX like) and do this all the
> time for repetitive code.

> For example, if I have:

> field1 field2 ... fieldn

> somewhere in the code, I don't have to type them all in, I can just
> use a SAS macro to generate this code. Same is true of any piece of
> repetitive code, even stuff much more complex.

> In the above, 1, 2, ... n would be a SAS macro variable and done with
> a macro do loop. Of course, the macro stuff must be processed first
> and put into memory prior to actual execution of the final code

> This allows me to for example have one program that rewrites itself
> 500 times making changes each time to generate up 500 different
> graphs.

> I've read the groups on deja, looked through my REXX lit, etc. It
> seems that REXX might allow me to do the same, but I'm unsure as to
> how. Looks like INTERPRET or VALUE would be part of the process.

You're right: the INTERPRET command is the way to go. You simply build a string
that is a valid chunk of REXX code and use INTERPRET to execute it.

--
        -- Aron

NB: To reply by e-mail, remove "spam-block." from my address.
- - - - - - - - - - -
"A cold heart is more dangerous and deadly than any weapon."

        -- Hiltgunn Zassenhaus



Tue, 21 Dec 2004 01:23:48 GMT  
 Macro?
In article


Quote:
> Hi Folks!
> Is there a good way to use REXX as a macro language to write other
> REXX statements -- all in the same program?

No.  The source that will be interpreted is already stored, and perhaps
partially tokenised by the time the program starts to be executed.

You can of course write program code to a different file and invoke that
but it's not the same.

Quote:
> I use SAS a lot at work (SAS is very REXX like) and do this all the
> time for repetitive code.

If I understand you correctly you're using SAS macro; macro expanders
typically (always?) expand the source text of a program so that it
appears as if the expanded form had been entered in the first place - ie
it's just a shorthand.  Rexx doesn't have a macro capability.

You might see the word macro used in discussions of rexx; that's partly
because some people call all programs like clists and rexx execs "macros"
and partly because scripts which run within ispf edit are known as ispf
edit macros and they can be written in rexx (or clist or cobol or
assembler or PL/1 or...).

I'd dispute that sas (or even sas macro) is rexx like.  In my experience
programming in sas is full of concerns about things like data formats
and layouts, and the sas dataset concept is completely alien to rexx.

--
Jeremy C B Nicoll - my opinions are my own.



Mon, 20 Dec 2004 22:46:27 GMT  
 Macro?


Quote:

> > I've read the groups on deja, looked through my REXX lit, etc. It
> > seems that REXX might allow me to do the same, but I'm unsure as to
> > how. Looks like INTERPRET or VALUE would be part of the process.
> You're right: the INTERPRET command is the way to go. You simply build
> a string that is a valid chunk of REXX code and use INTERPRET to
> execute it.

No, that's a terrible idea.

INTERPRET is ok for the occasional line that can't be done any other way,
but not to generate the entire program which is pretty much what Johnny
does with sas macro.

In any case a program that contained all the possible logic to build each
single line and interpret it one line at a time would be a) complex, and
b) run like a dog with no legs

--
Jeremy C B Nicoll - my opinions are my own.



Tue, 21 Dec 2004 05:19:15 GMT  
 Macro?

Quote:

> > Is there a good way to use REXX as a macro language to write other
> > REXX statements -- all in the same program?

> No.  The source that will be interpreted is already stored, and perhaps
> partially tokenised by the time the program starts to be executed.

If that were the case, then INTERPRET and VALUE would have to be dropped
from Rexx. No, you can have the program dynamically build a string which
is a line of code, and execute it at any given time in the program. You
could for example read in a line from a text file and pass it to
INTERPRET as a single line of code to run. I have one application which
does just that - with some special preparation of the string as it is
read in from disk.

As well, VALUE is a great way in Classic Rexx to write a static function
which works with a run-time specified variable... the name of the
variable is passed to VALUE and VALUE takes care of accessing the
variable you wish to have accessed.

--
Michael Lueck
Lueck Data Systems

Remove the upper case letters NOSPAM to contact me directly.



Tue, 21 Dec 2004 10:41:14 GMT  
 Macro?

Quote:
> b) run like a dog with no legs

Would that make it doxin.rex ???

--
Michael Lueck
Lueck Data Systems

Remove the upper case letters NOSPAM to contact me directly.



Tue, 21 Dec 2004 10:44:20 GMT  
 Macro?
In Object REXX, you can add new methods to an object instance
via setmethod. The code of the new method can have any length.

Here's a small example:

/* dynamically add a method to an instance */

obj = .dynmeth~new

my_code = .array~of("say 'Hello World'", "do i = 1 to 10",,
                   "  say 'this is a test. iteration' i", "end")

say "running the following code:"
say "-"~copies(40)
do i over my_code
  say i
end
say "-"~copies(40)

obj~add("my_method", my_code)  -- create method
obj~my_method  -- run method

exit

::CLASS dynmeth

::METHOD add
  use arg name, code
  newmethod = .method~new(name, code)
  self~setmethod(name, newmethod)

Trial downloads of Object REXX for various platforms can be found at
http://www.software.ibm.com/webapp/download/product.jsp?s=p&id=TDUN-4...

Kind regards,
Jan Engehausen, REXX Development, IBM Germany



Tue, 21 Dec 2004 13:44:45 GMT  
 Macro?
Here's the correct one:

http://www14.software.ibm.com/webapp/download/product.jsp?s=p&id=TDUN...

Kind regards,
Jan Engehausen, REXX Development, IBM Germany



Tue, 21 Dec 2004 14:15:51 GMT  
 Macro?


Quote:

> > > Is there a good way to use REXX as a macro language to write other
> > > REXX statements -- all in the same program?

> > No.  The source that will be interpreted is already stored, and
> > perhaps partially tokenised by the time the program starts to be
> > executed.
> If that were the case, then INTERPRET and VALUE would have to be dropped
> from Rexx. No, you can have the program dynamically build a string which
> is a line of code, and execute it at any given time in the program.

Yup ok, but the query, in sas macro terms relates to building substantial
portions of a program via macro expansion before starting to execute the
program.

Of course you could write a rexx exec that generated lots of lines of
code then ran a loop calling interpret to process each one, but can you
imagine the overhead that would cause?  Far better to generate a new exec
and write it to some file somewhere then call it.

--
Jeremy C B Nicoll - my opinions are my own.



Wed, 22 Dec 2004 03:11:29 GMT  
 Macro?
On Fri, 05 Jul 2002 20:11:29 +0100, Jeremy C B Nicoll

Quote:




>> > > Is there a good way to use REXX as a macro language to write other
>> > > REXX statements -- all in the same program?

>Yup ok, but the query, in sas macro terms relates to building substantial
>portions of a program via macro expansion before starting to execute the
>program.

>Of course you could write a rexx exec that generated lots of lines of
>code then ran a loop calling interpret to process each one, but can you
>imagine the overhead that would cause?  Far better to generate a new exec
>and write it to some file somewhere then call it.

I'm note sure that what I will suggest is suitable (not sure of your
requirements) but my PPWIZARD preprocessor (free) has very powerful
macro capability, is programmable in rexx and so could generate a
custom tailored rexx program which could then the executed.

Bye,
Dennis

----------------------------

http://www.labyrinth.net.au/~dbareis/index.htm
   * PPWIZARD, HTML preprocessor (or rexx/Javascript etc) - #define, #include, #import SQL, #if)
   * URL Checker (check external links in web pages)
----------------------------



Wed, 22 Dec 2004 09:52:23 GMT  
 Macro?
On Thu, 4 Jul 2002 14:46:27 UTC, Jeremy C B Nicoll

Quote:

> If I understand you correctly you're using SAS macro; macro expanders
> typically (always?) expand the source text of a program so that it
> appears as if the expanded form had been entered in the first place - ie
> it's just a shorthand.  Rexx doesn't have a macro capability.

Yep, that's essentially it. You can for example say:

%do &1=1 %to 500;
  data &i;
      more stuff goes here
%end;

This would execute 500 different data steps or whatever. You can do
some things like this in REXX with stem variables, but anything really
complex
seems confounding -- at least to me! :->

Quote:
> You might see the word macro used in discussions of rexx; that's partly
> because some people call all programs like clists and rexx execs "macros"
> and partly because scripts which run within ispf edit are known as ispf
> edit macros and they can be written in rexx (or clist or cobol or
> assembler or PL/1 or...).

Yep, my 1st "computer" was my VM session.

Quote:
> I'd dispute that sas (or even sas macro) is rexx like.  In my experience
> programming in sas is full of concerns about things like data formats
> and layouts, and the sas dataset concept is completely alien to rexx.

True enough. The syntax, a lot of the key words, etc. are similar or
the same. As you point out, the actual work to be done is often pretty
different.

I guess they seem the same to me since I've used both together, 1st on
CMS, then on MVS, and now on AIX (SAS) and OS/2 (REXX). The SAS editor
is very much like XEDIT/EDIT and the SAS concept of library, member,
etc. is virtually a duplicate of MVS from which I assume it probably
came.

Anyhoo, thanks to you and to all the others who offered opinions/help.

Cheers,

JVB



Wed, 22 Dec 2004 11:58:32 GMT  
 Macro?
|> Is there a good way to use REXX as a macro language to write other
|> REXX statements -- all in the same program?
|>
|> I use SAS a lot at work (SAS is very REXX like) and do this all the
|> time for repetitive code.

|> For example, if I have:

|> field1 field2 ... fieldn

|> somewhere in the code, I don't have to type them all in, I can just
|> use a SAS macro to generate this code. Same is true of any piece of
|> repetitive code, even stuff much more complex.
|>
|> In the above, 1, 2, ... n would be a SAS macro variable and done with
|> a macro do loop. Of course, the macro stuff must be processed first
|> and put into memory prior to actual execution of the final code

|> This allows me to for example have one program that rewrites itself
|> 500 times making changes each time to generate up 500 different
|> graphs.

|> I've read the groups on deja, looked through my REXX lit, etc. It
|> seems that REXX might allow me to do the same, but I'm unsure as to
|> how. Looks like INTERPRET or VALUE would be part of the process.

| You're right: the INTERPRET command is the way to go. You simply build a string
| that is a valid chunk of REXX code and use INTERPRET to execute it.

Yes.  I thought I'd expatiate "a valid chunk of REXX code":  if you're going
to build a REXX   "DO" loop or "SELECT", you have to have the complete loop
or "WHEN's" (along with the "END") for the INTERPERT to work.  I don't know
about "coding"  (er, interpreting) a subroutine --- that is, how interpret is
supposed to work/function when you pass it a (subroutine) label, or any label
for that matter, especially an "ON" conditon label. _________________Gerard S.



Wed, 22 Dec 2004 23:47:49 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. A macro involving two sub-macros - where the 2nd macro needs results from the first

2. macro -vs- macro/codeblock

3. Help with macros writing macros in Bigloo

4. syntax-rules macros with sub-macros

5. Scheme macro source: rewriter-widget, a widely applicable macro interface

6. Macros defining macros with define-syntax

7. symbol-macros and regular macros

8. Question about a macro-defining macro

9. Macro-Defining Macros

10. macro macros

11. Local macro within a macro?

12. how much macro is too much macro

 

 
Powered by phpBB® Forum Software