TomDLux has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.my &part ::= &List::Part::part.assuming(labels => <<sheep goats>>)
On the other hand, putting my in the main script will not have any effect in the package, will it?
Awaiting instant translation ...
--
TTTATCGGTCGTTATATAGATGTTTGCA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl 6 Exegesis 6 pg 7
by adrianh (Chancellor) on Aug 07, 2003 at 06:30 UTC | |
by TomDLux (Vicar) on Aug 07, 2003 at 15:32 UTC | |
by adrianh (Chancellor) on Aug 07, 2003 at 16:50 UTC | |
by bunnyman (Hermit) on Aug 07, 2003 at 15:43 UTC | |
|
Re: Perl 6 Exegesis 6 pg 7
by bobn (Chaplain) on Aug 07, 2003 at 06:12 UTC | |
by chromatic (Archbishop) on Aug 07, 2003 at 06:36 UTC | |
by adrianh (Chancellor) on Aug 07, 2003 at 06:35 UTC | |
by Aristotle (Chancellor) on Aug 07, 2003 at 09:42 UTC | |
by bugsbunny (Scribe) on Aug 07, 2003 at 11:56 UTC |