I did not use [: before, very interesting. Do I understand correct and @ has "priority" during parsing? that is why (-.@2)&| and not (-.)@(2&|), as I expected.
On Wed, Mar 21, 2012 at 1:20 PM, Ric Sherlock <[email protected]> wrote: > Comments inline: > > On Wed, Mar 21, 2012 at 9:32 PM, Alexander Epifanov <[email protected]> wrote: >> Hello, >> >> 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. >> I wrote this: >> ns#~((((3&=@#) *. (*./@~:))@":)"0) ns >> 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? > > You can simplify this further. I would use white space to help me > parse the sentence more easily (the interpreter doesn't care though) > ns #~ (((3 = #) *. *./@~:)@":)"0 ns > > The following article on the wiki may help with understanding how to > read tacit sentences. > http://www.jsoftware.com/jwiki/Guides/Reading%20Tacit%20Verbs > >> Q2: Why I should write 3&=, but not *.&/ ? > > With 3&= you are binding a noun to a verb to create a new verb. With > *./ the / is an adverb that automatically "binds"/modifies the verb to > its left. > >> 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 = #) *. *./@~:)@":)"0 ns > Note that 3&=@# isn't really tacit in the sense that you aren't using > forks or hooks. However you haven't referred to the arguments because > you were able to create the new verb by combining the noun and verbs > using conjunctions, so in that sense it is tacit. > >> 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? > > You can write this as a tacit function in a number of ways: > (] #~ [: -. 2 | ]) ns2 NB. only forks > (#~ [: -. 2 | ]) ns2 NB. uses hook at end > (#~ [: -. 2&|) ns2 > (#~ 2 -.@| ]) ns2 > (#~ -.@(2&|)) ns2 > > You need the 2&| in brackets otherwise it is evaluated (-.@2)&| > > Any of these functions can be assigned to a name > getEven=: (#~ 2 -.@| ]) > getEven=: #~ 2 -.@| ] NB. the brackets aren't necessary for assignment > > >> @, which is not used in normal expression, that is strange for me that >> expression and function is not the same, K looks more habitually at >> this point: >> expression: ns2:!10; ns2@~ns2!2 >> function: ns2@{~x!2} ns2 / exactly the same like expression. >> >> What is why it is not clear for me why J expression in explicit style >> by default, but function in tacit. >> >> Thank you and sorry if described problem is not very clear. >> -- >> Regards, >> Alexander. >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm -- Regards, Alexander. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
