Emacs Extensions for
GE Smallworld Magik Development

Screen-casts, tutorials, and productivity tools for Magik programmers who use Emacs. From tab-mode and code folding to the Magik Debugger and object inspector — explore features built by a developer, for developers.

Learn More
HydePark Consulting Screen-casts on YouTube RSS via FeedBurner

Nine screen-casts published between November 2010 and January 2011 — covering everything from ECB mode to the Tree Item GUI control. Read the story behind the project →

Get in Touch

Trace Magik method dispatch with Emacs

Magik’s dynamic dispatch makes method calls look deceptively simple. You ask an object to perform an operation, and the runtime selects an implementation from the receiver’s class hierarchy at execution time. The source line can therefore be correct while the method that actually runs belongs to a subclass or another specialised class.

Tracing Magik’s method dispatch with Emacs’ trace function adds a useful call-and-return view to the editing session. Emacs can show which Lisp function was entered, the arguments it received, and the value it returned. That makes it valuable for inspecting the bridge between an editor command and the Magik process, provided the trace is attached to a deliberately narrow function rather than the entire interpreter.

A typical failure illustrates the value. A request calls calculate_total, but one customer class overrides that method and another inherits a fallback. The debugger shows the call site, not every candidate consulted during resolution. A trace around the submission function can prove that the request was sent once; a Magik tracepoint can identify the implementation that answered it.

For teams in Sydney, Melbourne, Brisbane and Perth, this workflow matters when Smallworld installations support water networks, mining assets or council service registers. Those environments often combine decades of legacy data with newer integrations. Knowing which method ran becomes an operational skill, especially when a change is tested in an office and then deployed to field systems in another state.

Separate the invocation from the implementation

Magik dispatch occurs inside the Smallworld runtime, not inside Emacs Lisp. An editor buffer may show customer.balance, while the process is still loading packages, constructing the receiver, choosing an inherited implementation and converting return values before Emacs receives them. The visible call is only the request; tracing exposes selected events around that request.

Resolution follows the relationships among the receiver’s class and the methods available to it. A more specific override normally wins over a general ancestor method. The same source expression can therefore choose different code for different receiver types, and a change to a shared ancestor can affect several workflows without altering the edited call site.

This distinction is especially useful in Australian utility and local-government projects, where one collection model may serve metropolitan water assets, regional pumping stations and council land records. Teams need a reproducible account of dispatch before changing a method that affects billing, maintenance or spatial data. Recording the receiver, requested operation, selected implementation and result creates that evidence.

Understand the boundary of Emacs tracing

Emacs’ trace function instruments an Emacs Lisp symbol. Using M-x trace and naming a function turns on call tracing; (untrace 'function-name) removes it. Trace output records entry, arguments and return values, while M-x trace-buffer provides a buffer in which the sequence can be reviewed. It is excellent for a bridge function, but it does not inspect classes or perform Magik method lookup.

The simplest adapter can look like this. Replace magik-eval with the evaluation entry point used by your installed MagikEmacs release, since command names differ between configurations.

(defun mgk--invoke (receiver method &rest args)
  "Send one method invocation to the connected Magik process."
  (magik-eval
   (format "%s.%s(%s)"
           receiver method
           (mapconcat #'identity args ", "))))

(trace 'mgk--invoke)

This wrapper creates a precise boundary around one submitted method call. The trace proves which receiver and operation crossed into Magik, how many times the adapter ran, and what value came back. It still cannot, by itself, prove which inherited implementation executed inside the Smallworld runtime.

Where an investigation later moves from a local reproduction to a shared web workflow, the Rootsafe web services resource can be consulted for that wider layer. Keeping publication and hosting concerns outside the trace loop prevents them from distracting the dispatch investigation.

Build a trace around the suspected dispatch

Begin with a hypothesis tied to observable behaviour. If a total is wrong, trace the request that carries the receiver and operation, then compare the entry with the returned value. If the editor appears to freeze, trace the process-submission function and check for repeated calls. A useful trace answers one question, so avoid enabling it on every connection helper.

Pair the Lisp trace with a Magik-side tracepoint when implementation identity matters. The Magik debugger can mark the candidate method and expose the implementation selected by the runtime. That combination separates transport questions from resolution questions: Emacs shows that a call was submitted, while Magik shows which body handled it.

Keep the experiment small. Use one receiver class, one argument set and one representative dataset. Record the Smallworld release, loaded package versions and any recent method redefinition. If nested calls are noisy, use the optional depth argument supported by Emacs’ trace implementation to limit recursion, then inspect the untruncated trace only if the first pass is inconclusive.

Read the trace as a dispatch story

A useful trace reads as a sequence: adapter entered, receiver and method recorded, Magik process called, result returned, adapter exited. Compare that sequence with the object shown in the debugger and the method body reached in the Magik source. A mismatch often reveals that two similarly named methods exist in different packages or that an override delegates to its ancestor.

Several common findings emerge. A repeated entry can expose an accidental retry or recursive call. A missing return can show that the adapter is looking in the wrong place for a value. An unexpected receiver can indicate that a collection returned the wrong object type. Most importantly, a clean adapter trace paired with an unexpected Magik implementation separates an editor or transport problem from a genuine dispatch problem.

Australian engineering teams often keep their language plain in stand-ups: “the method isn’t hitting”, “the subclass is different”, or “let’s trace it”. Translating that direct observation into a traceable sequence is valuable. Capture timestamps, receiver types and package versions so the result can be compared across an office workstation and a production-support session without relying on recollection.

Fit tracing into the Magik editing workflow

A trace becomes much more useful when it sits beside navigation and inspection tools. Install only what the problem needs: the Magik Emacs extensions category includes tools for navigation, object inspection, folding and debugger sessions, so it is a sensible place to check before assembling a custom workflow. Source folding can hide a branch in the buffer, while object inspection can show the receiver whose class makes dispatch surprising.

A practical loop starts at the failing call, marks it in the source, opens the receiver in the object inspector, traces the submission adapter and then switches to the Magik debugger at the selected implementation. Return to Emacs with the result and attach the relevant trace-buffer excerpt to the work notes. This keeps the editor as the control centre while making each runtime boundary explicit.

Distributed support adds one Australian wrinkle: Sydney and Melbourne observe daylight-saving changes, Brisbane remains on AEST, and Perth uses AWST. Store trace timestamps in UTC as well as local time, and include the time-zone label. That small detail prevents a support engineer in Perth from correlating the wrong run with an incident logged in Sydney.

Turn a trace into a repeatable debugging cycle

Finish by turning the observation into a procedure. Save a minimal reproduction, note the expected and actual dispatch paths, and state which hypothesis the trace eliminated. Update the method documentation or test with the receiver class that exposed the issue, not only with the class used by the original example. This turns a one-off debugging session into durable knowledge for the next maintainer.

Remove temporary instrumentation after the evidence is captured. Leaving trace enabled on a shared function can flood the message area, slow the editor and obscure genuine errors. Keep the trace wrapper small, give it a clear purpose and disable it as part of the same test cycle. Sanitise customer names, credentials and other sensitive values before sharing excerpts outside the project team.

Browse the extension category, reproduce one failing dispatch in a trace buffer, and contact HydePark Consulting when you need help adapting the workflow to your Smallworld installation. A focused trace, paired with Magik’s own resolution information, can turn an ambiguous method problem into a change the team can test, deploy and explain.

Core Features

Tab Mode & ECB

Quick tab switching and Emacs Code Browsing mode for navigating Magik codebases efficiently.

Magik Smeller

Code analysis tool that helps identify potential issues in Magik source files.

Code Folding

Hide/Show mode for collapsing and expanding Magik code blocks to focus on what matters.

Visual Bookmarks

Quick visual bookmarks for jumping between key locations in your Smallworld session buffers.

Object Inspector

Inspect Magik objects and display them in an Emacs Deep Print buffer for detailed examination.

Magik Debugger

Set breakpoints and monitor slots and variables directly from within Emacs.

Development Tools

Direct links between Emacs and the Smallworld Development Tools application, including Click Monitor.

Screen-casts & Tutorials

Dark code editor window with syntax-highlighted Magik source code in muted blues and greys, conveying a focused development environment

Screen-cast 1: Tab Mode, ECB & More

Covers tab-mode, ECB, Magik Smeller, code folding, visual bookmarks, pragma toggling, moving code, external editor, and MS Explorer.

November 7, 2010
Split-pane Emacs interface with multiple buffers open, warm amber and navy tones against a dark background

Screen-cast 5: Object Inspection & Deep Print

Inspect a Magik object, prompt for an expression evaluated within a Smallworld session, and display results in a Deep Print buffer.

January 16, 2011
Debugging interface with breakpoint markers and variable watch panels in subdued teal and charcoal tones

Screen-cast 7: Magik Debugger

Useful tools for application developers: Object Inspector and Magik Debugger with breakpoints and slot/variable monitoring.

January 2011
Tree control GUI element with expandable branches rendered in clean greys and muted blues on a light background

Screen-cast 9: Tree Item GUI Control

Tree Item is a GUI control providing extensive facilities for displaying lists with rows, columns, trees, and in-place editing.

January 20, 2011