lists processing

Hi all,

I’ve a list

{{a1, a2, ...}, {b1, b2, ...}, ...}

Is a handy way to multiply each list item by, say, x?

Not directly (i.e. in the way that APL, Mathematica, MATLAB and others can), but we can define a handler to make it fairly, er, handy.

on run
	set nestedList to {{0, 1, 1.5, 2, 3}, {4, 5, 6, 7}, {{8, 9, 10}, {11, 12, 13}}, {14, {15, 16}, 17}}
	multiplyNestedItems of nestedList by 2
end run

to multiplyNestedItems of aList by aNumber
	if class of aList is list then
		set newList to {}
		repeat with listItem in aList
			set end of newList to multiplyNestedItems of listItem by aNumber
		end repeat
		newList
	else if class of aList is class of (aList as number) then
		return aList * aNumber
	end if
end multiplyNestedItems

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari Version 4 Public Beta (4528.17)
Operating System: Mac OS X (10.4)