Some examples of the libraries and procedures in the rebottled namespace of r7rs-libs.

(rebottled cl-pdf)

Originally written for Common Lisp by Marc Battyani, this library was then ported to Scheme by Bruce Butterfield.

The library allows us to construct and output PDF documents. The following example displays two repeated blocks of text and a title in a variety of fonts, sizes and positions in the document.

(define (ex1)
  (pdf:with-document-to-file
    "ex1.pdf"
    (let ((helvetica (pdf:build-font "Helvetica"))
          (courier (pdf:build-font "Courier")))
      (pdf:with-page
        (pdf:in-text-mode
          (pdf:set-font (pdf:font-name helvetica) 36)
          (pdf:move-text 100 750)
          (pdf:draw-text "scm-pdf: Example 1"))
        (pdf:in-text-mode
          (dotimes (i 25)
            (pdf:set-font (pdf:font-name helvetica) (* i 1.5))
            (pdf:move-text (+ i 5) (+ i 10))
            (pdf:draw-text "Helvetica")))
        (pdf:in-text-mode
          (dotimes (i 25)
            (pdf:set-font (pdf:font-name courier) (* i 1.5))
            (pdf:move-text (+ i 5) (- 50 (+ i 10)))
            (pdf:draw-text "Courier")))))))

This library needs documentation, and some helper functions to layout larger blocks of text.

(rebottled pstk)

To use the library: (import (rebottled pstk))

The PS/Tk library enables a Scheme program to interact with Tk, to create cross-platform graphical user interfaces. Virtually all of Tcl/Tk is available through Scheme. Other examples of using Tk in this way include LTk from Lisp, Tkinter from Python, Perl/Tk and Ruby/Tk.

PS/Tk must communicate with the separate Tcl/Tk program, a process managed in an implementation-specific manner. The current R7RS version of PS/Tk has support for, and has been tested on, the following:

  • Chibi Scheme: under Linux (calls to "/bin/sh")

  • Gauche Scheme: under Linux (calls to "/bin/sh")

  • Sagittarius Scheme: under Linux and Windows. (Should work on Mac OS too.)

Further Scheme versions or platforms can be added by extending the cond-expand statement in the source code.

For more information:

pstk win

Simple Example

Get started with the following program:

(import (scheme base)
        (scheme write)
        (rebottled pstk))

(let ((tk (tk-start)))                                                  ; 1
  (tk/pack (tk 'create-widget                                           ; 2
               'button 'text: "Hello"
               'command: (lambda () (display "Hello world") (newline))) ; 3
           'padx: 20 'pady: 20)
  (tk-event-loop tk))                                                   ; 4
1 Starts the TK shell working. The returned value is used to interact with the shell.
2 Creates a button with a label and command, and packs it onto the default frame.
3 Commands are given as Scheme functions of zero arguments.
4 Starts the TK event loop.
pstk hello

Working with Widgets

The example above shows how widgets are created by sending instructions to the Tk process. The manner of operation is very close to, but a little different to that used in Tcl/Tk itself. In this section, some descriptions and examples are given to help in translating the Tcl/Tk documentation into Scheme.

In Tk, widgets are created using appropriately named functions, providing a name for the new widget as a string. Tk parses this string to work out the parent widget and provide some structure. In PS/Tk we instead represent widgets as functions; these functions take a command and associated arguments. Commands that the widgets respond to include:

  • get-id: returns the Tk id

  • create-widget: used to create a child widget

  • configure: used to alter parameters of a widget

  • cget: returns value of a configuration option

For example, having created a button, we can later change the displayed text using configure, or retrieve the text using cget:

sash> (hello 'configure 'text: "Goodbye")
()
sash> (hello 'cget 'text:)
"Goodbye"

Apart from representing widgets as functions, most of the Tk parameters and functions map across into Scheme. Consider the Tcl/Tk equivalent of the example program above:

button .hello -text Hello -command {puts stdout "Hello world"}
pack .hello -padx 20 -pady 20

The first line creates a widget named ".hello". The "." means it is attached to the top-most frame. The widget is referred to in the second line, which packs the widget into the frame.

Comparing the second line with the Scheme program illustrates how direct most conversions can be:

pack <widget-name> -padx 20 -pady 20
(tk/pack <widget-value> 'padx: 20 'pady: 20)

Notice these three principles:

  1. Instead of a string for the widget name, we have what is returned by creating the widget (a function); for the top-most frame ("." in tcl/tk) we have the return value of tk-start (called tk here).

  2. The parameters -padx are converted to symbols with a trailing colon 'padx:

  3. The function name pack becomes tk/pack

In addition, Scheme values are converted to Tcl values. So Scheme’s #t/#f are Tcl’s "1"/"0", symbols can be used in place of strings, etc.

Creating a widget is done through the create-widget command mentioned above:

button .hello -text Hello -command {puts stdout "Hello world"}
(define hello
  (tk 'create-widget 'button
      'text: "Hello"
      'command: (lambda () (display "Hello world") (newline))))

Instead of calling a button function, as in Tcl, the parent widget’s function is requested to create a button widget. The parameters defining the button are the same as in the Tcl example, just mapped to Scheme equivalents. This call returns a function defining the new button, which we can name in a Scheme variable.

Notice how the command 'create-widget is passed as a symbol without a trailing colon; compare with how the parameter 'text: is given.

This use of symbols as commands arises elsewhere, for example with winfo:

winfo screenwidth .           # TCL version
(tk/winfo 'screenwidth tk)    ; Scheme version

All the Tk widgets can be created and used in this way. For a list of available widgets see any Tk documentation or https://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm.

Tk Functions

These functions map directly onto underlying Tk functions. The names start tk/ with the remainder of the name mapping onto the Tk equivalent function:

  • tk/bell is equivalent to Tk’s bell

  • tk/choose-color is equivalent to Tk’s tk_chooseColor

tk/after

tk/after takes a time in milliseconds and an optional function. After the given time, it calls the function or continues processing.

In the analogue clock example, the function to redraw the hands in the clock uses tk/after to delay for a second before calling itself to draw the hands in the new position and repeating.

(define (hands canvas)

  ; code to redraw the clock

  (tk/after 1000 (lambda () (hands canvas))))

tk/appname

tk/appname gets or sets the application name.

sash> (tk/appname)
"tclsh"
sash> (tk/appname "new name set")
"new name set"
sash> (tk/appname)
"new name set"

tk/bell

tk/bell rings the bell.

tk/bgerror

tk/bgerror is used to tell the Tcl process that an error has occurred.

tk/bind

tk/bind binds actions to events. For example, a function can be called when a mouse button is clicked, or a key pressed. First argument is a window, or the symbol all; second argument is the pattern for the event to bind to; and third argument is the function to call.

(tk/bind 'all "<Button-1>" `(,(lambda (x) (display x) (newline) #f) %x))

tk/bindtags

tk/bindtags gets or sets the binding tags of a given window.

tk/caret

tk/caret is used to query or set the current caret position in a given window.

sash> (tk/caret tk)                            ; 1
"-height 0 -x 0 -y 0"
sash> (tk/caret tk 'height: 10 'x: 2 'y: 3)    ; 2
""
1 tk refers to the default, or top-most window, as it is the value returned by tk-start.
2 Sets the height or x/y position of the caret in the given window.

tk/choose-color

tk/choose-color opens a dialog from which to select a colour. Returns the RGB code of the selected colour, or "" if cancel is clicked.

sash> (tk/choose-color)
"#7ce679"
color chooser

Optional parameters let you select the initialcolor parent and title. See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/chooseColor.htm

tk/choose-directory

tk/choose-directory opens a dialog from which to select a directory. Returns the directory name as a string or "" if cancel is clicked.

sash> (tk/choose-directory)
"/home/peter/Software/r7rs-libs"
directory chooser

Optional parameters let you select the initialdir parent title and whether the chosen directory must exist. See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/chooseDirectory.htm

tk/clipboard

tk/clipboard provides access to the clipboard, with its parameter specifying an action: append clear get

See Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/clipboard.htm

tk/destroy

tk/destroy deletes the window or windows given as arguments.

tk/event

tk/event is used to create and manage events.

See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/event.htm

tk/focus

tk/focus manages the input focus.

See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/focus.htm

tk/focus-follows-mouse

tk/focus-follows-mouse changes the focus status so it follows the mouse rather than changes with a click.

tk/focus-next

tk/focus-next returns the next window from the given window, in the focus order.

tk/focus-prev

tk/focus-prev returns the previous window from the given window, in the focus order.

tk/get-open-file

tk/get-open-file opens a dialog from which the user can select a file. Returns the file path in a string or "" if cancel is clicked.

sash> (tk/get-open-file)
"/home/peter/Software/r7rs-libs/rebottled-examples/pstk/example-menu.sps"
pstk open file chooser

Optional parameters let you select the initialdir parent title filetypes etc. See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/getOpenFile.htm

tk/get-save-file

tk/get-save-file opens a dialog from which the user can select a file. Returns the file path in a string or "" if cancel is clicked.

sash> (tk/get-save-file)
"/home/peter/Software/r7rs-libs/rebottled-examples/pstk/newfile.txt"
pstk save file chooser

Optional parameters let you select the initialdir parent title filetypes etc. See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/getSaveFile.htm

tk/grab

tk/grab provides a way to redirect mouse or keyboard events to specific windows.

See Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/grab.htm

tk/grid

tk/grid is the first of three techniques used to place widgets within a frame. This geometry manager is probably the most important of the three, and can be used to arrange widgets by row and column.

The following sample, taken from the example "example-temp-conversion.sps" illustrates some of the possibilities:

  (tk/grid celsius 'column: 2 'row: 1 'sticky: 'we 'padx: 5 'pady: 5) ; 1
  (tk/grid label 'column: 2 'row: 2 'sticky: 'we 'padx: 5 'pady: 5)   ; 2
  (tk/grid button 'column: 2 'row: 3 'sticky: 'we 'padx: 5 'pady: 5)
  (tk/grid (tk 'create-widget 'label 'text: "celsius")
	   'column: 3 'row: 1 'sticky: 'w 'padx: 5 'pady: 5)          ; 3
  (tk/grid (tk 'create-widget 'label 'text: "is")
	   'column: 1 'row: 2 'sticky: 'e 'padx: 5 'pady: 5)          ; 4
  (tk/grid (tk 'create-widget 'label 'text: "fahrenheit")
	   'column: 3 'row: 2 'sticky: 'w 'padx: 5 'pady: 5)
1 Places the celsius widget in row 1, column 2. The sticky option means the widget will fill the space in the horizontal direction. The pad options place some space around the widget. Note, rows and columns are indexed from 1.
2 Similarly, the label is placed in column 2 row 2.
3 This option only has w for the sticky option: the text label is left-justified.
4 With the e option for sticky, this label is right-justified.

The final layout is:

pstk temp

For more of the many options, see: https://www.tcl.tk/man/tcl8.6/TkCmd/grid.htm

tk/image

tk/image used to create, delete and query images.

sash> (define im (tk/image 'create 'photo 'file: "doc/pstk-hello.png"))  ; 1
#<unspecified>
sash> (tk/pack (tk 'create-widget 'label 'image: im))                    ; 2
""
1 Loads an image from a file. The type should be photo or bitmap.
2 Puts the image onto a label in the current frame.
pstk image

See the Tk documentation for more details: https://www.tcl.tk/man/tcl8.6/TkCmd/image.htm

tk/lower

tk/lower lowers the given window below all its siblings in the current stacking order.

tk/message-box

tk/message-box displays a Tk message box. These dialogs can be straightforward or display a range of options and an icon.

The simplest information box shows a given message, and adds an "OK" button:

sash> (tk/message-box 'message: "Hello")
"ok"                                        ; 1
1 The function returns the string label of the clicked button.
pstk box1

We can also add a title to the box, and select an icon from one of: (error info question warning) The type of box specifies the buttons. The choices are:

  • "abortretryignore" - which displays three buttons, "abort" "retry" "ignore"

  • "ok" - which displays one button "ok"

  • "okcancel" - which displays two buttons "ok" or "cancel"

  • "retrycancel"

  • "yesno"

  • "yesnocancel"

sash> (tk/message-box 'title: "Error on opening file" 'icon: 'question 'message: "What to do now?" 'type: "abortretryignore")
"ignore"
sash> (tk/message-box 'title: "Error on opening file" 'icon: 'question 'message: "What to do now?" 'type: "abortretryignore")
"abort"
pstk box2

For a full set of options, see the Tk documentation: https://www.tcl.tk/man/tcl8.6/TkCmd/messageBox.htm

tk/option

tk/option is used to add or retrieve window options to or from the option database.

For details see the Tk documentation: https://www.tcl.tk/man/tcl8.6/TkCmd/option.htm

tk/pack

tk/pack is the second of three techniques used to place widgets within a frame.

(tk/pack command ...)

The tk pack command takes a number of options to control the order and spacing of widgets placed within a frame. For the Tk documentation, see: https://www.tcl.tk/man/tcl8.6/TkCmd/pack.htm

tk/place

tk/place is the third of three techniques used to place widgets within a frame. It provides a way to place widgets at specific coordinates. For the Tk documentation, see: https://www.tcl.tk/man/tcl8.6/TkCmd/place.htm

tk/popup

tk/popup takes three arguments, a menu and x/y coordinates. The function pops up a menu at the given position.

tk/raise

tk/raise raises the given window above its siblings in the current stacking order.

tk/scaling

tk/scaling is used to get or set the number of pixels per point on a display. An optional displayof argument is used to specify a window.

sash> (tk/scaling)
"1.3333333333333333"

tk/selection

tk/selection provides access to the X selection (e.g. text highlighted with the mouse).

In the following image, the text "get-save" was highlighted with the mouse, and returned by calling the function with the symbol 'get:

pstk selection

tk/update

tk/update updates any pending events - "Use with extreme care" (Nils Holm)

tk/useinputmethods

tk/useinputmethods is used for XIM filtering. According to the Tcl wiki, this is useful in some locales, such as Japanese or Korean, to use particular input devices. This only works under X.

(tk/useinputmethods ['displayof: window] [boolean])

For querying:

sash> (tk/useinputmethods)
"1"

tk/wait

tk/wait is a general-purpose wait function, where the arguments specify events to wait for. In case of visibility/window types, tk-wait-for-window and tk-wait-until-visible are better choices. This function can also wait for changes to variables.

See the Tk documentation for details: https://www.tcl.tk/man/tcl8.6/TkCmd/tkwait.htm

tk/windowingsystem

tk/windowingsystem returns a string naming the underlying window system.

sash> (tk/windowingsystem)
"x11"

tk/winfo

tk/winfo is used to find out information about windows currently being managed by tk. For example, the screen width and height can be found using:

sash> (tk/winfo 'screenwidth tk)
"1920"                                    ; 1
sash> (tk/winfo 'screenheight tk)
"1080"
1 The values are returned as strings, use string→number to convert to numbers.

Similarly, information about a named window:

sash> (tk/winfo 'x tk)
"860"
sash> (tk/winfo 'y tk)
"464"

There are many kinds of information that may be queried. For a full list, see the Tk documentation: https://www.tcl.tk/man/tcl8.6/TkCmd/winfo.htm

tk/wm

tk/wm is used to communicate with the Window Manager of the operating system. A simple use is to set the title of the top-most window:

  (tk/wm 'title tk "GMT Clock")

More complex uses include fixing a window’s size, specifying an operating-system-specific window type or setting an icon. For the Tk documentation, see: https://www.tcl.tk/man/tcl8.6/TkCmd/wm.htm

ttk/available-themes

ttk/available-themes returns a list of the available themes.

sash> (define tk (tk-start))
#<unspecified>
sash> (ttk/available-themes)
("clam" "alt" "default" "classic")

ttk-map-widgets

Tile is an alternative set of widgets for Tk supporting a more attractive set of themes as well as some additional widgets, such as a treeview.

ttk-map-widgets is used to map native Tk widgets to their TTk equivalents. To use all the Tile widgets, call:

(ttk-map-widgets 'all)

(A value of none will not use any Tile widgets. Alternatively, list the specific widgets you want to map.)

ttk/set-theme

ttk/set-theme is used to set the theme to one of those available.

sash> (ttk/set-theme "classic")
""

ttk/style

ttk/style is used to query or change the Tk style database. For the Tk documentation, see: https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_style.htm

PS/Tk Functions

These functions are included within the library but do not have direct Tk equivalents. (The function names start "tk-".)

tk-end

tk-end is used to shutdown the Tk process, and effectively end the program.

(tk-end)

tk-eval

tk-eval evaluates a piece of TCL code, provided as a string.

sash> (tk-eval "bell")
""
sash> (tk-eval "puts 3")

An error occurred inside Tcl/Tk
 --> 3
#<unspecified>

tk-event-loop

tk-event-loop is used to enter the TK event loop. It takes the tk value returned from tk-start as a parameter, and does not end until tk-end is called.

(tk-event-loop tk)

tk-start

tk-start is used to initiate the Tk process. It returns a function used to send commands to Tk. An optional argument names the tcl/tk program to use: on Linux, this program is "tclsh", but for easy distribution, you may wish to use "tclkit".

(let ((tk (tk-start "tclkit"))) ...)  ; 1
1 Starts the Tk program called "tclkit" and stores the result in the tk variable.

tk-var tk-get-var tk-set-var!

These three functions work as a group and deal with how variables are linked to widget controls.

tk-var is used to register a new tk-var with the given symbol name.

tk-get-var is used to retrieve the value of a tk-var

tk-set-var! is used to change the value of a tk-var

For example:

(tk-var 'cb-value)                                    ; 1
(tk 'create-widget 'checkbutton 'text: "Check me"
	       'variable: (tk-var 'cb-value))         ; 2
(display (tk-get-var 'cb-value))                      ; 3
1 Set up symbol cb-value as the name of variable
2 Associates the cb-value variable with the check button
3 Retrieves the cb-value value to display the check button’s state

tk-wait-for-window

tk-wait-for-window waits until the given window is destroyed (such as a dialog being closed).

tk-wait-until-visible

tk-wait-until-visible waits until the given window becomes visible.

tk-with-lock

tk-with-lock is used to protect functions which are working with state in a multi-threaded environment.

(tk 'create-widget 'button
    'command: (lambda ()
                (tk-with-lock
                  (lambda () do-something-critical))))

History

The PSTK library has had a long history in the Scheme community and, in one form or another, is available for many Scheme implementations. The current file includes its history starting from an implementation of Chicken/Tk by Wolf-Dieter Busch from 2004 based on earlier code by Sven Hartrumpf from 1997. Nils Holm made the library portable, and so created PSTK. Ken Dickey created an R6RS version.

Some links to versions for other Scheme implementations and documentation:

(rebottled pstk-plotchart)

To use the library: (import (rebottled pstk) (rebottled pstk-plotchart))

The PlotChart library is part of tklib, a library of additional functions to use with Tk. This library provides access from Scheme to (part of) PlotChart.

Before using this library, you will need to install tklib. On Linux, tklib can be installed through your standard package manager. For example:

sudo apt-get install tklib

Alternatively, download the Tcl sourcecode from a site such as:

and install by running the Tcl script "installer.tcl".

Check your installation by running one of the Tcl example programs.

The Tcl documentation available for plotchart is easily converted into Scheme. The following examples illustrate how to use the library, and more examples (some converted from tklib’s examples) are included with r7rs-lib.

Bar Chart

Bar charts are used to display and compare some measurable quantity of discrete categories of data. One or more series of data may be shown per category, and the series may be shown side-by-side or stacked.

The first example shows a single series of data:

(import (scheme base)
        (rebottled pstk)
        (rebottled pstk-plotchart))

(define tk (tk-start))                                          ; 1
(import-plotchart)                                              ; 2

(define canvas (tk 'create-widget 'canvas
                   'background: 'white
                   'width: 400
                   'height: 400))

(define bar-chart (create-bar-chart canvas                      ; 3
                                    '(Venus Earth Mars Pluto)   ; 4
                                    '(0 6 2)                    ; 5
                                    1))                         ; 6
(bar-chart 'plot 'mydata '(0 1 2 5) 'green)                     ; 7
(bar-chart 'title "Number of Moons")                            ; 8
(bar-chart 'legend 'mydata "Moons")                             ; 9

(tk/pack canvas)

(tk-event-loop tk)
1 Start and use Tk in the usual manner.
2 Plotchart must be imported (this loads the package into Tk).
3 Create a bar chart on a given canvas.
4 Define the x-axis labels.
5 Define the y-axis scale: (minimum maximum label-gap) .
6 Number of series to plot on the bar chart.
7 Add a series of data. mydata is the name assigned to the series. The list of numbers give the column sizes.
8 Set a title to the bar chart.
9 And a label to the named series, to place in the legend.
pstk bar chart 1

As a second example, three series of data are plotted in a stacked arrangement:

(define bar-chart (create-bar-chart canvas
                                    '(Q1 Q2 Q3 Q4)
                                    '(0 30 2)
                                    'stacked))      ; 1
(bar-chart 'plot 'yr2014 '(4 2 3 5) 'green)
(bar-chart 'plot 'yr2015 '(7 6 3 8) 'red)
(bar-chart 'plot 'yr2016 '(6 4 7 9) 'blue)          ; 2
(bar-chart 'title "Quarterly Sales")
(bar-chart 'legend 'yr2014 "2014")
(bar-chart 'legend 'yr2015 "2015")
(bar-chart 'legend 'yr2016 "2016")                  ; 3
1 stacked is used instead of a count of the number of series.
2 Data are given for each series separately.
3 Similarly, a separate identifier is given for the legend.
pstk bar chart 2

Pie Chart

Pie charts represent a set of values as proportions of a disk.

(define pie-chart (create-pie-chart canvas))
(pie-chart 'plot '("Earth" 1 "Mars" 2 "Jupiter" 53                    ; 1
                   "Saturn" 53 "Uranus" 27 "Neptune" 13  "Pluto" 5))
(pie-chart 'title "Number of Moons")
1 Data are given in a list where alternate values give the label and count.
pstk pie chart

XY Plot

An xy-plot is used to display various kinds of data in a 2D arrangement.

The first example plots two simple functions:

(import (scheme base)
        (rebottled pstk)
        (rebottled pstk-plotchart))

(define tk (tk-start))
(import-plotchart)

(define canvas (tk 'create-widget 'canvas
                   'background: 'white
                   'width: 400
                   'height: 400))

(define graph (create-xy-plot canvas            ; 1
                              '(-10 10 2)
                              '(-100 100 20)))
;; label the graph and axes
(graph 'title "Two Functions")
(graph 'xtext "input x")
(graph 'ytext "output y")
;; colour the two lines
(graph 'dataconfig "square" 'colour: 'blue)
(graph 'dataconfig "cube" 'colour: 'green)
;; line labels in the legend
(graph 'legendconfig 'position: 'bottom-right)  ; 2
(graph 'legend "square" "x*x")                  ; 3
(graph 'legend "cube" "x*x*x")
;; add data
(do ((i -10 (+ i 0.1)))
  ((> i 10) )
  (graph 'plot "square" i (square i))           ; 4
  (graph 'plot "cube" i (* i i i)))

(tk/pack canvas)

(tk-event-loop tk)
1 When creating the xy-plot, the ranges and tick spacing of the x and y axes are defined.
2 Sets the position of the legend: this must be done first
3 Sets the text to use for the legend for this series.
4 (x y) values are plotted in turn for each series.
pstk xy plot 1

The second example illustrates a scatter plot with a trend line:

(define tk (tk-start))
(import-plotchart)

(define canvas (tk 'create-widget 'canvas
                   'background: 'white
                   'width: 400
                   'height: 400))

(define graph (create-xy-plot canvas
                              '(0 20000 4000)
                              '(0 100 20)))
;; label the graph and axes
(graph 'title "Crater Diameter vs Depth")
(graph 'xtext "Depth (feet)")
(graph 'ytext "Diameter (miles)")
;;
(graph 'dataconfig "values" 'type: 'symbol 'symbol: 'upfilled 'colour: "blue")  ; 1
(graph 'dataconfig "relation" 'colour: "green")
;; add data
(for-each (lambda (pair)
            (graph 'plot "values" (car pair) (cdr pair))
            (graph 'trend "relation" (car pair) (cdr pair)))                    ; 2
          '((14500 . 81) (2000 . 2) (10500 . 73) (7000 . 51) (16000 . 77)))

(tk/pack canvas)

;; finally save the plot
(graph 'saveplot "craters.ps")                                                   ; 3

(tk-event-loop tk)
1 The type can be line symbol or none for lines/symbols/nothing to be drawn for the series.
2 The trend command records the datavalues and draws a line indicating the 'trend' of the data.
3 A copy of any plot can be saved as a postscript file, but call this after the canvas has been packed.
pstk xy plot 2