From J Wiki
Jump to: navigation, search

GTK IDE, J labs, formatting text, creating RTF, R example, visualization, synchronous, asynchronous, language survival, translate math into code.

We held our "August" meeting at the end of July to accommodate special guests Eric Iverson and Marshall Lochbaum, fresh from the recent J conference.

Meeting Agenda for NYCJUG 20120731 "August meeting"

1. Beginner's regatta: starting the GTK IDE - see "Looking at the J GTK

Where are the labs?  See "Interesting Things in File Lab.pdf".

2. Show-and-tell: bolding primes - see "Creating Formatted Text.pdf".

3. Advanced topics: example visualization done in R - see "Comparing Mariano
Rivera to other closers using R.pdf".

J for visualization: see "Coding as Performance.pdf".

Synchronous versus asynchronous programming: see "Developer of Node.js.pdf".

4. Learning, teaching and promoting J, et al.: what helps a language survive?
See "Why Visual Basic 6 Still Thrives.pdf"; also "What simplicity means in
different programming languages.pdf".

The difficulty of translating math into code and why this is important: see
"Scientists struggle with mathematical details.pdf".


Beginner's regatta

We examined some of the code comprising J's GTK-based IDE in order to better understand its basic structure.

Looking at the J GTK IDE

Let's see how we start the GTK IDE for J7 (from the jconsole):

   load 'gtkide'

Simple enough – but it locks our console session while we're running it – it needs an event loop.

Where does the code come from and what does it look like? The details of the short-cut for “gtkide” are in the global variable “Public_j_”.

63 2

|afm    |~addons/graphics/afm/afm.ijs      |
|bmp    |~addons/graphics/bmp/bmp.ijs      |

   (0{"1 Public_j_) i. <'gtkide'

   (1{"1 Public_j_) {~ (0{"1 Public_j_) i. <'gtkide'

   jpath '~addons/ide/gtk/gtk.ijs'
c:/program files (x86)/j64-701/addons/ide/gtk/gtk.ijs

   $gtkfl=. fread 'c:/program files (x86)/j64-701/addons/ide/gtk/gtk.ijs'

   LF+/ . = gtkfl           NB. How many lines is this?
   '=:'+/ . E. gtkfl        NB. How many global assignments are there?

So, this is a bit large to cover in one sitting. There really should be a table of contents or some other organizational aid for a script this large. Let’s look only at the first part of this code.

NB. J gtkide
require 'gui/gtk project'

This requirement seems to include this project:

c:/Program Files (x86)/j64-701/addons/gui/gtk:
total used in directory 136 available 52393796
drwxrwxrwx  1 Administrators Domain Users      0 07-26 10:26 config
drwxrwxrwx  1 Administrators Domain Users      0 07-26 10:26 demo
-rw-rw-rw-  1 Administrators Domain Users 130607 06-19 01:30 gtk.ijs
-rw-rw-rw-  1 Administrators Domain Users   2433 06-19 01:30 history.txt
-rw-rw-rw-  1 Administrators Domain Users   4918 06-19 01:30 image.ijs
-rw-rw-rw-  1 Administrators Domain Users    220 06-19 01:30 manifest.ijs
-rw-rw-rw-  1 Administrators Domain Users    245 06-19 01:30 readme.txt

coclass 'jgtkide'
coinsert 'jgtk'

[see the PDF Looking at the J GTK IDE.pdf below for more on this]

Interesting Things in Files Lab

Looking through the J labs on working with files turned up a number of interesting anomalies and useful items.

from:	 adam dunne
to:	 Programming forum <>
date:	 Wed, Jul 25, 2012 at 5:17 AM
subject:	 [Jprogramming] quote bug in J602

in ijx if I enter a single quote nothing happens; on entering a second single quote the response is 2 single quotes. I can't define strings. (This happened after running the files Lab)

from: adam dunne
date: Wed, Jul 25, 2012 at 6:56 AM		

if I enter 'string' it displays nothing until the closing quote, then displays 'string' correctly

from: Tom Arneson
date: Wed, Jul 25, 2012 at 9:38 AM

I just ran the files lab and then defined some strings. It worked as expected. My OS is Win XP.

from: Devon McCormick
date: Wed, Jul 25, 2012 at 10:03 AM

I get odd behavior in my ijx session window starting after the end of chapter 6 or start of chapter 7 of the files lab in 6.02 - after the "prompt" example: the session seems to stop accepting input.

from: Devon McCormick
date: Wed, Jul 25, 2012 at 10:29 AM

I haven't been able to re-produce the odd behavior I reported here. It may have something to do with either 1) testing out the "prompt" verb, or 2) the "fselect jpath '~system\main\files.ijs'" command does not open in the '~system\main' directory and I select some random file where it does open.

These are the two things that happened before my input to the ijx window stopped appearing but I have not been able to re-produce the bug. I'm running under Windows 7.

from: Devon McCormick
date: Wed, Jul 25, 2012 at 10:41 AM

Under Windows 7, there seems to be a bug in J6.02 "fselect": it ignores its argument of a starting path and appears to initially point to the most-recently-opened directory according to the file selection dialog. So, if I run

   fselect 'C:\foodir\foofile.txt'

but, within the file selection dialog, navigate to "C:\bardir\' to select that file, the next time I run

   fselect 'C:\foodir\foofile.txt'

the dialog opens in "C:\bardir".

from: bill lam
date: Wed, Jul 25, 2012 at 10:59 AM

>> Does gtkwd work?

I haven’t answered this because I’m having trouble finding things in J7. One of the interesting things I noticed in the J6 file lab:

For example:

  fread 'labfile.txt';20 50
    reads 50 bytes of the file after skipping the first 20.

And this

-- ((2) 2 of 3) General Rules (ctd) -------------------------
*  `String` verbs, like freads, fappends, and fwrites, convert text strings between Host and J formats. Text strings may be delimited by the CRLF pair, or by isolated CR or LF characters. J text strings are delimited by the LF character alone. When converting J text strings to Host format, the LF characters are replaced by CRLF, CR or LF as appropriate.
*  Filenames conform to the normal rules for the base operating system.
*  Extended filenames found in Windows 9x are supported.  The extended name should not be enclosed in double quotes (").
   NB. Test your system to see what your line separator is.
   'abc' fwrites 'labfile.txt'
   eol=:;('CR';'LF')#~(CR,LF)e.fread 'labfile.txt';_2
   'Your host line separator is ',eol,'.'
Your host line separator is CRLF.

And this

-- ((3) 4 of 9) fread (ctd) ---------------------------------
The 'b' option boxes each line of the file.
   'b' fread (jpath '~system\extras\config\stdcfg.ijs');0 80
|NB. standard configuration||FIXFONTW=: '"Courier New" 12'|PROFONTW=: '"MS San|

-- ((3) 5 of 9) fread (ctd) ---------------------------------
The 'm' option creates a matrix with each line in the file on a separate row. The line separators are removed.
Notice that some lines may be padded with blanks.
   'm' fread (jpath '~system\extras\config\stdcfg.ijs');0 80
NB. standard configuration

FIXFONTW=: '"Courier New" 12'
   $'m' fread (jpath '~system\extras\config\stdcfg.ijs');0 80
4 29


We looked an an example of using J to generate fragments of an RTF file in order to display a structured list of numbers with the primes bolded. See Creating Formatted Text.pdf below.

Advanced topics

We looked at an example of created sophisticated visualizations by sketching ideas by hand, then using the R programming language to create the desired graphics from data. See Comparing Mariano Rivera to other closers using R.pdf below.

We also looked at an interesting blog post about "coding as performance" that mentions J as having "great visualization tools" - see Coding as Performance.pdf below.

Continuing our tradition of considering good and interesting ideas from other languages, we read about the "Node.js" Javascript package that eases the difficulty of adapting to Javascript's asynchronous programming paradigm by forcing it into a synchronous framework. See Developer of Node.js.pdf below.

Learning and Teaching J