[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

silly multiple values



I once saw a proposal for passing arguments with the name used by the
callee.  The idea was that the caller could pass them in any order and
the names provide some documentation.  (I think this came up in a
keyword discussion on CommonLisp; KMP, do you remember more?  BTW - I
don't think it is a good idea.)  For example:

    (cons car 'a cdr 'd) = (cons cdr 'd car 'a)

The major problem with using this idea for returning values is
figuring out the inheritance of named values.  One possible definition
is the following.

The names of returned values have dynamic scope.  The special form
"receive" creates a context for receiving named values.  Its first
argument is a list of the names of the values to be received, its
second argument produces them, and following arguments use them.

The special form "establish" has one or more arguments.  The first is
a list of name-value pairs.  The name is the name of a value to
return, the value is its value.  Subsequent arguments are an implicit
begin whose value is the value of the establish form.  Establish
should only appear in tail-recursive positions.

Receive and establish can be implemented by the following T syntax
definitions.

(define-syntax (receive names produce . body)
  `(apply (lambda , names ,@ body)
	  (bind , (map (lambda (name) `(, name (undefined)))
	               names)
	    , produce
	    (list ,@ names))))

(define-syntax (establish name-value-pairs . body)
  `(begin ,@ (map (lambda (pair) `(set! ,@ pair))
		  name-value-pairs)
	  (undefined)
	  ,@ body))

I don't think this is a good proposal but there may be a good way to
use the basic idea.  It does allow forms to ignore "extra" values and
(this variation) can be implemented simply.

-andy
-------