Bo Jacoby <[email protected]> wrote:
> How to de-smell this:
> 3([* i.@#@,@[ ^/ i.@>:@])~ 0 0 1 1 1
3 (]* ((^/&i. >:)~ #)) 0 0 1 1 1
Maybe? That comes from just a little mechanical algebra:
> 3([* i.@#@,@[ ^/ i.@>:@])~ 0 0 1 1 1
First notice the repeated (i.) on either argument of (^/). There is a general
pattern, (f@u v f@w <--> u v&f w), which in this case specializes to
3([* #@,@[ ^/&i. >:@])~ 0 0 1 1 1
Then, at least in this example the (@,) is superfluous, so we elide it:
3([* #@[ ^/&i. >:@])~ 0 0 1 1 1
Finally, here is an idiom: ( (u@[ v w@]) <--> ((v w)~ u)~ ), and since
(x v~~ y <--> x v y), we have
3 (]* ((^/&i. >:)~ #)) 0 0 1 1 1
The last idiom is really a matter of preference. I like the bare verbs, but
code golf-wise it doesn't win.
More importantly, however, I really have no idea what you are trying to
accomplish. The above just performs some J syntax manipulations; however, this
doesn't at all demonstrate the main point of avoiding code smell as I see it,
which is more about finding places to improve the *algorithm* rather than only
cleaning up the syntax.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm