[Jprogramming] Implementing a tacit "filter" function
Alex Rufon
alex_rufon at ist-systems.com
Wed Aug 25 18:08:31 HKT 2010
When I started using J, I realized that learning J is a paradigm shift.
The simplest way for me to explain this is this way.
For example, you have a table of information and you need find all rows which matches a certain condition. Before I learned to use J, what I would expect is something similar to this SQL DML command:
SELECT * FROM table1 WHERE column1 < 10
In J, I may code it this way:
[data=. (10 $ 3) ? 15
13 0 8
3 7 9
1 8 2
1 4 6
13 8 2
12 0 1
8 14 10
8 7 5
3 11 9
9 10 0
10 > {. "1 data
0 1 1 1 0 0 1 1 1 1
data #~ 10 > {. "1 data
3 7 9
1 8 2
1 4 6
8 14 10
8 7 5
3 11 9
9 10 0
One of the paradigm shifts for me is in knowing that you can get the masking vector (10 > {. "1 data) and you can manipulate it.
You just have to keep using it and asking question and then after a while it would suddenly click into place.
Good luck on your journey. ;)
r/Alex
P.S.
Both my son and daughter are named Alex too. :D
-----Original Message-----
From: programming-bounces at jsoftware.com [mailto:programming-bounces at jsoftware.com] On Behalf Of Alex Gian
Sent: Wednesday, August 25, 2010 5:10 PM
To: Programming forum
Subject: Re: [Jprogramming] Implementing a tacit "filter" function
On Wed, 2010-08-25 at 07:14 +0800, bill lam wrote:
> I guess you think J is a functional language. What if you are told J
> is not a functional language?
Hi Bill!
Thanks, but I want to learn J, not to get into a philosophical dilemma
about "functional languages"... :)
Having said that, my view is that if you've got: 1) nameless functions,
2) can pass functions as arguments and 3) lazy evaluation (which I'm sure is manageable in J - though not often necessary) then you've got a functional language.
The main difference I can now see (with my newbie vision) between J and other FLs is that J does not rely as heavily on recursion, because of its marvellous handling of arrays. This has got to impact on programming _style_ a bit, but even though I am somewhat used to the elegant recursive style, the incredible speed gain you get with J is more than worth it for me.
> There were lengthy discussions on this subject in J forums. Please
> search forum achieve for detail.
I am sure I'll read those discussions at some stage, but first I have to finish Rich's book, then Roger's, the the Dictionary... so loads of reading ahead.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list