1.4 Exercise 4: The fragment system

This exercise is about the fragment system and how it is represented in the Mjolner tool.

1.4.1 Hiding details of your implementation

Load the files loops.bet and useloops.bet in the Mjolner tool.

If you click the '+' next to the 'useloops' icon [505 bytes 17x18 PNG] in the Projects window, you will see that the program INCLUDEs the file 'loops' (symbolized by a single up-arrow: [337 bytes 17x18 PNG]).

Click the line that says [337 bytes 17x18 PNG]loops. We would like to save the do-parts in another file; our implementation file.

While viewing 'loops' choose 'SLOTs->Create Implementation File...' and type loopsbody. Now you have created a new file 'loopsbody' whose ORIGIN is 'loops' (symbolized by a double up-arrow: [339 bytes 17x18 PNG]). Conversely, 'loops' now has BODY 'loopsbody' (symbolized by a down arrow: [346 bytes 17x18 PNG]).

Go back to 'loops' by clicking [339 bytes 17x18 PNG]loops in the Projects window.

Mark the do-part of upTo (press and hold the mouse button from the middle of 'do' to somewhere in the do-part).

[7kb 536x405 PNG]


Choose 'SLOTs->Make DoPart SLOT', and name it upToImplementation. Now the implementation of upTo is automatically moved down into 'loopsbody'.

Double-click <<SLOT upToImplementation: DoPart>> in 'loops'. This takes you directly to the code in 'loopsbody' (or click the Definiton button [421 bytes 32x18 PNG] in the toolbar or press Alt+Right).

The Mjolner tool keeps track of your current implementation file at all times. This is the file into which the implementaion is moved when you choose 'SLOTs->Make DoPart SLOT'. When you use 'SLOTs->Create Implementation File...' to create a new file, that file becomes the current implementation file. If you wish to change it, use the SLOTs menu.

Move the do-parts of downTo and stepTo down into 'loopsbody' as well. This can be done in one step by selecting both downTo and stepTo and choosing 'SLOTs->Hide Implementation'.

1.4.2 Browsing through SLOTs and fragment forms

A SLOT is something of the form <<SLOT blahblah: DoPart>>. The corresponding fragment form contains a line such as ---blahblah: DoPart---.

Using the Mjolner tool you can easily jump from a SLOT to the corresponding fragment form or vice versa.

While viewing 'loops', double-click the stepTo SLOT. This causes the implementation of stepTo to be displayed. In the Fragment Forms window you can see that it contains three do-parts and that currently 'stepToImplementation' is displayed.

Jump to the implementation of downTo by clicking on the corresponding line in the Fragment Forms window. To find the SLOT mathing the 'downTo' fragment form, click the 'ToSlot' button [628 bytes 32x18 PNG] in the toolbar or right click in the Form window and select 'Follow->Link To SLOT'.

[65kb 563x520 PNG]

Now the tool searches through the chain of ORIGINs (adhering to the rules for doing so) looking for a matching SLOT. It ends up finding such a SLOT in 'loops'.

[7kb 436x367 PNG]


Three patterns are defined in 'loops': upTo, downTo and stepTo. To be precise, they are defined in a lib:attributes fragment form. as can be seen in the Fragment Forms window. But which slot will this fragment form be inserted into, i.e. where is the SLOT corresponding to lib:attributes? Find out the same way as above. Of course, the matching SLOT is located in 'betaenv'.


Mjolner Tool Workshop
© 2001-2004 Mjølner Informatics
[Modified: Thursday September 13th 2001 at 18:47]