>>>>> "LW" == Larry Wall <[EMAIL PROTECTED]> writes:
LW> On Sat, Mar 15, 2003 at 05:32:41PM -0800, mlazzaro wrote: LW> : So my reading is that it's not possible to specify 'required' LW> : named parameters, unless we're completely missing something. My LW> : first impulse is that it's not a big deal, because who's gonna LW> : do that? My second impulse is... well... if I were writing a LW> : big library with big, hairy methods, and wanted to *require* the LW> : use of names for all params because the signatures are just too LW> : baffling otherwise, I can sortof see wanting that... If, for LW> : example, you are a purist who believes _all_ sub parameters LW> : should be named, we might want Perl to nonjudgementally support LW> : that particular neurosis. Bleah, dunno. LW> Your reading is correct. It's possible to force the issue at run LW> time, at least: LW> sub foo(+$req = die 'You must supply a "req =>" argument') {...} LW> or maybe LW> sub foo(+$req = MUST) {...} LW> where "MUST" could be something even more magical, possibly even LW> recognized by the compiler, just as $CALLER::_ could be. But I'm LW> not terribly interested in supporting that particular neurosis. but if you declare required positionals and don't pass them all in even by name, the compiler will detect that now via the signature. if the caller knows the order and passes them in that way, and the module doc says to pass them by name, then caller emptor. if the sub is documented to be all pass by name and you don't do that, then you are to blame. there is no need for more B&D here, just let the compiler check the names passed in against the list in the sig. this means that you have a more perl5 like experience IMO: sub foo( $a, $b, $c ) { ... } foo( 1, 2, 3 ) ; foo( a => 1, c => 3, b => 4 ) ; @args = ( a => 3, c => 4 ) ; foo( b => 3, [EMAIL PROTECTED] ) ; @args = ( a => 3 ) ; foo( b => 3, [EMAIL PROTECTED], c => 5 ) ; i think all of those should work (AFAIK they are ok with apoc6). i like the ability to build up the pairs in an array or hash and splatting that in the call. one good use is when you have extra arguments optionally added to the arg list. too often in p5 you see the args assigned to hash and then parsed out with tedious runtime code or a module or sub that does it. i created such a beast which describes all the attributes of an object with list of hashes that have a name, required flag, default, and other things. having the compiler do more of this checking would make it easier to debug and remove a lot of runtime overhead. having the required params in the first zone (positional) and then the optional named args makes it also easier to manage required vs optional. my current design has a whole attribute description flag dedicated to 'required' and it only checks at runtime. when you pass in named args with a splatted hash/array then you have to defer checking to runtime if any required params aren't filled in explicitly in the call. so the last two cases above lose some/all compile time checking. one issue is that you pass $b by position and the others by name. only the earlier ones can be passed by position and later ones by name. uri -- Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com ----- Stem and Perl Development, Systems Architecture, Design and Coding ---- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class