Build Your First Interactive Program
Building quick and easy interfaces is one of Medley Interlisp's most powerful features. You can always refer to the Interlisp Reference Manual for an exhaustive list of its GUI capabilities. It's time to build our first interactive program—a distress call module for a spaceship.
In this chapter, we'll learn to do the following things in Medley:
Build windows.
Assign variable names to values.
Build menus and buttons.
Attach windows and menus.
Build functions.
Display function outputs in windows.
Connect functions to button clicks.
Medley has predefined formats to follow when you want to create objects like windows and menus.
To create a window, we follow the format: (CREATEW REGION TITLE BORDERSIZE). In the Interlisp Exec, type: (CREATEW NIL "DISPLAY MODULE" 10). You can now click and drag to create a new window with the title DISPLAY MODULE and a border size of 10.
REGION lets us define the position at which the window will appear and its size. When NIL, we can define the region dynamically (by clicking and dragging) like we just did.
Predefined regions are useful when we want to create multiple windows of the same type and size. To create a region, we follow the format: (CREATEREGION LEFT BOTTOM W H) . LEFT and BOTTOM refer to the pixel distance of the region we're defining from the left and bottom edge of the screen. W and H are the width and height of the window. In the Exec, type:
(CREATEW (CREATEREGION 500 500 300 200) "DISPLAY MODULE" 10)
Do you see your window? Play around with the values to get a feel of the pixel density!

Try to create a window with no title and border. Can you make one that looks like a button?
It's quite easy to create different objects in Medley. But ideally, we want a way a to give them short names so we can call them when we want instead of typing out the entire format every time.
(SETQ NAME VALUE) will let us assign values to variable names. VALUE can be a function, a call to create a window, or any snippet of code for which you need a new name. Let's assign a name to our region first. We can use this name to set the region for our window. We'll also give our window a name.
In the Exec, type:
(SETQ window-region (CREATEREGION 500 500 300 200))
Medley is now aware of a new region named window-region. We can use this region for any new window we make.
(SETQ display-window (CREATEW window-region "DISPLAY MODULE" 10))
This creates a new variable display-window which when called will create a new window at the region window-region.
We can open or close this window with
(OPENW display-window)and(CLOSEW display-window).
Menus are windows that can have menu-like items and subitems. A cool way to refactor menus is to create a menu with no title and one item which appears and acts like a button.
Menu creations follow the format:
(CREATE MENU TITLE ← "NAME" ITEMS ← '(ITEM1 ITEM2 ITEM3))
Creating a menu defines a menu object in the background but doesn't create an instance of it on our screen. To do that we can use: (MENU NEWMENU POSITION) where the first MENU tells Medley to create a new menu with the name MENU at POSITION . Example: (MENU button-menu 700 200) . This is just an example and won't work because button-menu hasn't been defined yet.
Similar to MENU, we can also use:
(ATTACHMENU button-menu display 'TOP 'CENTER): Attaches the menubutton-menuto the windowdisplayat the top, centered.(ADDMENU button-menu display): Addsbutton-menuto the bottom-left corner ofdisplay-window.
In your Exec type:
(SETQ button-menu (CREATE MENU ITEMS ← '("NAVIGATION SYSTEM FAILURE")))
This creates a menu called button-menu with no title and one item only.
(ATTACHMENU button-menu display-window 'LEFT 'CENTER)You should see a button-like window appear on the left edge of the windowdisplay-windowwith the text "NAVIGATION SYSTEM FAILED".Right now, the button doesn't do anything. Next, we'll connect a function to the button which can print text to
display-window.

Let's create a list of distress calls we can randomly cycle through each time we press our button! In your Exec, type:
(SETQ distress-calls (LIST
"Help! Nav systems compromised. What is lost will never be found."
"Help! Nav systems compromised. Lethal solar flare imminent."
"Help! Nav systems compromised. Stuck in orbit. Planetfall- ETA: 2 cycles."
"Help! Nav systems compromised. Class 3 Destroyer approaching. Contact- ETA: 6 cycles."
"Help! Nav systems compromised. Direction constant. Speed unknown. Debris field ahead. Contact- High."
))Now, that we have a list named distress-calls , we can set up a function called nav-sys that displays a random message from this list to our display-window . Next, we'll connect this function to our button-menu.
We can define a new function with DEFINEQ . In your Exec, type:
(DEFINEQ (nav-sys ()
(PRIN1 (CAR (NTH distress-calls (RAND 1 (LENGTH distress-calls))))
nav-display)))Let's break down our function:
nav-sys: Name of functionPRIN1: for printing to a specific windowCAR: returns the first element of a list(NTH list number): returns the tail of the specifiedliststarting from the specifiednumber. So, if we have a list(A B C D)and we use(NTH (ABCD) 2), we'll get(B C D)as the output.(RAND value1 value2): returns a random value in a range fromvalue1fromvalue2.(LENGTH list): returns the length of the list.(CAR (NTH distress-calls (RAND 1 (LENGTH distress-calls)))):(RAND 1 (LENGTH distress-calls))returns a random number between 1 and the total length of the listdistress-calls.(NTH distress-callsreturns the tail of the list starting from the element at that random number.(CARreturns the first element of that tail.(PRIN1 ... nav-display)prints that element to thenav-displaywindow, which we will create below.And of course,
(DEFINEQ (nav-sys ()gives the namenav-systo our function. For our current function, we have no use for any parameters, so we use an empty parameter list,().
Let's delete the button we made before with (DELETEMENU button-menu display-window) .
We'll make a new nav-button with our nav-sys function attached!
In your Exec, type:
(SETQ nav-button
(CREATE MENU
ITEMS ← '("NAVIGATION SYSTEM CHECK")
WHENSELECTEDFN ← (FUNCTION nav-sys)
))Our new button has only a minor addition (and a different name).
WHENSELECTEDFN ← (FUNCTION nav-sys) executes the function nav-sys when menu-item (our button nav-button ) is selected.
We'll create a new window called nav-display:
(SETQ nav-display (CREATEW (CREATEREGION 500 500 300 200) "NAV SYSTEM DISPLAY" 10))Let's add our button to our new window next. Type:
(ATTACHMENU nav-button nav-display 'BOTTOM 'CENTER)

Go ahead and interact with your button!

Is your distress call module working?
Last updated
Was this helpful?
