Skip to content

mumez/smalltalk-dev-plugin-graph-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smalltalk-dev-plugin: Graph and Shortest Path

This repository showcases a project created by smalltalk-dev-plugin — a Claude Code extension for Pharo Smalltalk development.

This is a slightly more advanced example. From a single prompt with basic class hints, Claude Code designed a detailed implementation plan and generated working source code — including Dijkstra's shortest-path algorithm, complete with tests.

You can watch the actual development process in the video below.

Watch the video

Prompt

The following prompt was given to /st:buddy:

/st:buddy I want to create GrNode and GrArc to represent directed graphs
and solve shortest path problems. Nodes have a name, arcs have a score.
Let's start this as a GraphGear project.

Generated Source

The source code is in the src directory. Three packages were generated:

Package Description
BaselineOfGraphGear Metacello baseline configuration
GraphGear Core classes — GrNode, GrArc, GrGraph
GraphGear-Tests SUnit tests — GrNodeTest, GrArcTest, GrGraphTest

Class Overview

  • GrNode — A named node (vertex) in a directed graph. Maintains outgoing arcs.
  • GrArc — A weighted, directed arc (edge) connecting two nodes.
  • GrGraph — A directed weighted graph with Dijkstra's shortest-path algorithm.

Try It in Pharo

If you would like to try the generated source code in a live Pharo environment, you can load the GraphGear project using Metacello:

Metacello new
  baseline: 'GraphGear';
  repository: 'github://mumez/smalltalk-dev-plugin-graph-example:main/src';
  load.

Once loaded, verify that all tests pass:

GrGraphTest suite run. "print it"

Here is a usage example — building a graph and finding the shortest path with Dijkstra's algorithm:

graph := GrGraph new.
graph addNodeNamed: 'A'.
graph addNodeNamed: 'B'.
graph addNodeNamed: 'C'.
graph addNodeNamed: 'D'.
graph addArcFrom: 'A' to: 'B' score: 1.
graph addArcFrom: 'A' to: 'C' score: 4.
graph addArcFrom: 'B' to: 'D' score: 3.
graph addArcFrom: 'C' to: 'D' score: 1.

graph shortestDistanceFrom: 'A' to: 'D'.              "=> 4"
(graph shortestPathFrom: 'A' to: 'D') collect: #name. "=> #('A' 'B' 'D')"
    A ---1--- B
    |         |
    4         3
    |         |
    C ---1--- D

  Shortest path A to D: A -> B -> D (cost 4)
  Not: A -> C -> D (cost 5)

You can browse the GrNode, GrArc, and GrGraph classes in the System Browser. You will notice that CRC-style class comments were also generated along with the source code.

About

Example of smalltalk-dev-plugin: Graph and Shortest Path

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors