For a work problem I encountered yesterday, it occurred to me that it'd be trivial to solve with the right helper module. I can't work out if that module is easy, hard or impossible to write - or has already been written.

I'm slightly fuzzy on the details, but I imagine it looking something like this:

% cat myprog use Data::Annotate; # 'Tie::Annotate'? sub adder { return $_[0] + $_[1] } my($foo, $baz) = (2, 5); annotate($foo, 'foo'); my $bar = adder($foo, $baz); say "bar is ", $bar; say "bar is annotated as ", annotation($bar); say "bar is derived from ", derivation($bar); # not sure if that should also attempt to show derivation of the # components; maybe it should take a maxdepth argument: my $etc = $bar + $foo; say "etc is annotated as ", annotation($etc); say "etc is derived from ", derivation($etc, depth => 3); % perl myprog bar is 7 bar is annotated as foo + 5 bar is derived from foo + 5 at myprog line 2 main::adder(2, 5) called at myprog line 5 etc is annotated as (foo + 5) + foo etc is derived from (foo + 5) + foo at myprog line 11 (foo + 5) at myprog line 2 main::adder(2, 5) called at myprog line 5 foo annotated at myprog line 4 %

An obvious difficulty is how to construct the annotation string for various ops, but I'd be happy enough if it said "i_add(i_add(foo, 5), foo)" instead.

I'd welcome your thoughts.

Hugo


In reply to annotation, derivation by hv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.