NYCJUG/2013-04-09

From J Wiki
Jump to navigation Jump to search

multi-dimensional arrays, Bezier, SVG, functional programming, Qt GUI, language, nouns, verbs, OOP, Object-Oriented Programming


Location::

Meeting Agenda for NYCJUG 20130409

1. Beginner's regatta: some simple exercises: see "Poor Mans Diff - Practical
MultiD arrays.doc".


2. Show-and-tell: using SVG to create interactive web animations: see "animated-
bezierJS.doc".


3. Advanced topics: some functional extensions to J: see "Jprogramming-Functional
Extensions.doc".

Advances in J GUI-building: see "Qt Implementation of wd.doc".


4. Learning, teaching and promoting J, et al.: language learning - see "Nouns
before verbs.doc".

Example of an introductory J text: see (first few pages of) "Chapter 1 of the
Stokes book on learning J.doc".

OOP considered BS: see "All evidence points to OOP being bullshit.doc".

Proceedings

Beginner's Regatta

Poor Man’s “Diff”

Here’s an example of using J to illuminate the differences between two different versions of a file. In this case, we’re looking at the J code to play Nurikabe, both before and after a fix to correct a defect in ending the game correctly.

  ...
Downloading games/nurikabe...
Installing games/nurikabe...
Done.
All available packages are installed and up to date.

   'f0 f1'=. (<;._2)&.>fread&.>(<'c:/Program Files (x86)/j64-801/addons/games/nurikabe/nurikabe'),&.>('0';''),&.><'.ijs'
   #&>f0;<f1
939 939
   f0-.f1
+---------------+-------------------+-----------------------+...
|if. -.DONE do. |formx=. wdqformx'' |gx=. wdqchildxywhx 'g' |...
+---------------+-------------------+-----------------------+...
...-------------------------+------------------------------------+...
...del=. 1 + siz - _2 {. gx |wd 'set g wh ',": _2{. gx + 0 0,del |...
...-------------------------+------------------------------------+...
...-------------------------------+
...wd 'pmovex ',":formx + 0 0,del |
...-------------------------------+
   ;LF,~&.>f0-.f1             NB. Lines in old, not new
if. -.DONE do.
formx=. wdqformx''
gx=. wdqchildxywhx 'g'
del=. 1 + siz - _2 {. gx
wd 'set g wh ',": _2{. gx + 0 0,del
wd 'pmovex ',":formx + 0 0,del

   ;LF,~&.>f0-.~f1            NB. Lines in new, not old
if. 0=DONE do.
formx=. wdqform''
gx=. wdqchildxywh 'g'
wd 'set g wh ',": siz
NB. del=. 1 + siz - _2 {. gx
NB. wd 'pmove ',":formx + 0 0,del

   (>(<CRLF)-.~&.>f0-.f1);<>(<CRLF)-.~&.>f0-.~f1  NB. Side-by-side comparison
+-----------------------------------+---------------------------------+
|if. -.DONE do.                     |if. 0=DONE do.                   |
|formx=. wdqformx''                 |formx=. wdqform''                |
|gx=. wdqchildxywhx 'g'             |gx=. wdqchildxywh 'g'            |
|del=. 1 + siz - _2 {. gx           |wd 'set g wh ',": siz            |
|wd 'set g wh ',": _2{. gx + 0 0,del|NB. del=. 1 + siz - _2 {. gx     |
|wd 'pmovex ',":formx + 0 0,del     |NB. wd 'pmove ',":formx + 0 0,del|
+-----------------------------------+---------------------------------+

A Practical Use of Multi-dimensional Arrays

Here’s an example of assembling a multi-dimensional array to copy three directories to three drives, each with two sub-directories, each with two versions of the destination package to be updated. We start by templating the copy command we’ll be using with the sources.

   srcs=. (<'C:\Clarifi\'),&.>'tseries';'zoo';'quadprog'
   >egcmds=. (<'xcopy '),&.>srcs,&.><' {dest} /S /C /H /I /R /Q /Y'
xcopy C:\Clarifi\tseries {dest} /S /C /H /I /R /Q /Y
xcopy C:\Clarifi\zoo {dest} /S /C /H /I /R /Q /Y
xcopy C:\Clarifi\quadprog {dest} /S /C /H /I /R /Q /Y

We continue by assembling the orthogonal concatentation of drive letters by sub-directories, by destination versions.

   #dests=. 'TUV',&.>/(<':\Clarifi\'),&.>('Modelstation';'Node'),&.>/(<'\res\R\'),&.>/('R-2.8.0';'R-2.12.2'),&.><'\library\'
3 2 2       NB. 3 drives by 2 sub-directories by 2 versions
   >,dests  NB. Make sure they look right…
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\
T:\Clarifi\Modelstation\res\R\R-2.12.2\library\
T:\Clarifi\Node\res\R\R-2.8.0\library\
T:\Clarifi\Node\res\R\R-2.12.2\library\
U:\Clarifi\Modelstation\res\R\R-2.8.0\library\
U:\Clarifi\Modelstation\res\R\R-2.12.2\library\
...

Now concatenate the three destinations libraries onto each of the destinations root directories:

   libs=. 'tseries';'zoo';'quadprog'
   $dests,&.>/libs
3 2 2 3     NB. 3 drives by 2 sub-dirs by 2 versions by 3 libraries

Check that these look as expected:

   >,dests,&.>/libs
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\tseries
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\zoo
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\quadprog
T:\Clarifi\Modelstation\res\R\R-2.12.2\library\tseries
T:\Clarifi\Modelstation\res\R\R-2.12.2\library\zoo
...
V:\Clarifi\Node\res\R\R-2.8.0\library\quadprog
V:\Clarifi\Node\res\R\R-2.12.2\library\tseries
V:\Clarifi\Node\res\R\R-2.12.2\library\zoo
V:\Clarifi\Node\res\R\R-2.12.2\library\quadprog

Line up multiple repetitions of the source libraries with the appropriate destination libraries:

   srcs
+------------------+--------------+-------------------+
|C:\Clarifi\tseries|C:\Clarifi\zoo|C:\Clarifi\quadprog|
+------------------+--------------+-------------------+
   $dests=. dests,&.>/libs
3 2 2 3
   $,/dests
6 2 3

Collapse along the leading dimensions to get a shape to which we can sensibly map the three libraries.

   $,/,/dests
12 3
   >0{,/,/dests
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\tseries
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\zoo
T:\Clarifi\Modelstation\res\R\R-2.8.0\library\quadprog
   $12#(<'xcopy '),&.>srcs,&.>' '
36

Check a couple of attempts to align sources and destinations properly before we commit to creating the final set of commands.

   >5{.(12#(<'xcopy '),&.>srcs,&.>' '),&.>,dests
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.8.0\library\tseries
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.8.0\library\zoo
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.8.0\library\quadprog
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.12.2\library\tseries
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.12.2\library\zoo

This is not correct – think more carefully about how we align three items to three columns.

   >5{.(,12 3$(<'xcopy '),&.>srcs,&.>' '),&.>,dests
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.8.0\library\tseries
xcopy C:\Clarifi\zoo T:\Clarifi\Modelstation\res\R\R-2.8.0\library\zoo
xcopy C:\Clarifi\quadprog T:\Clarifi\Modelstation\res\R\R-2.8.0\library\quadprog
xcopy C:\Clarifi\tseries T:\Clarifi\Modelstation\res\R\R-2.12.2\library\tseries
xcopy C:\Clarifi\zoo T:\Clarifi\Modelstation\res\R\R-2.12.2\library\zoo
   $ cmds=. (,12 3$(<'xcopy '),&.>srcs,&.>' '),&.>,dests
36
   >_2{.cmds=. cmds,&.><' /S /C /H /I /R /Q /Y'
xcopy C:\Clarifi\quadprog V:\Clarifi\Node\res\R\R-2.8.0\library\quadprog /S /C /H /I /R /Q /Y
xcopy C:\Clarifi\tseries V:\Clarifi\Node\res\R\R-2.12.2\library\tseries /S /C /H /I /R /Q /Y

   6!:2 'rr=. shell&.>cmds'
253.621

Show-and-tell

Advanced topics

Learning, teaching and promoting J

Materials

-- Devon McCormick <<DateTime(2013-10-16T03:06:13-0200)>>