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

Re: small Q



Brian Campbell <Brian_Campbell@lotus.com> wrote in message
398F2D0B.EB3781D5@lotus.com">news:398F2D0B.EB3781D5@lotus.com...
> Since I'm comming from a long history of one return value programming
> languages (Scheme R4RS, SmallTalk, C, Java, PASCAL, etc.), could someone
> describe where multiple return values would be useful and not just a
> convenience?

Here is a simple example in Common Lisp where having "floor" return both a
quotient and a remainder is (IMO) _useful_:

(defun seconds-to-dhms (total-seconds)
  "Given an integer number of seconds, SECONDS-TO-DHMS
  converts it to the values: DAYS HOURS MINUTES SECONDS."
  (multiple-value-bind (day remainder1)
                       (floor total-seconds 86400)
    (multiple-value-bind (hours remainder2)
                         (floor remainder1 3600)
      (multiple-value-bind (minutes seconds)
                           (floor remainder2 60)
        (values day hours minutes seconds)))))

Al Reich




References: