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

Multiple values, revised proposal

>The defaulting of missing values in BIND is to support programming styles such 
>as the following:
>  (bind ((frobby path-to-frobby (find-frobby name)))
>    (if frobby
>      ;; There is one
>      (do-something-with name frobby path-to-frobby)
>      ;; No frobby with that name exists
>      (do-something-else name)))
>  ;; Returns two values:
>  ;;  The frobby with that name, or #f if there isn't one
>  ;;  The path by which that frobby was found
>  (define find-frobby (method (name)
>    (bind ((x ..la de dah..))
>      (when (umpty ump...)
>	 (when (something something something...)
>	   (bind ((frobby (do dah ...)))
>	     (unless (no-good? frobby)
>	       (values frobby (foo fah)))))))))
>In your [Meehan's] proposal find-frobby would have to be written as
>  (define find-frobby (method (name)
>    (bind ((x ..la de dah..))
>      (if (and (umpty ump...)
>		(something something something...))
>	   (bind ((frobby (do dah ...)))
>	     (if (no-good? frobby)
>	       (values frobby (foo fah))
>	       (values #f #f)))
>	   (values #f #f)))))

What's wrong with the following version?  Perhaps some will find the
use of set! objectionable, but I don't understand why.  This version
avoids the need for defaulting missing values in BIND, and also makes
clear to compiler and programmer that it offers to return exactly two
values.  Perhaps you don't find anything particularly wrong with this
version, but would nevertheless like to support the no-setting style?

  (define find-frobby (method (name)
    (bind ((x ..la de dah..)
	   (frobby #f)
	   (path-to-frobby #f))
      (when (umpty ump...)
	 (when (something something something...)
	   (set! frobby (do dah ...))
	   (unless (no-good? frobby)
	     (set! path-to-frobby (foo fah)))))
      (values frobby path-to-frobby))))