1. If you knew that ;: could be used to split the words (e.g. no quotes in the text), then using an inverse simplifies the code:
trimmer=: 3 : 0 y #~ 1 (0 _1)} -. y e. 'AEIOUaeiou' ) tweeter=: trimmer each &. ;: tweeter 'In what cases can J find the inverse of a verb' In wht css cn J fnd the invrse of a vrb 2. Otherwise, it is easiest to program without an inverse: trimmer=: 3 : 0 < ' ',y #~ 1 (0 _1)} -. y e. 'AEIOUaeiou' ) tweeter=: 3 : 0 }.; trimmer;._1 ' ',y ) tweeter 'After a few months off I''m back working through some problems' Aftr a fw mnths off I'm bck wrkng thrgh sme prblms 3. if you really want to use an inverse, then perhaps: trimmer=: 3 : 0 ' ',y #~ 1 (0 _1)} -. y e. 'AEIOUaeiou' ) splitter=: ([: <;._1 ' ',]) :. (}.@;) tweeter=: trimmer each &. splitter tweeter 'After a few months off I''m back working through some problems' Aftr a fw mnths off I'm bck wrkng thrgh sme prblms On Fri, Dec 30, 2016 at 6:08 AM, Adam Tornhill <[email protected]> wrote: > After a few months off I'm back working through some problems in the > Daylog APL challenge as a way of learning J. One problem is to shorten a > message yet retain most readability by removing interior vowels from words. > Here's my rather verbose solution to this problem: > splitToWords =: ' ' & splitstringjoinWords =: ' ' & joinstringtrimVowel =: > -. & 'AEIOUaeiou'innerPart =: }. @: }:trimInnerVowels =: {. , (trimVowel @: > innerPart) , {:trimmable =: (> &2) @: #trimWord =: ] ` trimInnerVowels @. > trimmable > makeTweetable =: joinWords @: (trimWord &. >) @: splitToWords > > The verb joinWords is, semantically, the inverse of splitToWords and I'd > like to express that in my solution. I know that J can automatically find > the inverse of some user defined verbs. However, in this case it fails: > joinWords =: splitToWords ^: _1 > t┌─┬──┬──┬─────┐│i│am│so│happy│└─┴──┴──┴─────┘ joinWords t|domain > error: joinWords > My guess is that there isn't a deductible relationship between the script > functions I use, but I'd love to understand how function inverse really > works. In particular I'd like to learn more about: > 1. In what cases can J find the inverse of a verb?2. Is there any way for > me, as a user, to specify or declare an inverse to a specific verb? > I'm also pretty sure that my solution above can be simplified a lot. I'd > be happy for any feedback on the code. > Thanks in advance! > -- Homepage: www.adamtornhill.com Twitter: @AdamTornhill > The History of your Code will decide its Future: https://codescene.io/Your > Code as a Crime Scene: https://pragprog.com/book/ > atcrime/your-code-as-a-crime-sceneLisp for the Web: https://leanpub.com/ > lispwebPatterns in C: https://leanpub.com/patternsinc > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
