this script might build something close to what you are after. the Formula parameter to the New Column function needs a completely built formula, in the form it needs to be in when it actually runs, which is after your script runs. the eval( evalexpr( ... expr(...) ... expr(...) ... ) ) strategy below is one way to do what you need. expr() is used to tag the parts that need to be evaluated. evalexpr() hunts them down and evaluates them. eval() evaluates the expression returned by evalexpr. Note the minus between the two expr() is NOT evaluated inside the for loop, but names[i+1] IS evaluated (by evalexpr) and NewColumn IS evaluated (by eval).
<<GetColumnNames returns a list of the table's column names. char() makes a string for concatenation.
dt = New Table( "Untitled",
Add Rows( 1 ),
New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1] ) ),
New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),
New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4] ) ),
New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [8] ) ),
New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [16] ) ),
New Column( "f", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32] ) )
);
cc = N col (dt);
names=dt<<getColumnNames;
For( i = 1, i <= cc, i = i + 2,
Eval( // evaluate the expression returned by...
Eval Expr( // evaluate the embedded expr...
New Column( "Delta " || char(names[ i + 1 ]), // convert the column to a string
numeric, continuous,
// Formula won't evaluate on its own. Needs TWO expr for this case
Formula( Expr( names[ i + 1 ] ) - Expr( names[ i ] ) )
)
)
)
);
/* ----- resulting script -----------------
New Table( "Untitled",
Add Rows( 1 ),
New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1] ) ),
New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),
New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [4] ) ),
New Column( "d", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [8] ) ),
New Column( "e", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [16] ) ),
New Column( "f", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [32] ) ),
New Column( "Delta b", Numeric, "Continuous", Format( "Best", 10 ), Formula( :b - :a ) ),
New Column( "Delta d", Numeric, "Continuous", Format( "Best", 10 ), Formula( :d - :c ) ),
New Column( "Delta f", Numeric, "Continuous", Format( "Best", 10 ), Formula( :f - :e ) )
)
*/
Craige