Opened 12 years ago

Closed 10 years ago

#1002 closed enhancement (fixed)

define-values is overly restrictive

Reported by: johnwcowan Owned by:
Priority: major Milestone: someday
Component: unknown Version: 4.8.x
Keywords: Cc:
Estimated difficulty:

Description

Currently, define-values requires that its lambda-list be a proper list of identifiers like (a b), whereas it should allow (a b . c) and even a, which are both valid lambda-lists.

The following definition achieves this:

(define-syntax define-values 
   (syntax-rules () 
     ((define-values () exp) 
      (call-with-values (lambda () exp) (lambda () 'unspecified))) 
     ((define-values (var . vars) exp) 
      (begin  
        (define var (call-with-values (lambda () exp) list)) 
        (define-values vars (apply values (cdr var))) 
        (define var (car var)))) 
     ((define-values var exp) 
      (define var (call-with-values (lambda () exp) list))))) 

Change History (3)

comment:1 Changed 12 years ago by johnwcowan

Here's the definition from R7RS:

(define-syntax define-values
  (syntax-rules ()
    ((define-values () expr)
     (define dummy
       (call-with-values (lambda () expr)
                         (lambda args \schfalse))))
    ((define-values (var) expr)
     (define var expr))
    ((define-values (var0 var1 ... varn) expr)
     (begin
       (define var0
         (call-with-values (lambda () expr)
                           list))
       (define var1
         (let ((v (cadr var0)))
           (set-cdr! var0 (cddr var0))
           v)) ...
       (define varn
         (let ((v (cadr var0)))
           (set! var0 (car var0))
           v))))
    ((define-values (var0 var1 ... . varn) expr)
     (begin
       (define var0
         (call-with-values (lambda () expr)
                           list))
       (define var1
         (let ((v (cadr var0)))
           (set-cdr! var0 (cddr var0))
           v)) ...
       (define varn
         (let ((v (cdr var0)))
           (set! var0 (car var0))
           v))))
    ((define-values var expr)
     (define var
       (call-with-values (lambda () expr)
                         list)))))

comment:2 Changed 12 years ago by sjamaan

Jeez, that's horrible!

A much simpler (I hope equally correct) version has been sent to chicken-hackers.

comment:3 Changed 10 years ago by sjamaan

Resolution: fixed
Status: newclosed

Fixed by 25a9b9932014f8ff84825658c054a91e6c0630f3..136e0b4292aec0cb8c5c8f6c9860d22bc2261a1e136e0b4292aec0cb8c5c8f6c9860d22bc2261a1e

Note: See TracTickets for help on using tickets.