Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!msi.umn.edu!cs.umn.edu!boley From: boley@cs.umn.edu (Daniel Boley) Newsgroups: comp.lang.scheme Subject: Re: Destructuring / pattern-matching (was: Multiple return values) Message-ID: <1991Apr16.001511.14500@cs.umn.edu> Date: 16 Apr 91 00:15:11 GMT References: <9104130136.AA06792@kuwait> <9104151633.AA16272@garlic.Stanford.EDU> Organization: University of Minnesota, Minneapolis, CSci dept. Lines: 27 Is this too simple a way to destructure a list of values? Here we locally destructure the first 3 elements of the list multiple-values-as-a-list into 3 local variables and as well as getting the cdddr in rest. ; first define this simple fcn..... (define (give value form) ; give value to a function (apply form value)) ; use GIVE to destructure a list of multiple values... (give multiple-values-as-a-list (lambda (variable-1 variable-2 variable-3 . rest) expr-to-evaled-with-destructured-bindings)) ; A macro is unnecessary, but if you used a macro, it could look like... ; (this needs a better mnemonic name) (give-macro (variable-1 variable-2 variable-3 . rest) multiple-values-as-a-list expr-to-be-evaled-with-destructured-bindings) Of course, a single value handled this way will be a list of one item, so it won't be as transparent as MULTIPLE-VALUE-BIND, yet it seems so simple. By just extending the lambda form so that the list of formals can be a list of lists, one can make this quite general... - Dan Boley boley@cs.umn.edu