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

Re: multiple-value-setf



Sam Steingold <sshteingold@cctrading.com> is awake again:
> 
>      1.  *** Apropos --> `multiple-value-setf' <--
>      
>      system::multiple-value-setf    macro
>      
>      what does this macro do? may I guess? :)

It's like `multiple-value-setq', except that it allows arbitrary places
instead of only symbols.

>      2. Apparently, multiple-value-bind is implemented using 
>      multiple-value-list, thus it conses (or is it some sort of constant 
>      list?) Is this a performance hit?

`multiple-value-bind' does *not* cons. The use of multiple values will only
cause heap allocation if you explicitly call `multiple-value-list'. Just
try the following to convince yourself:

  (defun test (x y) (multiple-value-bind (q r) (floor x y) (+ q r)))
  (compile 'test)
  (space (test 1729 12))

>      3. Why isn't multiple-value-setf in the language?

Maybe because `multiple-value-setq' is normally sufficient?

>      What's wrong with the following:
>      
>      (defmacro multiple-value-setf ((&rest exps) form)
>        (let* ((vars (mapcar (lambda (xx) (gensym "MVSF")) exps))
>          (combo (mapcan (lambda (xx vv) (list xx vv)) exps vars)))
>          `(multiple-value-bind (,@vars) ,form
>            (setf ,@combo))))

If some of the exps have side-effects, the side-effects will be executed
after the evaluation of the form, thus not following the normal left-to-right
evaluation order. For example:

  (multiple-value-setf ((aref a (incf i))) i))
  ==> (multiple-value-bind (#:mvsf736) i (setf (aref a (incf i)) #:mvsf736)) ;

which is subtly different from

  (setf (aref a (incf i)) i).

                     Bruno


! To unsubscribe from the clisp-list mailing list, send mail to     !
!               listserv@ma2s2.mathematik.uni-karlsruhe.de          !
! including the two words "unsubscribe clisp-list" as message body. !