> I am unable to come up with a really good example right now, though.
Does http://www.jsoftware.com/jwiki/Essays/FFT
fit the bill?
My own latest version looks as follows. The main changes
are renaming "floop" to "butterfly" and swapping the
arguments to it. I am curious how other languages solve
this problem because it involves working with n-dimensional
arrays where n can be 20 or 25 or ...
BTW, this example shows that the designers of J messed
up the definition of ,: on atoms, for otherwise we could have
used ,:"r instead of ,&,:"r .
cube =: ($~ q:@#) :. ,
roots =: _1 ^ i. % ]
butterfly =: 4 : 'for_r. i.#$y do. (x=.{."1 x) ] y=.(+/y) ,&,:"r x*-/y end.'
FFT =: ( roots@-:@# butterfly&.cube ]) f. :. iFFT
iFFT =: (# %~ +@roots@-:@# butterfly&.cube ]) f. :. FFT
extend =: >.&.(2&^.)@<:@+&# {."1 ,:
ptimesj =: *&.FFT/ @ extend
----- Original Message -----
From: Boyko Bantchev <[email protected]>
Date: Tuesday, August 9, 2011 12:21
Subject: Re: [Jprogramming] Materials for NYCJUG meeting today - Tuesday 8/9 at
Empire State Building
To: Programming forum <[email protected]>
> On 9 August 2011 18:54, Devon McCormick <[email protected]> wrote:
> > ..............
> > way to avoid looping by using arrays rather than recursion
> which seems to be
> > a common iteration method in functional languages. Ideally,
> I'd like an
> > example where I can show both an array-based solution and
> work in some of
> > J's iterative methods as well - things like scan and the power
> conjunction.
> Since the audience is functional programmers, I guess stressing on
> arrays as contrasted to linked lists would be a very good idea.
>
> Modern functional languages have many features in common with J.
> One is easy formation of function-valued expressions (through not
> only lambdas, but also composition, partial application, etc).
> They also offer much to aid the programmer in avoiding explicit
> recursion through the use of map, filter, folds, zips, etc.
>
> Still, J has a clear advantage over most functional languages by
> its basic data sructure being a random-access array rather than a
> linked -- and therefore unidirectional -- list. Linked
> lists may
> be awkward when speed is important, and do not easily lend themselves
> to parallel processing. (I personally believe that relying so
> heavily on linked lists in those languages is a mistake, a legacy
> from Lisp that they should have got rid of long ago.)
>
> So, I would guess that a functional programmer would be interested,
> on the one hand, in seeing how certain things are done in J
> similarly to what they already know and practice in their languages.
> This, on the other hand, is a good starting point for also showing
> significant differences, such as: arrays vs. lists; map being
> implicit and rank-dependent, etc.
>
> I am unable to come up with a really good example right now, though.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm