This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: values (Re: R5RS)


"C. Ray C." <crayc@206.31.63.15> writes:
> Here is a simple implementation of the list-let I proposed:
> 
> (define-macro (list-let vars lst . body)
> 	`(apply (lambda ,vars ,@body) ,lst))
> 

And here are some simple implementations of multiple-value-bind and a few
other CL'isms:

;;; multiple-value-bind
(define-macro (let-values var-list values-form . form*)
    `(call-with-values
      (lambda () ,values-form)
      (lambda ,var-list ,@form*)))

;;; values-list
(define (list->values list) 
    (apply values list))

;;; multiple-value-list
(define (values->list values-form)
    (call-with-values
     (lambda () values-form)
     list))

;;; We have to construct a list for this one, yuck.
;;; Why doesn't (values 1 (values 2 3) 4) => #<values 1 2 3 4> anyway?
;;; multiple-value-call
(define (apply-to-values function . form*)
    (apply function (apply append (map multiple-value-list form*))))

---

Some random thoughts/questions concerning values...

Someone indicated that guile values/call-with-values are not R5RS
conformant. Is this because call-with-values creates a continuation
that accepts a single #<values ...> argument rather than multiple
arguments?

guile> (define t                                        
           (call-with-current-continuation              
            (lambda (return)                            
              (call-with-values                         
               (lambda ()                               
                 (call-with-current-continuation        
                  (lambda (cont)                        
                    (return cont))))                    
               (lambda (x y z) y)))))
guile> t
#<continuation 1155 @ 807cc48>
guile> (t 1 2 3)
standard input:176:1: In expression (t 1 2 ...):
standard input:176:1: Wrong number of arguments to #<continuation 1155 @ 807cc48>
ABORT: (wrong-number-of-args)
guile> (t (values 1 2 3))
guile> t
2

What would it cost to support multiple arguments continuations and use
them to implement multiple values?

Can anyone think of a reason to include m-a-c (except for possibly
strict R5RS compliance)?

Can anyone comment on possible efficiency issues of m-a-c versus
explicit #<values ...> objects?

In spite of R5RS saying:
        "The effect of passing no value or more than
         one value to continuations that were not created by
         call-with-values is unspecified",
having continuations explicitly _ignore_ superfluous arguments would
allow for a set of CL'isms:

(floor 1.5 1) => 1, 0.5
(* 10 (floor 1.5 1)) => 10

        Regards,
        Ole Myren Røhne

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]