String.reverse patch
Vasily Chekalkin
bacek at bacek.com
Fri Oct 15 05:41:45 UTC 2010
Hello.
On Fri, Oct 15, 2010 at 3:23 PM, Jonathan Leto <jaleto at gmail.com> wrote:
> I put a new patch here relating to to String.reverse :
Patch is totally wrong.
1. It update STRING in-place.
2. It treats STRING as sequence of bytes.
3. It doesn't operate on PMC.
Proper version should consist of
// Sketchy version.
Parrot_str_reverse(src) {
STRiNG *new_str = Parrot_str_new();
iter = STRING_ITER_INIT(src);
while (iter) {
str_append(new_str, iter.get_and_advance()
};
}
// In string.pmc
METHOD reverse() {
SET_ATTR_str_val(INTERP, SELF,
Parrot_str_reverse(INTERP, GET_ATTR_str_val(INTERP, SELF));
}
// Optional op
op reverse(out STR, in STR) {
$1 = Parrot_str_reverse(interp, $2);
}
--
Bacek
More information about the parrot-dev
mailing list