       Re: Style Question: The Functional Way

• To: mathgroup at smc.vnet.net
• Subject: [mg115809] Re: Style Question: The Functional Way
• From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
• Date: Fri, 21 Jan 2011 04:32:42 -0500 (EST)

```On Thu, 20 Jan 2011, Just A Stranger wrote:

> Hello,
>
> So I'm trying to learn how to do things the functional way. As an exercise
> I'm trying to program a simple economics related table that gives revenue,
> marginal revenue, etc given a demand schedule (2 lists of numbers
> representing quantity and price respectively). A simple task in a
>
> The point is that I need a list of the differences in the given lists, from
> which I will be using to get marginal values (derivatives). I'll call it,
> say, DeltaList, and I was wondering if this would be a proper "functional"
>
>
>
>
> In: DeltaList[L_] := Subtract @@@ Reverse /@ Partition[L, 2, 1]
>
> (DelatList: list -> list)
>

Hi
here is another way

data = RandomReal[{-1, 1}, 100];
DeltaList[data] = Most[RotateLeft[data] - data]

Oliver

>
> Basically, it partitions the list into ordered pairs, reverses those ordered
> pairs to prep them for the subsequent Subtract application.
>