Ovid wrote:
Is there guidance on where to go from here or what the balance is between 
convenience functions and the bare minimum?

Speaking for myself, I know that I would like Perl 6's value transforming/mapping operators to be functions that don't mutate their arguments, or have standard variants that are, so that I can do all these things with pure functional semantics if I want.

One thing I don't like about Perl 5 is that $foo =~ s/// mutates its argument, and so if I wanted to write my own non-destructive trim() subroutine, I had to first copy the argument, then use s/// on it, then return the copy, rather than just use a one-liner s/// whose result is the changed string and that didn't modify the original.

Now fortunately as I recall Perl 6 is different and substituting regexes don't mutate their argument but return the changed version, and there is distinct meta-syntax like .= if you want it to mutate in place instead.

Or I may have remembered wrong.

Perhaps if this is a common issue it might be useful (I don't recall if it is already the case) to have a general meta syntax for all operators that distinguishes between whether they mutate their topic/main argument into the result or return the result.

Less important than with the string/etc operators but also very useful are non-mutating+mutating variants of various collection type operators. For example, it would be useful to have versions of the syntax for element insert/delete, and push/pop/shift/unshift/splice etc that just return the new version rather than changing the argument.

I suppose in a general case what might be useful is a meta-operator for a mutator that is conceptually shorthand for "first clone the argument, then apply the mutator to the clone instead, then return the clone". Now maybe something like this already exists, but conceptually it would be the opposite of the op= metasyntax.

Anyway, those are some thoughts I have.

-- Darren Duncan

Reply via email to