krulwich@ils.nwu.edu (Bruce Krulwich) (12/08/89)
Several suggestions have been made regarding extensions to Scheme's use of a single rest arg as the only means for a function's having a varying number of parameters. Several of these suggestions have required some variant on keywords in the arg-list, which people have reacted strongly against. It seems to me that this problem can be gotten around by having lists in the argument list in place of symbols. For example, one possible syntax for optional args with defaults would be (lambda (arg1 ... argn (opt1 (opt2 def2) opt3 ... (optn defn))) <body>) where the last element in the formal parameter list is a list specifying the non-required parameters. Within this list, optional arguments are specified as symbols or lists of two elements, where the lists of two elements represent optional parameters with defaults. Nonprovided optional arguments without defaults would have unspecified values. If this list is improper, the final CDR is a rest arg with default nil. This scheme of using lists in formal parameter lists to represent non-standard args would also work for more complex methods of handling parameters, such as the scheme discussed a few weeks ago using procedures to get arguments. (I'm personally in favor of such an idea because of its relation to continuations, but that's another matter.) Anyway, such a scheme could use the syntax I'm proposing in a way similar to above: (lambda (arg1 ... argn (num-params fetcher-fct)) <body>) where the num-params is the number of parameters specified and the fetcher takes an int and gets that param. I'm not proposing this method in particular, just this style of syntax. It could just as soon be used for the method discussed this past summer, which would be something like: (lambda (arg1 ... argn (more-args? fetcher-fct)) <body>) where the fetcher-fct is passed a continuation of three arguments which it will call on the next available arg, whether there are more args, and a new fetcher function. I think that any similar method for parameter fetching could be expressed by having a list as an element in the formal parameter list. I think that using a syntax such as those I've shown here will allow Scheme to have complex parameter spec's without keywords. Any comments?? Bruce Krulwich Institute for the Learning Sciences krulwich@ils.nwu.edu