From J Wiki
Jump to: navigation, search

bowling scores, terseness as an aid to understanding, check-digits, K, Arthur Whitney, Sapir-Whorf, how notation and language affect thought, SIGAPL.

Location::Heartland, NYC

Meeting Summary

Agenda for NYCJUG of 20090512

1. Beginner's regatta: using J code for ideas on how to write a program in
another language: see "BowlingVectors.pdf".

2. Show-and-tell: see "CheckDigitSpecAndCode.pdf".

3. Advanced topics: Queue magazine interview with Arthur Whitney; see
"QueueConversationwithArthurWhitney_p12-interview.pdf" and

4. Learning, teaching and promoting J: BAPLA09 - what to say about J?
See also "IgniteIVNYCCallforSpeakers.pdf" and "ImagineScienceFilmFestivalRFS.pdf".


We discussed the contrast between a three-line J solution and a twenty-some page elaboration of Ruby code to do the same thing. This led to speculation about the pros and cons of terse versus verbose notations.

We then looked at successful introduction of J in a small way into a work environment to someone uninterested in the language but appreciative of the results. This success suggests an approach to elucidating algorithms with J while shielding a novice from its unusualness.

Our discussion of the Queue magazine interview with Arthur Whitney, and the perusal of "Reddit" comments on the article, opened up a number of fruitful topics. Some of these led to reflections on what drives contemporary software methodologies and how this differs from an APL/J/K philosophy that embraces understanding. We also discussed some of Arthur's remark in light of the Sapir-Whorf hypothesis that language shapes thinking.

Finally, we heard a lament on the state of SIGAPL and talked about what the J community has to say to a more traditional APL community.

Beginner's regatta

There was an interesting piece on the web - - in which the author Ron Jeffries used a piece of J code as the starting point for demonstrating how to develop code using "Test-Driven Development" techniques. Part of what was interesting is that the author admits he didn't really understand the J code but still used it to guide his own Ruby code.

The start of his article (complete version File:BowlingVectors.pdf) goes like this:

An Idea from June Kim, in J Language

June Kim recently posted some examples of the bowling game implemented in J language, which is a derivative of APL, with the added advantage that it can actually be typed in and displayed. The examples are probably clear to someone who knows J or APL, but are pretty cryptic to the likes of me. I’m looking at the J documentation and may bring down a version to play with. Meanwhile, my limited understanding of June’s examples suggest a solution that I’ve decided to try in Ruby.

For your amusement, here is an example, from Henry Rich, that June presented:

NB. Index of each ball that starts a frame
framex =: 10 {. 0 {~^:a:~  _1 _1  ,~  i.@# > :@:+  10&~:
NB. Score for each ball, assuming that ball starts a frame
scoreifframe =: 3   +^:(9<])`+/@|.\   ,&0
NB. Pick the balls that actually start frames & add em up
gamescore =: [: +/ framex { scoreifframe

NB. means a comment: I know that much J already. The comments give us a hint on a possible implementation.

One of the many interesting things about this is that the J, as shown, has a typo which renders it inoperable - can you see what it is (answer here)? I found it by starting to enter successively smaller pieces of the line in error until I simply noticed the problem.

Tracy Harms has compiled several examples of J solutions to this problem here.


I presented some recent work in which I gave some J code to a colleague to help her test the correctness of an algorithm being implemented by developers where I work. The fairly simple algorithm is outlined, with examples, on pages five and six of this reference: . See the J code below for an explanation of the algorithm, or take a look at the specification and the code File:CheckDigitSpecAndCode.pdf.

An important part of what I provided my colleague was ammunition to demonstrate the intermediate results of this calculation to illustrate the correctness of each step. As part of this effort, I broke my J code into a small vocabulary of cover functions with descriptive names, as shown here:

NB. Define utilities (cover-fns):
cvt2Nums=: 13 : 'ALP0 i. y onlyNumUClets ALP0'    NB. Convert characters to numbers
doubleAlt=: (]* 1 2 $~#)                     NB. Double every other number
mod=: modulus=: |
onlyNumUClets=: (13 : 'x#~y e.~toupper x')   NB. Only allowable characters
singleDigit=: 13 : ';(10 #.^:_1])&.>y'       NB. Break number into digits

NB. Define main verb:
calcCheckDigit=: 13 : '10|-+/singleDigit doubleAlt ALP0 i. y onlyNumUClets ALP0'
NB.EG 3 -: calcCheckDigit 'RM052007USD403P6'

This final, single-line definition might be a bit much for a non-J person to understand, so I further provided a function to show each step of the algorithm:

showDerivation=: 3 : 0
   y=. y onlyNumUClets ALP0
   smoutput '   stp1=. cvt2Nums ''',y,''''
   smoutput stp1=. cvt2Nums y
   smoutput '   stp2=. doubleAlt stp1'
   smoutput stp2=. doubleAlt stp1
   smoutput '   stp3=. singleDigit stp2'
   smoutput stp3=. singleDigit stp2
   smoutput '   stp4=. sum ',":stp3
   smoutput stp4=. +/stp3
   smoutput '   stp5=. 10 mod ',":stp4
   smoutput stp5=. 10|stp4
   smoutput '   if(0=',(":stp5),',0,10-',(":stp5),')'
   smoutput 10|-stp5

So, running this with a worked-out example from the specification demonstrates each step and the expected result:

   showDerivation '392690 QT'  NB. Example from specification
   stp1=. cvt2Nums '392690QT'
3 9 2 6 9 0 26 29
   stp2=. doubleAlt stp1
3 18 2 12 9 0 26 58
   stp3=. singleDigit stp2
3 1 8 2 1 2 9 0 2 6 5 8
   stp4=. sum 3 1 8 2 1 2 9 0 2 6 5 8
   stp5=. 10 mod 47

Advanced topics

We discussed [[File:i> magazine]]. Of particular interest were his comments about how he likes to periodically throw away his old code and re-write a system from scratch - a notion completely antithetical to consensus wisdom. However, it becomes more feasible with a codebase of a manageabley small size, perhaps due to coding in a terse language, and more attractive if one is familiar with old, accreted monstrosities of code that are "caverns measureless to man", unknowable and unchangeable by any individual or team.

There were also File:RedditCommentsOnArthurWhitneyInterview.pdf that should be kept in mind and addressed appropriately.

Learning and teaching J

We looked at some possible venues for promoting J outside of our own small world: File:IgniteIVNYCCallforSpeakers.pdf and, in other media, File:ImagineScienceFilmFestivalRFS.pdf.

Answer to "Typo in Example"

The line

framex =: 10 {. 0 {~^:a:~  _1 _1  ,~  i.@# > :@:+  10&~:

has a spurious space breaking apart >: into two separate characters.

Scan of Meeting Notes

NYCJUGMeetingNotes090512 50.jpg NYCJUGMeetingNotes090512 J 50.jpg