Skip to content

Record and display MeTTa program traces #904

@ngeiswei

Description

@ngeiswei

A generally useful capability of MeTTa would be to record program traces. I suppose it would be implemented in a function that would take a space where to record the trace of a function call, itself describe by its function name and arguments, maybe something like

(: trace-eval (-> Space (-> $a $b) $b))

and would be used in the following way

;; Define foo that counts backward from $x to 0
(= (foo $x) (if (== $x 0) 0 (foo (- $x 1))))

;; Define `trace-space` to contain the trace of foo
!(bind &trace-space (new-space))

;; Run (foo 42) while storing a trace in `trace-space`
!(trace-eval &trace-space foo 42)

The result of that call would be [0] and the side effect would be that trace-space would contain the trace data. The exact format remains to be determined (maybe this could in fact be a parameter of trace-eval). An example of the content of trace-space after the call would be

(called-by (foo 42) foo.metta)
(called-by (foo 41) (foo 42))
(called-by (foo 40) (foo 41))
...

Then one could have rendering tools to display a tree of such data, like

|-(foo 41)
  |-(foo 40)
    |-(foo 39)
    ...

It would be good if such rendering represent non-deterministic branches clearly. Again the specifics remains to be defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions