[Jprogramming] Feedback on beginner's code
Henry Rich
henryhrich at gmail.com
Tue Mar 15 01:26:20 UTC 2016
> Again, smaller sub-units help to avoid such accidents:
>
> sort =: /:~
> de_space =: -.&' '
> normalize =: de_space at sort@tolower
> isAnagramOf =: -:&normalize
>
> Almost every time, these tiny sub-units provide something useful even
> beyond of the current context ("anagrams"). They are certainly easier
> to test/verify.
Emphatically agreed. And also take a moment to decide the proper rank for a verb. Here,
isAnagramOf applies only to lists, so define it as
isAnagramOf =: -:&:normalize"1 NB. & would be OK too
de_space might reasonably be rank 1 as well.
>
> It also makes reasoning about the ranks of the components easier.
> In consequence, it becomes easier to make an educated selection
> between @ vs @: or & vs &: -- much better than to stick blindly
> to some mysterious rule of thumb.
I would rather say that the goal is to understand why the rule of thumb is not mysterious.
The first step is to note that there is a difference between & and &:, @ and @:,
and &. and &.: - something many J newcomers pick up late.
Henry Rich
>
> Martin Neitzel
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list