User:Ian Clark/BUZZ/FirstSteps

From J Wiki
Jump to: navigation, search

BUZZ: First Steps

1. Check bzi works

<...a list of sample commands -not all of them work!>


bzi_z_ is created by buzz\bzz.ijs

It is a command-line "keyhole" to control the BUZZ bus.

The basic bus code resides in the 2 locales: bz, bxt

  • bz -- bus functionality, including bzi interpretation and duty_cycle
  • bxt -- bus extension, nouns+verbs shared by bz and kompos

Each kompo has its own locale too.

Kompo is short for "BUZZ bus-enabled component".

Apologies for foisting yet another neologism on the gui community, but all the obvious words are taken up, like widget, gadget, etc.

The first call of bzi loads the bus locales bz, bxt

To do this without outputting the sample commands:


-but this is normally redundant.

In time I shall have a "control panel" kompo: wbz which will communicate with the bus entirely by bzi-commands, removing the need to type bzi-commands.

Note that the first word of a bzi-command is always the command. It is case-sensitive. Only the initial letter is looked-at, so you can shorten it:

   bzi 'Destroy'	NB. equivalent to...

If bzi cannot make sense of the command, it outputs diagnostics (boxed).

2. Start the bus and check the timer works

   bzi _

This starts the bus at top-speed.

You can run it slower, for debugging purposes.

It should also show an indicator window, top-left, with a STOP button.

If you can't see it, refer to OBSERVATION below.



BZRUNNING_z_ is a boolean flag that controls the duty_cycle.

You can stop the bus by:

   BZRUNNING_z_=: 0

-but you would normally do so by:

   bzi _.

-or by pressing the STOP button on the bus indicator kompo: kindbz

Indicator kindbz was vital in the early days when the timer went wild. It doesn't seem so important now, but I still like to see it.

- Make it appear with:

   showkind 1
- Make it disappear with:
   showkind 0
- Toggle it with:
- The same goes for trace messages:
   trace 1
   trace 0
   trace ''

Keep trace on (trace 1) for now.

3. Load a kompo to play with

  bzi 'use kelv'

>>>>> NB <<<<<

If kelv appears off the screen, bring it into view by:

   bzi 'Origin'

-then drag it to where you want.

To stop it going back to where it was, nail it down with:

   bzi 'Locate'

- These commands apply to all kompos.

- I'm using quite a big screen -- a gotcher for someone with a smaller screen.


This creates the following objects in the base locale:

nouns: KELV_00  KELV_01  KELV_02  KELV_03  KELV_04

- The verbs are callbacks, to do something when data is entered into a kompo.

- The nouns are "watched variables" (watchvars, or watchvals). (You can have different names, to suit your app.)
While the bus is running, they will keep step with the kompo display.

4. Set the kompo's title and field-captions

   TITLE=: 'My Title'
   CAPTIONS=: 'alpha' ; 'bravo' ; 'charlie' ; 'delta' ; 'echo'


TITLE and CAPTIONS are "honorary" watchvars. (There will be others: POSN SIZE FONT FONTSIZE ...)

They are common to all kompos, whether they are used or not.

If created in the base locale, they will be seen by all kompos.

But if created in the kompo's own locale, this will override the communal watchvar, to allow individual kompos to have their own titles, etc.

You can see it with TITLE:

   TITLE_kelv_=: 'kelv''s own title'
- but not being a watchvar (watchvars can only reside in: base) it won't show until the kompo is next nudged.

Several things nudge a kompo, but you can force a nudge by:

   bzi 'nudge kelv'

5. Alter a watchvar and see the kompo change

   KELV_00=: 99
   KELV_01=: 22


This only happens when the bus (timer) is running.

Timers are a nuisance and I'd rather do without them.

- J crashes hard on the Mac if the timer is not turned off before quitting.

A timer would not be necessary in either Dyalog APL or APL+Win.

- APL+Win has []WATCHPOINTS and Dyalog has "trigger".

- J has (4!:5), but it has to be called to see what's changed. This is the job of duty_cycle_bz_, which is called repeatedly using a timer.

6. Alter a field in the kompo: kelv and see the watchval change

   KELV_00 ; KELV_01 ; KELV_02 ; KELV_03 ; KELV_04


When a field of kelv has focus, pressing Enter triggers an AKT_ callback.

By default these are setup to issue a prompt such as:

   AKT_KELV_01=:	empty

If you re-enter this line, then Enter goes silent for that field.

But you can also replace 'empty' with your own verb to do something.

The next step illustrates...

7. Run ATEMP: an app using kompo: kelv

This is best done by quitting and restarting J, but should work as-is...

(except I see the indicator doesn't work unless you restart -- a bug)

   bzi 'atemp'

Altering the contents of any field will update the other four fields appropriately.

   open buzz 'atemp'
- You'll see how simple the app is.

It can be run standalone via the J session:

   FAHRENHEIT=: 212.9
   alterF''		NB. needed to adjust the other vars based on FAHRENHEIT

The only thing that resembles "gui code" is the line:

   bzi 'memo 5'
- which loads a "style":
   buzzmemo 5

This style (and the line to insert in the app to load it) is generated by:

   bzi 'Generate'

which the app-builder calls when a satisfactory kompo set-up has been achieved.

- "Memo" numbers are allocated like "temp" numbers: 1+(highest present)


This app has been hacked to allow it to work without the timer running. (More complex apps may not be so lucky to work like this.)

The "hack" is the additional line:

   BZIY=: __

which sets a noun in the stylesheet script which is otherwise defaulted. This starts the bus as if you'd typed:

   bzi __
- ie starting it in "burst mode".

If you remove this line, the bus starts at top speed.

8. ATEMP has a "hidden" watchvar: SPHT (Specific Heat)

   bzi _	NB. start the bus
   bzi 'use kmsg > SPHT'	NB. load another kompo to watch SPHT
   SPHT=: 2
AKT_SPHT=:	empty


AKT_SPHT has not been set up to do anything.

- So although we see it change in kompo: kmsg, it does not change HEAT as a result.

- (Though you would see the right figures if you alter field: MASS in kompo: kelv.)

To make it update correctly we can re-enter the line thus:

AKT_SPHT=:	empty
AKT_SPHT=:	alterM
- because alterM recalculates HEAT as: MASS * SPHT * KELVIN

Now, if you reassign SPHT, you'll see HEAT change in: kelv.

9. Another sample app

   bzi 'asee'

This shows a string both normal and reversed.

- Either windoid can be updated. (Click 'OK' to update it.)

- Two copies of kompo: ksee are loaded. The second is called ksee2.

Simply specifying the name of a given kompo with a trailing number is enough to load an independent copy of that kompo.

   bzi 'aseehex'

This is an elaboration of asee which shows a text file in both clear-text and a standard hex display.

- Choose a new file to display with


BUG on Mac: needs timer turned off to avoid a hard crash.