Plot locale

From J Wiki
Jump to navigation Jump to search


<=   =>

Plot also illustrates a common technique in the use of locales. Close J and restart it to get a clean slate. There are no verb names in the base locale, but there are a few other standard locales that are populated by the profile.ijs script.

   names 3	NB. verbs
   names 6	NB. locales
base     j        jcompare jgl2     jp       jqtide   jregex   jrx      jtask    z 


The load verb (defined in the z locale) loads the plot.ijs script into the plot locale.

   load 'plot'
   plot ? 5 $ 100	
   names 3
   names 6
base  j     jcfg  jplot z
   plot
+----------+
|plot_plot_|
+----------+


The verb plot is not defined in the base locale, but is defined in the z locale. When it is executed in the base locale the definition from the z locale is executed as if it were in the base locale. Entering the name plot displays its definition. The interesting thing about the definition of plot is that it executes the plot verb in the plot locale. So the plot in the z locale is a cover that works in all locales and has the result of executing plotin the plotlocale.

This technique of loading a facility like the plot package into its own locale, and then defining cover verbs in the z locale so that plain name references invoke the desired verb in the facility locale is common. The definitions in the plot locale can be viewed as the private implementation of the facility and the names that are exposed by being defined in the z locale are the public or published interface.

<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106