On page 7 of Exegesis 6, Damian describes how currying can rescue legacy code when subroutines are updated.The idea is that an existing routine:

sub part (Selector $is_sheep, *@data ) returns List of Pair

is modified by the addition of optional parameter in the middle of the signature.

sub part (Selector $is_sheep, Str ?@labels is dim(2) = <<sheep goats>>, *@data ) returns List of Pair

If you have existing code which invokes the routine with a selector and with data which does not satisfy the description, "array of two strings", you're fine. But otherwise, or if you have code which uses a dynamic data set, your data will be mistaken for a set of labels, and the function will be invokes with no data.

Damian suggests using currying to provide backward compatability. Currying, for those who don't know, has nothing to do with the star of Rocky Horror, but involves supplying one parameter to a routine, generating a routine which takes fewer parameters. A simple example, multiplication takes two arguments; currying multiplication with the argument '2' generates a function double. Instead of taking two parameters and multiplying them together, it takes one parameter and retuns 2 times that value.

So now for my question:

Damian suggests using currying:

my &part ::= &List::Part::part.assuming(labels => <<sheep goats>>)
to make the existing code compatible with the new structure of the routine. If you change the name of the routine, the curry provides a backwards compatible path, and new code can use the new name. But a ,em>realroutine invoking the new routine could achieve the same result.

On the other hand, putting my in the main script will not have any effect in the package, will it?

Awaiting instant translation ...

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Perl 6 Exegesis 6 pg 7 by TomDLux

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.