> On a side note regarding the same subject > > Why didn't Chris use p=: 1 = [EMAIL PROTECTED]: > Which produces the same results. I suppose he was explaining the > use of Forks
"Elegant Programming" was written before the availability of the nvv (noun verb verb) fork. http://keiapl.org/anec/#nvv Having nvv reduces the need for noun"r 1: 2: 3: etc. ----- Original Message ----- From: Ian Gorse <[EMAIL PROTECTED]> Date: Wednesday, September 3, 2008 11:36 Subject: [Jprogramming] simple question regarding 1: To: [email protected] > Hi everyone > > I am currently reading the article "Elegant Programming #~ 1: = [EMAIL > PROTECTED]:" > by Chris Burke and I have come across a snag that I don't quite > understand. > > p=: #~ 1: = [EMAIL PROTECTED]: > > let me slightly rephrase it to explain my problem more clearly > p=: 1:= [EMAIL PROTECTED]: > > This returns 1 if a number is prime otherwise it returns 0. As I was > testing J code to understand why it works, I came across a problem > regarding 1: > > p 3 4 5 6 7 8 > returns 1 0 1 0 1 0 > > ([EMAIL PROTECTED]:) This returns the number of prime factors of the > argument. I > understand that > > The article states the verb 1: returns 1, given any argument, so > how can > p 8 > > return a 0? > > ([EMAIL PROTECTED]:) 8 > 3 > 1: = 3 > 1 > 1: = (([EMAIL PROTECTED]:) 8) > 1 > p 8 > 0 > > > > Edit > After explaining my problem I have solved my answer. I realized > I was > dealing with a fork and in reality J was performing > > (1: = 8) = ( ([EMAIL PROTECTED]:)8 ) > (1) = (3) > 0 > > (1:=5) = ( ([EMAIL PROTECTED]:) 5 ) > (1) = (1) > 1 > > I decided to post to the mailing list anyway to show, that elaborating > a problem can most of the time produce the correct solution :) > > On a side note regarding the same subject > > Why didn't Chris use p=: 1 = [EMAIL PROTECTED]: > Which produces the same results. I suppose he was explaining the > use of Forks ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
