m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help: Using eval to return value of $1, $2...?


From: Aaron Bush
Subject: Help: Using eval to return value of $1, $2...?
Date: Thu, 24 Jan 2002 14:58:03 -0500

I have a call to a macro like this:
abmacro(`zz', `1', `3', `abc', `4', `8')

abmacro should process the argunments in groups of three such as
displaying:
"zz-1 zz-2 zz-3"
for the first three arguments and then move on to process the next three
arguments and display:
"abc-4 abc-5 abc-5 abc-6 abc-7 abc-8".

I am trying to accomplish this using a forloop nested in another forloop
(I'm using the forloop example macro from the GNU-m4 docs). What i am
looking for is to build a macro that will take $@ as an argument and
return the value of $(offset) using eval.

Here is the test example:

define(forloop,`pushdef(`$1',`$2')_forloop(`$1',`$2',`$3',`$4')popdef(`$1')')dnl
define(_forloop,`$4`'ifelse($1,`$3',
,`define(`$1',incr($1))_forloop(`$1',`$2',`$3',`$4')')')dnl

define(`arg1', `$eval(3*itn + 1)')dnl

define(`abmacro', `forloop(`itn', `0', eval($#/3 - 1),
`forloop(`v',`$2',`$3', `arg1($@)-v'.. )')')dnl

abmacro(`zz', `1', `3', `abc', `4', `8')

----
The output is this:
$1-1.. $1-2.. $1-3.. $4-1.. $4-2.. $4-3..

The goal is to have $1 and $4 replaced with the _real_ $1 and $4 values.

Any ideas on how to get this done? This is my first day using m4 so i'm
still learning...

Thanks,
-ab



reply via email to

[Prev in Thread] Current Thread [Next in Thread]