Comments inline, also... On Wed, Mar 21, 2012 at 4:32 AM, Alexander Epifanov <[email protected]> wrote: > Could you please explain the followin thing: > [ns=:?10#1500 > 1225 1362 1263 1376 1445 383 1260 397 175 1188 > NB. I try to find 3digit numbers with unique digits.
Personally, here is how I would do that: ns=:1225 1362 1263 1376 1445 383 1260 397 175 1188 (#~ (3&=@# *. (-: ~.))@":"0) ns 397 175 > I wrote this: > ns#~((((3&=@#) *. (*./@~:))@":)"0) ns That's very similar to what I wrote, so we are thinking in a similar fashion. > I think here are too many brackets, so I removed some > ns#~(((3&=@#*.*./@~:)@":)"0) ns > > Q1: how J understand how to split (xyz) here? How can I parse it in mind? I do not understand this question. What is xyz? Reading Ric Sherlock's post didn't resolve this issue for me, either. > Q2: Why I should write 3&=, but not *.&/ ? 3&= is a function which has the same shape as its argument and which is true for numbers that have the value 3. It's grammatical structure is: noun conjunction verb The conjunction combines the noun and the verb *.&/ is a ... I am not sure what it is without more context. Its structure is: verb conjunction adverb The conjunction combines with the verb to form an adverb, and you wind up with a train of two adverbs (*.&)/ But you typically need a verb before you can use that in a sentence, and you would need to give those adverbs something to work on before they have any chance to turn into a useful verb. > After that I did: > (((3=#*.*./@~:)@":)"0) ns > > Q3: It absolutely not clear for me, how can I write 3=# (explicit) > instead of 3&=@# (tacit)? 3=# is not explicit. Explicit means that you have a direct reference to a variable (by name). None of those symbols are variables. See also http://jsoftware.com/help/learning/09.htm and look for "noun verb verb" Anyways, the part of the above phrase which contains 3 = # parses as: 3 = (# *. *./@~:) The rightmost part of the train parses as a fork before the rest of the train is considered. > It is the main problem in J for me, for example I write expression: > [ns2=:i.10 > 0 1 2 3 4 5 6 7 8 9 > ns2#~-.2|ns2 NB. it looks good, no problem. > > But the problem, if I would like convert it into the function, I > should absolutely rewrite it: > > ns2#~(-.@(2&|))ns2 NB. additional Q: why 2&| in brakets? The brackets are to tell @ that the verb it is operating on is the composite verb that you built. If you left out the () you would have -.@2 and @ does not know how to deal with a noun. You might find a study of the parsing and execution appendix useful, for understanding these grammatical rules: http://www.jsoftware.com/help/dictionary/dicte.htm There's also a trace facility, that presents the same information in a more concrete fashion: require'trace' trace '3 + 10 + 9' (put any expression you want in the string argument to trace). Note that trace does not deal with how composite verbs get executed. I hope this helps. I have not yet read your most recent message in this thread. I will read it next (but have avoided it up to now, to keep my thoughts simple). -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
