chicken-janitors
[Top][All Lists]
Advanced

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

[Chicken-janitors] #443: #!rest and #!key are not internally consistent


From: Chicken Trac
Subject: [Chicken-janitors] #443: #!rest and #!key are not internally consistent
Date: Wed, 08 Dec 2010 20:00:39 -0000

#443: #!rest and #!key are not internally consistent
----------------------------+-----------------------------------------------
 Reporter:  alanpost        |       Owner:       
     Type:  defect          |      Status:  new  
 Priority:  minor           |   Milestone:  4.7.0
Component:  core libraries  |     Version:  4.6.x
 Keywords:                  |  
----------------------------+-----------------------------------------------
 Run the following program through csi with the test egg installed.

 I've tried to group these tests such that if one in a group succeeds, all
 of them should.  It appears that #!rest and #!key are not self-consistent,
 following separate rules in conceptually identical situations.

 the separation of (foo ...) and (apply foo ...) shows that these tests
 aren't affected by (apply ...), so the (foo ...) vs (apply foo ...)
 difference is not essential to this issue.

 The main observations:

 1) #!rest affects where #!key args must be placed.
 2) sometimes #!key args in the middle of an argument list work, and
 sometimes they don't.

 I'm not trying to point out a specific test as being wrong, but that the
 set of these tests should be consistent and aren't.

 {{{
 (use test)

 ;; "initial" fails and "initial+rest" succeeds.  I would expect that,
 ;; given the "initial" test failure, that "initial+rest" would also fail.
 ;;
 ;; "end" succeeds and "end+rest" fails.  I would expect that, since
 ;; "end" succeeds "end+rest" would also succeed.
 ;;
 ;; Even if either of these expectations is false:
 ;;
 ;; #!key args must be in the initial position if you're calling
 ;; a function that also uses #!rest, but must be in the terminal
 ;; position if the function does not use rest.  I would expect one
 ;; or the other of these (or both) to succeed, but I least expected
 ;; the failure condition to be the opposite of the "initial" and
 ;; "initial+rest" cases.
 ;;
 ;; I would expect, if only one position (front or back) works, that
 ;; the same  position works regardless of whether the function also
 ;; accepts #!rest arguments.
 ;;
 ;; All of the "middle(+rest)*" tests fail *except* "middle+rest (2)".
 ;; I consider it strange that this test succeeds where all of the
 ;; remaining tests fail.
 ;;
 ;; It seems as if they should all fail or all succeed.
 ;;

 (define (fn x y z #!key k)
   `((,x ,y ,z) ,k))

 (define (fn-rest #!rest r #!key k)
   `(,r ,k))

 ;;; initial position
 ;;;

 ;; Here we *do not* match #!key k, unless we have a #!rest.
 ;;
 (test-group "initial"
   (test '((0 1 2) 3) (fn k: 3 0 1 2))
   (test '((0 1 2) 3) (apply fn '(k: 3 0 1 2))))

 (test-group "initial+rest"
   (test '((k: 3 0 1 2) 3) (fn-rest k: 3 0 1 2))
   (test '((k: 3 0 1 2) 3) (apply fn-rest '(k: 3 0 1 2))))


 ;;; middle position
 ;;;

 ;; both of these fail
 ;;
 (test-group "middle"
   (test '((0 1 2) 3) (fn 0 k: 3 1 2))
   (test '((0 1 2) 3) (apply fn '(0 k: 3 1 2))))

 (test-group "middle+rest"
   (test '((0 k: 3 1 2) 3) (fn-rest 0 k: 3 1 2))
   (test '((0 k: 3 1 2) 3) (apply fn-rest '(0 k: 3 1 2))))


 ;; The "middle+rest (2)" succeeds, where I would expect it to fail
 ;; with everything else (or better, I expect all of the middle
 ;; groups to succeed.)
 ;;
 (test-group "middle (2)"
   (test '((0 1 2) 3) (fn 0 1 k: 3 2))
   (test '((0 1 2) 3) (apply fn '(0 1 k: 3 2))))

 (test-group "middle+rest (2)"
   (test '((0 1 k: 3 2) 3) (fn-rest 0 1 k: 3 2))
   (test '((0 1 k: 3 2) 3) (apply fn-rest '(0 1 k: 3 2))))


 ;;; end position
 ;;;

 ;; here we *do* match #!key k, unless we have a #!rest.  Opposite of
 ;; the "initial" tests.  I would expect the success/failure pattern
 ;; to match the "initial" tests, rather than being opposite of them.
 ;;
 (test-group "end"
   (test '((0 1 2) 3) (fn 0 1 2 k: 3))
   (test '((0 1 2) 3) (apply fn '(0 1 2 k: 3))))

 (test-group "end+rest"
   (test '((0 1 2 k: 3) 3) (fn-rest 0 1 2 k: 3))
   (test '((0 1 2 k: 3) 3) (apply fn-rest '(0 1 2 k: 3))))

 (test-exit)
 }}}

-- 
Ticket URL: <http://bugs.call-cc.org/ticket/443>
Chicken Scheme <http://www.call-with-current-continuation.org/>
Chicken Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]