Exploring Medley: A Clojure Tutorial on an Interactive Lisp Environment
Table of Contents
Here is a tutorial summary of the Medley user documentation, with some example code snippets in Clojure:
Summary: Medley User Documentation
What is Medley?
Medley is a Lisp-based interactive programming environment and user interface development tool. It includes:
- An implementation of Common Lisp with extensions (Interlisp-D)
- A library of functions and tools for building user interfaces
- Debugging and program analysis capabilities
- Support for multimedia elements like images, animation, sound
Some key capabilities Medley provides:
- Live coding - write and modify Lisp code interactively
- GUI interface construction
- Bitmap/image editing
- Program tracing and inspection
Interactive Coding Workflow
A basic REPL loop allows entering code interactively:
user> (print "Hello world!") Hello world! nil user>
The programmer's assistant provides shortcuts, like re-running previous expressions:
user> (def x 10) #'user/x user> x 10 user> (redo) ;; Last expression is re-run 10
User Interface Construction
Windows can be created programmatically:
(def window (create-window :title "My Window" :width 100 :height 200))
Menus allow building interactive interfaces:
(def menu (create-menu :title "File" :items [["Open" #(do-open)] ["Save" #(do-save)]])) (show-menu menu)
Debugging and Analysis
Errors trigger a debugging prompt:
(defn divide [x y] (/ x y)) (divide 10 0) ;; Triggers error
In the debug REPL, the call stack can be inspected:
user> (bt) ; backtrace (#'user/divide 10 0) (#'user/eval204 10 0) ...
The `spy` library tracks time spent in functions:
(spy/start) ;; Run program (spy/report) ;; Print profiling report
Extensibility
Libraries extend Medley's capabilities, like graphing, GUI layout, etc. User defined initialization scripts customize defaults.
References
Questions
- How extensible is Medley - what languages or libraries can it be connected to?
- How does the performance compare to more modern Lisp implementations?
- What modern features are missing compared to languages like Clojure or Racket?