Replies: 2 comments
-
|
Hey there,
I value modularity & extensibility, which is why Mangle is designed to be an embedded into a host system. That should in principle make tooling easier. So I would support the idea of Mangle tools in general and UI in particular. It seems a few things that are needed by the core language implementation:
Then there are things that can be done outside the implementation, e.g. system components like a Mangle GRPC service (like this one here https://github.com/burakemir/mangle-service ...) which could hold rules, metadata and offer a port be UI tooling. In my view, modularity and extensibility would favor an approach where there are clear, stable interfaces, that could then be used to build systems out of dedicated components. Building a go server that exposes a prototype /parse endpoint should be very simple. I suggest looking at the abovementioned demo mangle GRPC service. If anyone wants to take a stab, please go for it (in a different repo). If there is no movement, I may get back to this in a while. I will think about the requirements for the core language implementation. There is already a lot there which I would consider stable, but it is not documented (there is not much of a Mangle developer documentation, and only the beginnings of user documentation). |
Beta Was this translation helpful? Give feedback.
-
|
SWI-Prolog has a fairly nice graphic debugger ... I don't know how applicable its design is to https://www.swi-prolog.org/gtrace.html https://www.swi-prolog.org/pldoc/doc_for?object=when/2 See also: https://www.metalevel.at/prolog/debugging |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Labels: enhancement, feature-proposal, discussion, good-first-project
Is your feature request related to a problem? Please describe.
Mangle is an exceptionally powerful tool for declarative data manipulation and reasoning. However, like many declarative logic languages (e.g., Datalog, Prolog), it can present a steep learning curve for newcomers. The textual representation, while precise, can be abstract, making it challenging to:
Visualize Data Flow: For complex rules with multiple joins, negations, and function calls, tracing the flow of data and understanding predicate relationships requires careful mental mapping.
Debug Effectively: When a rule doesn't produce the expected output, debugging involves text-based tracing, which can be cumbersome. A visual representation would make it immediately obvious which parts of a rule's body are failing to match.
Onboard New Users: Lowering the barrier to entry is critical for adoption. A hands-on, visual tool would significantly accelerate the learning process for engineers new to Mangle or declarative programming in general.
The GraphQL ecosystem saw a massive boost in developer experience (DX) and adoption with tools like GraphiQL and GraphQL Playground. We have an opportunity to provide a similar best-in-class experience for Mangle.
Describe the solution you'd like
I propose we design and build an Interactive Mangle Editor, a web-based tool that provides a synchronized, bidirectional interface between Mangle code and a visual graph representation.
Core Features:
Code-to-Graph Visualization (The Viewer):
A text-editor pane for Mangle code.
A canvas pane that automatically renders the code as a directed graph.
Mapping:
Predicates: Represented as nodes.
Facts: Represented as specific instances or "grounded" nodes, perhaps visually distinct from abstract predicates.
Rules: Encapsulated in a "compound node" or group. The rule's body predicates would be input nodes, and the head would be the output.
Variables & Logic Flow: Represented by directed edges connecting the predicate nodes.
Negation (!) & Built-ins (fn:): Should have distinct visual markers (e.g., dashed edges for negation, unique node shapes for built-ins).
Interactive Querying:
An input field to run a query (e.g., ?fruit(X, /sweet, _)).
Executing the query would highlight the matching facts and rule-paths in the visual graph, providing immediate feedback.
Graph-to-Code Editing (The Editor - Stretch Goal):
The ability to manipulate the graph visually (drag-and-drop predicates, draw connections) and have the Mangle code generated or updated in real-time in the text editor. This creates a powerful, intuitive way to construct and refactor rules.
Demonstration with an Example:
For the following code:
Facts
fruit(/apple, /sweet, /red).
fruit(/banana, /sweet, /yellow).
Rule
delicious(X) :- fruit(X, /sweet, _).
The visualizer would show:
A fruit predicate node.
Two fact nodes (fruit(/apple...), fruit(/banana...)) connected to the main fruit node.
A compound node for the delicious(X) rule.
An edge from the fruit predicate node into the delicious(X) rule node.
An edge out of the rule node to a delicious predicate node, signifying that this rule defines it.
Describe alternatives you've considered
Static Visualization Generator: We could build a simpler tool that just generates a static graph image (e.g., using Graphviz) from a Mangle file. This is much easier to implement but loses the key benefits of interactivity, real-time feedback, and editing.
Enhanced CLI Debugger: We could focus solely on improving our text-based debugging and tracing tools. While valuable, this wouldn't address the initial learning curve or provide the high-level structural overview that a visual tool offers.
I believe the interactive approach, while more ambitious, provides an order-of-magnitude greater value.
Additional Context
This is a significant undertaking, but we can approach it in phases.
Phase 1 (MVP): Build a robust Mangle parser (if our current one isn't sufficient for this) and a front-end "Viewer" that implements the Code-to-Graph visualization and interactive querying. This alone would be a huge win for debugging and teaching.
Phase 2: Implement the Graph-to-Code editing features, turning the viewer into a full-fledged IDE.
Proposed Tech Stack (for discussion):
Backend: A simple Python (Flask/FastAPI) or Go server that exposes a /parse endpoint.
Frontend: A modern JavaScript framework (like React or Vue) using a graph visualization library such as vis.js, D3.js, or React Flow.
I have already built a small-scale prototype (which I can share) demonstrating the feasibility of this concept using Flask and vis.js. It effectively parses simple facts and rules and renders them in a hierarchical layout.
This tool would be a major differentiator for Mangle, making it more accessible, powerful, and enjoyable to use.
Beta Was this translation helpful? Give feedback.
All reactions