Re: [stack] Parameters: ordered versus named
John Cowan <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
Manfred Von Thun scripsit: > My understanding is that there are some languages which > allow this kind of notation (Common Lisp ?, Ada ?) but > I cannot remember any details --- anyone?? Common Lisp (as well as some other Lisps such as DSSSL and Dylan) does indeed allow keyword arguments. They must physically follow the positional arguments (if any) both in declarations and in calls. It is also possible to capture unknown keyword arguments for analysis at runtime. In certain domains keyword arguments are used by default. For example, CL object constructors are normally keyword-based: you specify the fields of a class by name, and the default constructor will accept keyword arguments that initialize the fields. (It's also possible to write non-default constructors that work like ordinary functions, by order of arguments -- these are known as BOA constructors.) Python has a unified model: parameters are declared by name, and calls may use keywords, but non-keyworded arguments are assigned positionally. However, in calls non-keyword arguments must precede keyword ones. Again, it is possible to capture unknown keyword arguments. Ada also has a unified model, but there are no constraints on ordering in calls, and there is no provision for unknown keywords. Fortran 90 and 95 also use this model. Lua provides modest syntactic sugar for keyword-only calls: this is declared as a single argument representing a table mapping keywords to their values, so all analysis must be done at run time. In Perl, there is no special sugar, but passing a hash is common. Algol 60 allowed calls of the form: multiply(x) by: (y) but this meant the same as "multiply(x, y)" and the keywords had no significance to the compiler. Smalltalk is keyword-only, as has been pointed out, except in the cases of unary operators (postfix) and binary operators (infix). Binary operators are syntactically restricted to use symbol characters only. -- John Cowan http://ccil.org/~cowan [email protected] SAXParserFactory [is] a hideous, evil monstrosity of a class that should be hung, shot, beheaded, drawn and quartered, burned at the stake, buried in unconsecrated ground, dug up, cremated, and the ashes tossed in the Tiber while the complete cast of Wicked sings "Ding dong, the witch is dead." --Elliotte Rusty Harold on xml-dev