Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found