On Tue, Mar 23, 2004 at 01:22:23PM +0100, Marc Lehmann wrote:
> On Fri, Mar 19, 2004 at 02:19:09PM -0800, Manish Singh <[EMAIL PROTECTED]> wrote:
> > While on that subject, I'm wondering what a good way of representing
> > named parameters in scheme and perl would be. Any thoughts?
> This is natural, and common:
> $obj->method (arg1 => value1, arg2 => value2, ...)
> this, too:
> $obj->method (-arg1 => value1, -arg2 => value2, ...)
> as well as this:
> $obj->method (Arg1 => value1, Arg2 => value2, ...)
> All of these can be supported at the same time, and the difference
> between them is often seen as a style difference only.
> However, there is no way of using the same method both with named
> parameters or not (unless your resort to other syntaxes like $obj->method
> (ARG1, value1, ARG2, value2), making ARG1 etc. global or worse).
Yeah, that is unfortunate, since the interface should support both named
and positional interfaces (and combining the two in one call).
> Especially with methods with just a single argument, forcing named
> parameters might not be the best thing (OTOH, you can make a difference
> between methods with single argument and more, but...).
> Right now, a few things get autodetected because gimp-perl uses strong
> typing for the gimp objects (as opposed to e.g. C or scheme). All in all
> there would be no problem at all supporting named parameters (There is
> even a certain amount of support for that already in gimp-perl), but it
> will break existing scripts and make writing scripts slightly more
Well, this would go hand in hand with a plugin api redo, so scripts
are gonna break anyway.
> Personally though, I really want named parameters. Not at all because of
> me being able to remember arguments better (I think it's actually worse to
> have to remember the parameter names), but because it allows me to easily
> leave off arguments that can be defaulted.
> Most of these arguments, however, are at the end, so even more important
> than named parameters would IMHO be default values for unspecified ones.
> I once reworked the PDB code to allow variable number of arguments but
> left the check in for compatibility with existing plug-ins who expect all
> or nothing (ignoring the number of arguments actually passed; the API did
> provide this already).
So what would be a good way for perl to support both named and positional
stuff? The only way I can think of still is to use a hashref for named
Gimp-developer mailing list